Results 1 to 2 of 2

Thread: how to determine if a number is present in a string?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    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


  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [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]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width