Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

simsfan

VB string search help

This topic is 5561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making an app in VB, and I''m searching for spaces, " ", in the text, to be able to extract numbers from the text. But it doesn''t work!!! Here''s the code: ----------------------------------------------------------------- Sub SpaceSearch() Dim intPos As Integer Dim intPos2 As Integer Dim intPos3 As Integer Dim intPos4 As Integer Dim strAdresse As String Dim strAdresse2 As String Dim strAdresse3 As String intPos = InStr(1, Text1.Text, " ") strAdresse = Mid(Text1.Text, intPos, 4) If IsNumeric(strAdresse) Then txtAdresse.Text = strAdresse GoTo Quit Else intPos2 = InStr(intPos, Text1.Text, " ") strAdresse2 = Mid(Text1.Text, intPos2, 4) End If If IsNumeric(strAdresse2) Then txtAdresse.Text = strAdresse GoTo Quit Else intPos3 = InStr(intPos2, Text1.Text, " ") strAdresse = Mid(Text1.Text, intPos3, 4) End If If IsNumeric(strAdresse3) Then txtAdresse.Text = strAdresse GoTo Quit Else intPos4 = InStr(intPos3, Text1.Text, " ") strAdresse3 = Mid(Text1.Text, intPos4, 4) End If Quit: End Sub -----------------------------------------------------------------So, could anyone please try to figure out why it doesn''t work? - Simsfan

Share this post


Link to post
Share on other sites
Advertisement
Don''t assume that each chunk is of length 4 in your Mid calls.

Try this instead:

Public Function Break_String(ByRef Msg As String, ByVal Break_On As String) As String
Dim Lc As Integer
Dim Rt As String
Lc = InStr(Msg, Break_On)
If Lc = Len(Msg) And Lc <> 0 Then
Break_String = Left(Msg, Len(Msg) - 1)
Msg = ""
Exit Function
End If
If (Lc > 0) Then ''Is it in here?
Rt = Left(Msg, Lc - 1)
Msg = Mid(Msg, Lc + Len(Break_On))
Else
Rt = Msg
Msg = ""
End If
Break_String = Rt
End Function

...

Dim Something As String
Dim Substring As String
Something = InputBox("Enter something")

While Len(Something) > 0
Substring = Break_String(Something, " ")
MsgBox Substring
Wend

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!