Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable "Empty" or "Uninitialised" Please explain...

Status
Not open for further replies.

zollo9999

Programmer
May 12, 2002
95
AU
Hi

I'm not clear about when exactly a variable will have the value "Empty" I have read that it means the variable is "Uninitialised", but when does this occur, and when does this state/value change.

Is it when you have declared a variable but have not set a value?

Also, is it possible for an access field to have the empty value or is it just for variables?

I want to know if I need to use the IsEmpty() function along with IsNull and ="" to test the values in my database.

Thanks
Paul


Zollo A+ / VBA Developer
[thumbsup]
 
Only Variant type variables can be empty. Other data types initialize automatically to a default value. For example:
[tt]
Dim blnEmpty As Boolean 'automatically set to False
Dim strEmpty As String 'automatically set to vbNullString
Dim lngEmpty As Long 'automatically set to 0

Dim vEmpty As Variant
blnEmpty = IsEmpty(vEmpty) 'returns True
[/tt]
Some Properties can be Empty as well. For example, if a textbox control has no default value, its DefaultValue property is Empty.

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
One-liner test for empty, null or blank:
If Trim([thing to test] & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks to both of you for your replies.

PHV
I assume you mean in your reply that a "blank"
is a "" (zero length string)?

Or do you mean something like " "
(a string of blank spaces) ?

I'm cautious about using the term "blank" as it can be misunderstood or used incorrectly.

The test
Trim([thing to test] & "") = ""
is a great idea.

VBslammer
In my case I will not bother with the IsEmpty() test,
as I don't have any variant variables and I won't be looking for control properties either.

Cool dudes Thanks

Zollo A+ / VBA Developer
[thumbsup]
 
Due to concatenating with "", which creates a string, PHV's test will return True for both Null, ZLS, empty and space(s) (Trim function "removes" the spaces), and only return False if the field/control/variable contains other characters. In my opinion, one of the more reliable tests, though, it would return False also if the field/control/variable contains for instance only a carriage return character. I wouldn't use it on variants that can be other things than strings, though.

But do test it.

Here are two faqs on some of the terminology and how to deal with them faq707-3710, faq181-3884.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top