VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This function returns the numeric value string within another string.

by Trinh Nguyen (4 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 27th July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This function returns the numeric value string within another string.

API Declarations


'Start the Standard exe project
'Load a form
'Add a text box name text1.txt on a form
'Please note that the For Loop is start to search the from the first char
'to the last char in the string until the values are found.


Rate This function returns the numeric value string within another string.




  Dim SearchString, c1, c2, c3 As String
  Dim FoundNumber As Integer
  Dim i As Integer

  SearchString = "Look for a number12345in this string"

  'Given a For Loop to search for numeric value
  For i = 1 To Len(SearchString) - 2
     c1 = Mid(SearchString, i, 1)
     c2 = Mid(SearchString, i + 1, 1)
     c3 = Mid(SearchString, i + 2, 1)
     If c1 >= "0" And c1 <= "9" Then
          If c2 >= "0" And c2 <= "9" Then
                If c3 >= "0" And c3 <= "9" Then
                       FoundNumber = 1
                       Exit For
                End If
          End If
     End If
  Next

  If FoundNumber = 1 Then
      Text1.txt = Val(Mid(SearchString, i))
  Else
      Text1.txt = "Found Nothing"
  End If
End Sub
 'When the Form is loaded, the text box will show only the group of numeric 
 'number in the Search String.


Download this snippet    Add to My Saved Code

This function returns the numeric value string within another string. Comments

No comments have been posted about This function returns the numeric value string within another string.. Why not be the first to post a comment about This function returns the numeric value string within another string..

Post your comment

Subject:
Message:
0/1000 characters