Results 1 to 4 of 4

Thread: [RESOLVED] checking for spacebar values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Resolved [RESOLVED] checking for spacebar values

    I am almost too embarassed to post this, but I am stuck and need it fixed.. I have a textbox where the user has to enter a value before I perform the function..I checked for " ", which works if nothing is entered, BUT if the user uses the spacebar my check doesn't work.. I have tried "", IsNumeric, not IsNumeric, VBNullString, but nothing seems to trap it... This is really silly, please humor me... also it is legit to have blanks within the string or to be numeric ..
    Thanks

    '== check all the characters to see if they are all blanks
    Dim i As Integer
    Dim length As Integer
    Dim CharFound As Boolean
    CharFound = False
    length = Len(txtValue.Text)

    For i = 1 To length
    If Mid(txtValue.Text, i) <> " " Then
    CharFound = True
    Exit For
    End If
    Next

    If CharFound = False Then
    MsgBox "Please enter a search value.", vbExclamation, "Find"
    Exit Sub
    End If

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    Re: checking for spacebar values

    Hey, depending upon what you are trying to do, do you think that the trim method can work. Like since you dont want spaces, using Trim(str) will give u str without spaces. Or you can try

    Dim str As String
    str = "lah bla"
    MsgBox InStr(1, str, " ")

    For my case the msgbox returns a 4, if its a 0 then there is no space. Does this help? Or did I confuse you completely?

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: checking for spacebar values

    use Trim$ to strip spaces and check that, e.g.
    VB Code:
    1. If Len(Trim$(Text1.Text)) Then
    2.     ' There's something there
    3. Else
    4.     MsgBox "Please put something in"
    5. End If

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: checking for spacebar values

    WOW, that was a fast response, and a perfect answer.. The TRIM worked like a charm..
    Thanks so much guys..

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