To parse the sample:
Dim Pos as Integer, Result as String
Pos=InStr(Text,":")
Result=Left$(Text,Pos-1)
-or in one step
Result=Left$(text,InStr(Text,":")-1)
Wayne
Michael <[EMAIL PROTECTED]> wrote:
Michael <[EMAIL PROTECTED]> wrote:
how can i parse a string backwards ?
i.e. Result = Mid$(sLines(nrLines), Pos + 2) takes all
text from the "from left to right" postion +2 and puts
in results. i need i.e. if the string is 111111:22222
to take only 111111 and put it into Result.
With some help from other people, I have coded this:
Function Parse(text As String)
Dim Pos As Integer
Dim nrLines As Integer
sLines = Split(txtMain.text, vbCrLf)
Open App.Path & "\" & "output.txt" For Append As #1
For nrLines = 0 To UBound(sLines)
Pos = InStrRev(sLines(nrLines), text)
Result = Mid$(sLines(nrLines), Pos + 2)
Print #1, Result
Next
Close #1
End Function
Private Sub cmdParse_Click()
Call Parse(":")
End Sub
Please help.
--- Boyd Spangler <[EMAIL PROTECTED]> wrote:
> I didn't see your request for multilang uage support
> and I don't know much about it but check out this
> site at VBHelper http://www.vb-helper.com/tut11.htm.
> Wayne
>
> Michael <[EMAIL PROTECTED]> wrote:
> Thank you very much for the great help! I have
> updated
> my code with your routine and it works (much
> better).
>
> Please if you have any ideea answer to my email
> about
> Multilanguage Support in VB. If you did not receive
> it, tell me to post it again.
>
>
> --- Boyd Spangler <[EMAIL PROTECTED]> wrote:
>
> >
> > A more effecient way to do this is:
> >
> > Private Sub cmdParse_Click()
> >
> > Dim Pos As Integer
> >
> > Dim nrLines as Integer (or Long)
> >
> > sLines=Split(txtMain.Text, vbCrLf)
> >
> > Open App.Path & ; "\" & "output.txt" For Append As
> #1
> >
> > for nrLines = 0 to UBound(sLines)
> >
> > Pos=InStrRev(sLines(nrLines),"\")
> >
> > Result=Mid$(sLines(nrLines),Pos+1)
> >
> > Print #1,Result
> >
> > next
> >
> > Close #1
> >
> > End Sub
> >
> > Always define your variables. A variant is the
> > slowest and largest of the variables.
> >
> > Split shouldn't be used over and over 3000 times
> it
> > too is slow. It is used right in the splitting of
> > the main text anything else would be a waste of
> > time.
> >
> > Also opening and closing a file 3000 times slows
> > down the program. Open it, write information to it
> > and then close it.
> >
> > Don't take anyting I say as insulting....it is not
> &g t; meant that way.
> >
> > Wayne
> >
> >
> > anlaahoy <[EMAIL PROTECTED]> wrote:
> >
> > That's alright!
> > I thought you were going to read the lines from a
> > file...lol
> >
> > regards
> >
> > anla
> > --- In [EMAIL PROTECTED], B Mihai
> > <[EMAIL PROTECTED]>
> > wrote:
> > > Thank you all for your help.
> > >
> > > This is my solution resulting from your tips and
> > > coding snippets.
> > >
> > > ===========
> > > Private Sub cmdParse_Click()
> > > Dim Temp, nrLines, LineNumber
> > >
> > > sLines = Split(txtMain.Text, vbCrLf)
> > >
> > > For nrLines = 0 To UBound(sLines)
> > > LineNumber = sLines(nrLines)
> > > ScanLine (LineNumber)
> > > Next
> > >
> > > End Sub
> > >
> > > Function ScanLine(xLine)
> > > Dim xTemp, Parsed, UParse, Result
> > > xTemp = Split(xLine, "\")
> > > UParse = UBound(xTemp)
> > > Result = xTemp(UParse)
> > > Open App.Path & "\" & "output.txt" For Append As
> > #1
> > > Print #1, Result
> > > Close #1
> > > End Function
> > > ==============
> > >
> > > Very effective for what I needed.
> > >
> > > Happy coding and thank you all very much once
> > again
> > > for the ideeas!
> > > --- anlaahoy <[EMAIL PROTECTED]> wrote:
> > >
> > > >
> > > >
> > > >
> > > > Dim sFileName As String
> > > > &nb sp; Dim lFile As Long
> > > > Dim sLine As String
> > > > Dim lCount As Long
> > > > Dim Temp
> > > > Dim Parsed
> > > >
> > > >
> > > >
> > > > ' Change the filename below to your
> > filename:
> > > > sFileName = "C:\test.txt"
> > > >
> > > > ' Get a safe file handle.
> > > > lFile = FreeFile
> > > > ' Initialize the menu index counter.
> > > > lCount = 0
> > > >
> > > > ' Open the input file.
> > > > Open sFileName For Input As #lFile
> > > >
> > > > ' Read every line in the file.
> > > >
> > > > Do While Not EOF(lFile)
> > > > lCount = lCount + 1
> > > > Line Input #lFile, sLine
> > > > If Not Len(sLine) = 0 Then
> > > > Temp = Split(sLine, "\")
> > > > For Parsed = 0 To UBound(Temp)
> > > > MsgBox Temp(Parsed),
> vbInformation,
> > > > "Split Sample"
> > > > Next
> > > >
> > > > End If
> > > > Loop
> > > > MsgBox "Total number of lines:" & lCount
> > > > Close #lFile
> > > >
> > > >
> > > > --- In [EMAIL PROTECTED], B
> Mihai
> > > > <[EMAIL PROTECTED]>
> > > > wrote:
> > > > >
> > > > > Here is what I coded in combination with
> what
> > you
> > > > > helped.
> > > > >
> > > > > Dim Temp
> > > > > Dim nrLines
> > > > > Dim Parsed
> > > > >
> > > > > sLines = Split(txtMain.T ext, vbCrLf)
> > > > >
> > > > > For nrLines = 0 To UBound(sLines)
> > > > > Temp = Split(nrLines, "\")
> > > > > For Parsed = 0 To UBound(Temp)
> > > > > MsgBox Temp(Parsed), vbInformation, "Split
> > Sample"
> > > > > Next
> > > > > Next
> > > > >
> > > > >
> > > > > This is not yet the solution, as it returns
> > the
> > > > number
> > > > > of the line where the procedure is, and not
> > the
> > > > last
> > > > > part of each line (i.e. the text after "\"
> of
> > each
> > > > > line )
> > > > >
> > > > > The problem is : I dont know how to read a
> > line of
> > > > > text from a file, at a time. Note that> > > > txtMain.text
> > > > > has a file loaded into it and "slines" is
> > declared
> > > > in
>
=== message truncated ===
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
To unsubscribe, send an email to:
[EMAIL PROTECTED]
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
To unsubscribe, send an email to:
[EMAIL PROTECTED]
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/PlanetSourceCode/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
