Jump to content
  • Advertisement


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


VB string search help

This topic is 5481 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
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))
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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!