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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a string for multiple values in it

Status
Not open for further replies.

mistux

MIS
Mar 27, 2003
10
0
0
US
I need to parse the following string:

"( B Panel 48.1248 X 93.5 CRS Gage 16)"

I need:
1. The letter preceding the word "Panel" in this case "B"
2. The number following the word "Panel" in this case "48.1248"
3. The number following the word "Gage" in this case "16"

Everything else "should" stay constant, i.e. the format. Although the actual values will change and the length of them.

I know that I can use InString, but the code is driving me crazy!

Can anyone help me?
 
It will take some playing with, but you should be able to do all of this using the INSTR(), LEFT() and RIGHT() functions. Give it a try and if you can't get it, post your code and a handfull of sample data and we can help. Terry
**************************
* General Disclaimor - Please read *
**************************
Please make sure your post is in the CORRECT forum, has a descriptive title, gives as much detail to the problem as possible, and has examples of expected results. This will enable me and others to help you faster...
 
You may be able to combine these functions into one, but this way was easier for debugging:
Private Sub Command2_Click()
Dim strFirstLetter As String
strFirstLetter = ParseMeFirstLetter(Text0.Value)
Dim strNumberAfterPanel As String

strNumberAfterPanel = ParseMeNumberAfterPanel(Text0.Value)
Dim strNumberAfterGage As String
strNumberAfterGage = ParseMeNumberAfterGage(Text0.Value)
MsgBox "First Letter = " & strFirstLetter & "; Number After Panel = " & strNumberAfterPanel & "; Number After Gage = " & strNumberAfterGage, vbOKOnly, "Results"

End Sub


Private Function ParseMeFirstLetter(strin As String)
ParseMeFirstLetter = Right(strin, (Len(strin) - 1)) 'trim off the (
ParseMeFirstLetter = Trim(Left(ParseMeFirstLetter, (InStr(ParseMeFirstLetter, "Panel") - 1)))
End Function
Private Function ParseMeNumberAfterPanel(strin As String)
ParseMeNumberAfterPanel = Trim(Right(strin, (Len(strin) - InStr(strin, "l"))))
ParseMeNumberAfterPanel = Trim(Left(ParseMeNumberAfterPanel, (InStr(ParseMeNumberAfterPanel, "X") - 1)))
End Function
Private Function ParseMeNumberAfterGage(strin As String)
ParseMeNumberAfterGage = Right(strin, 4)
ParseMeNumberAfterGage = Trim(Left(ParseMeNumberAfterGage, (InStr(ParseMeNumberAfterGage, ")") - 1))) 'trim off the ending ) and the leading space
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top