isEmpty(x) vs. x =

# Thread: isEmpty(x) vs. x =

1. Senior Member
Join Date
Dec 1969
Posts
184

## isEmpty(x) vs. x =

If these both perform the same operation, would it be more efficient to use the comparative (="") rather than call a function (isEmpty())? And if they aren&#039;t the same, then is one more preferred over another?<BR><BR>Example:<BR>If isEmpty(x) Then Response.Write("isEmpty")<BR>If x = "" Then Response.Write("=")

2. Senior Member
Join Date
Dec 1969
Posts
2,225

## RE: isEmpty(x) vs. x =

I usually do something like this:<BR><BR>If x & " " = " " Then<BR><BR>That way you catch both x = "" and x = NULL

3. Senior Member
Join Date
Dec 1969
Posts
11,334

## Same in theory

IsEmpty() is used to see if a variant has been intialized or not.<BR><BR>Since they&#039;re initalized to blank anyways, just do<BR><BR>Dim x<BR>if x = "" Then &#039;tis true

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Not true...

Any of *THREE* conditions will satisfy<BR> If x = "" Then<BR><BR>(1) when x is Empty<BR>(2) when x is Null<BR>(3) when x is the zero length string, ""<BR><BR>If you *really* want to check *specifically* for Empty, then only isEmpty() will do so.<BR><BR>Now, it&#039;s true that in VBS programming 98% of the time you don&#039;t care whether something is Empty, Null, or "" -- so use the IF version. So they may be the same in practice, but certainly not in theory.<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## Are you sure?

For all intents and purposes, I bet if you check for "" or isEmpty(), your results will be the same.<BR><BR>I&#039;d even bet if you checked 0, "", or IsEmpty they&#039;d be the same.<BR><BR>Maybe?

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Read AGAIN what I said...

I said *IN PRACTICE* they may be the same.<BR><BR>But they certainly *are not* the same *IN THEORY*.<BR><BR>They are completely different conditions!<BR><BR>An empty variable in VBS is one that has been DIM&#039;ed but never had anything assigned to it. VBS uses that condition to detect "no value has been assigned" errors. (Actually, JS is much more likely to use that condition; VBS often just ignores it.)<BR><BR>One distinction is that you can have an empty *variable* but you can never have an empty *expression* (well, other than the trivial case of an expression consisting of an empty variable).<BR><BR>A NULL value can be obtained in several ways. The most obvious is the assignment of the *predefined* value NULL to a variable (or that value being used in an expression).<BR><BR>Further, NULL is treated differently in comparision operations!<BR>http://msdn.microsoft.com/library/en-us/script56/html/vsgrpcomparison.asp<BR>Look what happens when one of the variables in a comparison is NULL! The result is then *always* NULL! No "type mismatch" error. Just a NULL result. It&#039;s what trips up people doing comparisons vs. null values *all the time*.<BR><BR>Finally, a zero length string is completely different! It *TRULY* is a value of Type String. If you do<BR> s = ""<BR> Reponse.Write TypeName(s)<BR>you *will* see "String" as the result.<BR><BR>So you might be able to *treat* variables the same way (especially using that<BR> If ("" & var) = "" Then<BR>trick) but the three types are separate and distinct.<BR><BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
184

## RE: Same in theory

No more worrying:<BR><BR>Function isVarEmpty(item)<BR>&nbsp;&nbsp;isVarEmpty = CBool(IsEmpty(item) Or IsNull(item) Or item = "")<BR>End Function

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sure, but overkill...

I have never found a situation where Chris&#039;s solution wouldn&#039;t work. No matter what the source of the null/empty/zero-length-string.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•