April 14th, 2005, 12:47 AM
|
#1 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
I've wrote a small VB program that except input through a textbox. After I wrote the program I want to know what is the code that will allow me to print out an error message when nothing is entered?
How can do it with a if statment? Like
if textbox1.text = null then
"label1.text = " No Input"
End If
Thats all i want to do....can anybody help?
RedFox
__________________
For the Emperor, there were the Jedi. For the Evil Empire of Microsoft, there is a penguin.
|
| |
April 14th, 2005, 01:03 AM
|
#2 (permalink)
| | Perfetc Member
Join Date: Jan 2003 Location: Maryland Suburbia
Posts: 4,327
|
isnt there an "isEmpty" method (function) or something?
Haven't used VB in awhile, but i dont see why this wouldnt work
if textBox1.text() = "' then
whatever
end if
Those are two quotation marks with no space inbetween them.
Last edited by VHockey86 : April 14th, 2005 at 01:10 AM.
|
| |
April 14th, 2005, 03:25 AM
|
#3 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
| |
| |
April 14th, 2005, 03:52 AM
|
#4 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
I keep getting a "cast from string "" to Integer is not valid"
whats that mean? |
| |
April 14th, 2005, 04:32 AM
|
#5 (permalink)
| | Ultimate Member
Join Date: Dec 2004
Posts: 1,558
|
Try: Code: If textbox1.Text = "" Then
label1.Text = "No Input"
End If If that doesn't work, check your data types (in all your statements) because something is wrong there. That's what's causing the type cast error. |
| |
April 14th, 2005, 10:48 AM
|
#6 (permalink)
| | Perfetc Member
Join Date: Jan 2003 Location: Maryland Suburbia
Posts: 4,327
|
... is your textbox somehow like a "number box" ?
I agree, that is very weird. I would think that everything is treated as a string from a text box.
Perhaps what you need to do is stop the current function if that error occurs.
It's probably trying to use that data later on in your program execution since setting a label to "no input" never actually stops the rest of it from executing.
You probably want to do something like
If Not textbox1.Text = "" Then
//call a function to continue execution
Else
label1.Text = "No Input", (might also want to consider using a message box here, not so discrete)
End If
Another way around it would be to set
textbox1.Text = 0 if there is no input (so, in the else statement above). |
| |
April 14th, 2005, 11:02 AM
|
#7 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,137
|
In the button code, put this:
If txtbox1.Text = "" Then MsgBox "No Input"
Second, just setting a label.Text to a variable will not update the forum until you do a frmWhatever.Refresh (I think is the method - it's been a while).
Third, since this isn't a multiple line statement If, you don't need to get fancy with an End If. Just tack a MsgBox behind the Then and call it a day.
BTW, the MsgBox makes a pop up box. If you WANT the form to be updated (not how you would normally want the program to work), then you should do the lblLabel.Text = "No Input" and frmForm.Refresh inside a normal If, Then, End If.
Make sense?  |
| |
April 14th, 2005, 11:07 AM
|
#8 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,137
| Quote: |
Originally Posted by VHockey86 isnt there an "isEmpty" method (function) or something? | isEmpty works if the variable is either set to empty, or the variable is uninitialized. Even if there's no input to the box, I believe it will still be "" rather than empty. |
| |
April 14th, 2005, 11:46 AM
|
#9 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
|
The code that you would need to have is: Code: Private Sub subCheck()
If text1.text = “” then
‘If there is no input
Lable1.caption = “No Input”
Else
‘If there is input
Lable1.caption = “Input”
End if
End Sub Then just call subCheck when you needed to check.
-Blaze |
| |
April 14th, 2005, 11:47 AM
|
#10 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 21,026
|
have you tried
If CStr(txtBox.Text) = "" Then
OR Worst case scenario
Dim vSomeVar As Variant
vSomeVar = txtBox.Text
If vSomeVar = "" Then
or even worster scenario (this shouldn't even work seeing as a text box can't handle a NULL value
If IsNull(txtBox.Text) Then |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |