Computing.Net > Forums > Programming > An easy VB question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

An easy VB question

Reply to Message Icon

Name: Dan
Date: March 3, 2002 at 08:14:17 Pacific
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Mikko
Date: March 3, 2002 at 08:38:26 Pacific
Reply:

It's quite easy:)

(txtText1 is the name of the text box)

If txtText1.Text = "" then
...
else
...
end if


0

Response Number 2
Name: Dan
Date: March 3, 2002 at 20:44:41 Pacific
Reply:

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.


0

Response Number 3
Name: Grant
Date: March 4, 2002 at 05:41:01 Pacific
Reply:

Dan explained it, here it is again:

If txtText1.Text = "" then
...'string is empty
else
...'string isn't empty
end if

or

If txtText1.Text "" then
...'string is not empty
else
...'string is empty
end if

or

you could use Len(txtText1.Text) to return the number of characters in the textbox

Grant


0

Response Number 4
Name: A Certain TH
Date: March 4, 2002 at 07:16:25 Pacific
Reply:

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 if

where 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


0

Response Number 5
Name: jimbojones
Date: March 4, 2002 at 07:37:15 Pacific
Reply:

I think you're looking for a select case:
ie

Private 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 Sub

Jimbo



0

Related Posts

See More



Response Number 6
Name: A Certain TH
Date: March 4, 2002 at 08:08:28 Pacific
Reply:

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 characters

Tom


0

Response Number 7
Name: Vijay
Date: March 4, 2002 at 09:23:43 Pacific
Reply:

Please use the VB in built function InStr to find if the text contains the character u want.


0

Response Number 8
Name: Dan
Date: March 4, 2002 at 14:46:44 Pacific
Reply:

thanks everyone. thanks A Certain the the "Not" thing worked!


0

Response Number 9
Name: **fubar**
Date: March 5, 2002 at 05:08:21 Pacific
Reply:

Type this

If txt1= (wanted txt) Then
(do action)
else
goto Error Handler
end if


0

Response Number 10
Name: A Certain TH
Date: March 5, 2002 at 07:08:40 Pacific
Reply:

Are you sure it was the only answer that worked... ;)

(Anyway - its always good to have a few answers for every situation.)

Cheers
Tom


0

Response Number 11
Name: Neo
Date: March 9, 2002 at 08:37:19 Pacific
Reply:

Easy......

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


0

Response Number 12
Name: test
Date: June 17, 2002 at 14:13:13 Pacific
Reply:

'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


0

Response Number 13
Name: test
Date: June 17, 2002 at 14:14:33 Pacific
Reply:

'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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: An easy VB question

Command counting in VB! www.computing.net/answers/programming/command-counting-in-vb/4678.html

Easy VB Question www.computing.net/answers/programming/easy-vb-question/4002.html

Easy VB Question www.computing.net/answers/programming/easy-vb-question/9986.html