home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1695
Discussions: 188,401, Posts: 2,243,608, Members: 232,632
Old April 14th, 2005, 12:47 AM   Digg it!   #1 (permalink)
Member
 
redfoxstorm's Avatar
 
Join Date: Feb 2005
Posts: 386
VB Help with Void Null

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.

redfoxstorm is offline   Reply With Quote
Old April 14th, 2005, 01:03 AM     #2 (permalink)
Perfetc Member
 
VHockey86's Avatar
 
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.
VHockey86 is offline   Reply With Quote
Old April 14th, 2005, 03:25 AM     #3 (permalink)
Member
 
redfoxstorm's Avatar
 
Join Date: Feb 2005
Posts: 386
didn't work

redfoxstorm is offline   Reply With Quote
Old April 14th, 2005, 03:52 AM     #4 (permalink)
Member
 
redfoxstorm's Avatar
 
Join Date: Feb 2005
Posts: 386
I keep getting a "cast from string "" to Integer is not valid"

whats that mean?
redfoxstorm is offline   Reply With Quote
Old 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.
large_nostril is offline   Reply With Quote
Old April 14th, 2005, 10:48 AM     #6 (permalink)
Perfetc Member
 
VHockey86's Avatar
 
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).
VHockey86 is offline   Reply With Quote
Old April 14th, 2005, 11:02 AM     #7 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,137
Blog Entries: 7
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?
Whir is online now   Reply With Quote
Old April 14th, 2005, 11:07 AM     #8 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,137
Blog Entries: 7
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.
Whir is online now   Reply With Quote
Old April 14th, 2005, 11:46 AM     #9 (permalink)
Ultimate Member
 
Join Date: Jan 2003
Location: MA / NH
Posts: 1,497
Send a message via AIM to Blazer06
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
Blazer06 is offline   Reply With Quote
Old 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
vass0922 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Null and Void according to California Supreme Court FTM IMO Community 7 August 13th, 2004 01:16 AM
C++ question on void functions. Elburn Webmastering and Programming 6 February 12th, 2004 08:35 PM
Arctic Sillver will void your AMD warranty. Theophylact Processors, Memory, and Overclocking 13 April 30th, 2003 10:05 PM
redhat null: anyone know about it? storm2k Applications and Operating Systems 3 August 24th, 2002 01:55 PM
XML to void out the C language? newbie~wan Webmastering and Programming 31 April 2nd, 2002 11:41 AM

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Unarmed man on his stomach shot by .. (6)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
For cheap price and good qualit.. (1)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:21 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28