Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a more optimized way to parse then this

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
US
Public Function bastest1(string1 As String)
Dim string2 As String
Dim string2a As String
Dim string3 As String
Dim string3a As String

On Error GoTo errorhandler

MsgBox "1-" & string1 & "-"

string2 = Left(string1, InStr(string1, " ") - 1)

MsgBox "2-" & string2 & "-"

string2a = Mid(string1, InStr(string1, " ") + 1)

MsgBox "3-" & string2a & "-"

Select Case string2

Case "p":

string3 = Left(string2a, InStr(string2a, " ") - 1)

MsgBox "4-" & string3 & "-"

string3a = Mid(string2a, InStr(string2a, " ") + 1)

MsgBox "5-" & string3a & "-"

Exit Function

Case "s":

' Do
'tempstring$ = InStr(string2a, ",")
'If tempstring$ = "0" Then
'MsgBox "just one"
'Exit Do
'End If
' string2a = Left(string2a, InStr(string2a, ",") - 1)
' MsgBox "7-" & string2a & "-"
' string2aa = Mid(string2a, InStr(string2a, ",") + 1)
' MsgBox "8-" & string2aa & "-"
' Loop

MsgBox "6-" & string2a & "-"

Exit Function

Case Else:

MsgBox "else"

Exit Function

End Select

Exit Function

errorhandler:

MsgBox "error"

End Function
 
Looks a bit "Old". If you are using VB6, look up the "Split" function. It will easily break up any string into it's "words":

MyStr = "The lazy brown fox jumper over the quick red dog"
TheseWords = Split(MyStr)
For xx = 0 to UBound(TheseWords): ? xx, TheseWords(xx): Next xx
0 The
1 lazy
2 brown
3 fox
4 jumper
5 over
6 the
7 quick
8 red
9 dog

If you are using an earlier ver, I posted a routine "basSplit" in one of the Ms. Access forums a while ago, so you could search there for the routins. It would work for your (aparent) purpose.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top