|
-
Dec 18th, 2006, 10:59 AM
#1
Thread Starter
Addicted Member
[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
-
Dec 18th, 2006, 11:04 AM
#2
Lively Member
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?
-
Dec 18th, 2006, 11:11 AM
#3
Re: checking for spacebar values
use Trim$ to strip spaces and check that, e.g.
VB Code:
If Len(Trim$(Text1.Text)) Then
' There's something there
Else
MsgBox "Please put something in"
End If
-
Dec 18th, 2006, 11:37 AM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|