Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am taking a VB course in school and i am messing around with VB. But I have a question. How do you say "If txt1 (which is a textbox) has ANY sort of charatcer in it Then do this action
Else
do this action.So something like this
If txt1 (has a character in it) Then
"Do action"
Else
"DO this action
End IF
and I looking for the command that tells the computer that txt1 has a character in it.
Thanks

no i mean if txt1 HAS a character in it. Like "3" or "g" or anything than do something. Not if it has nothing in it.

Dan explained it, here it is again:
If txtText1.Text = "" then
...'string is empty
else
...'string isn't empty
end ifor
If txtText1.Text "" then
...'string is not empty
else
...'string is empty
end ifor
you could use Len(txtText1.Text) to return the number of characters in the textbox
Grant

The symbols for greater than and less than do not appear on these boards, as they are interpretted as HTML tags.
What Grant typed in (I guess) was:
If txtText1.Text {} "" then
...'string is not empty
else
...'string is empty
end ifwhere the "{}" is actually less-than/greater-than symbols which you cannot print here as they are interpretted as HTML tags.
However, if you insist on having ANOTHER way of doing it, then try:
If Not (txtText1.Text = "") then
Msgbox("Text")
Else
Msgbox("No Text")
End If
Cheers all
Tom

I think you're looking for a select case:
iePrivate Sub Command1_Click()
Select Case Text1.Text
Case "3"
MsgBox "3 is a great number..."
Case "g"
MsgBox "g is the best letter..."
Case Else
MsgBox "Something else..."
End Select
End SubJimbo

For the pedants:
Thought of another way:
If TextBox1.Text Like "?*" Then
Msgbox "Character(s)"
Else
Msgbox "No Characters"
End if? = at least one character
* = plus none or any more charactersTom

Are you sure it was the only answer that worked... ;)
(Anyway - its always good to have a few answers for every situation.)
Cheers
Tom

Easy......
if txt1.text "" Then 'Not equal to nothing
Do this
Else
Do this 'if hv char on it
End If

'parse out each member
'inefficient but easy
Do
lPos = InStr(lEnd + 1, sText, "") ")
If lPos = 0 Then Exit Do
lEnd = InStr(lPos + 9, sText, "
If lEnd = 0 Then
Exit Do
Else
lPos = lPos + 8
End If
colMembs.Add Mid$(sText, lPos, lEnd - lPos)
Loop

'parse out each member
'inefficient but easy
Do
lPos = InStr(lEnd + 1, sText, "[member>")
If lPos = 0 Then Exit Do
lEnd = InStr(lPos + 9, sText, "")
If lEnd = 0 Then
Exit Do
Else
lPos = lPos + 8
End If
colMembs.Add Mid$(sText, lPos, lEnd - lPos)
Loop

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |