Is it possible to evaluate a string to determine if at least one number is present within the string, returning True if so and False if not?
thanks,
Dan
Printable View
Is it possible to evaluate a string to determine if at least one number is present within the string, returning True if so and False if not?
thanks,
Dan
[code]
'check a string to see if a character is a number
Option Explicit
Dim strString As String
Function strCheck(sstring As String) As Boolean
strCheck = False
Dim sLetter As String
Dim intCre, sCount, sAscNum As Integer
'loop to the end of the text in textbox
'get the ascii number of each letter
For intCre = 1 To Len(strString)
sLetter = Mid(strString, intCre, 1)
sAscNum = Asc(sLetter)
'check each ascii number to be sure it is a number or decimal
'if it is then count one for the character in question
If sAscNum > 47 And sAscNum < 58 Then
sCount = sCount + 1
End If
Next intCre
'if they are all numbers or deciamls then the count should
'be equal to the number of characters in the textbox
If sCount > 0 Then strCheck = True
End Function
Private Sub Command1_Click()
'string to check
strString = "My my, I wonderer if a number like 2 or something is here?"
MsgBox strCheck(strString)
End Sub
[code]