Stephen Lebans Code Puzzle

G

Guest

Hi All

I recently downloaded some code from Stephen Lebans Web site to convert
Access reports into PDF files (which is brilliant by the way). I noticed that
the following code snippet is used occasionally :-

If Len(mUncompressedSnapFile & vbNullString) > 0 Then

I don't quite understand the reason for the vbNullString in this code, could
anyone explain it. The variable 'mUncompressedSnapFile' is a normal string
variable.
 
D

Douglas J. Steele

You sure mUncompressedSnapFile is a string, and not a variant?

When it's possible that a value could be either a zero-length string ("") or
Null, it's more efficient to use

If Len(mUncompressedSnapFile & vbNullString) > 0 Then

than

If Not IsNull(mUncompressedSnapFile) Then
If Len(mUncompressedSnapFile) > 0 Then

or

If Not IsNull(mUncompressedSnapFile) Then
If mUncompressedSnapFile <> "" Then

In other words, what Stephen's doing there is making sure that
mUncompressedSnapFile contains a non-blank string.
 
G

Guest

Hi Douglas and Terry

The variable in question is definitely declared as a String, however,
looking through the rest of the code I notice that this method is also used
against values that are passed as in-line variables in Functions which could
be Null values (maybe). Perhaps Stephen always uses the same technque for
checking a zero length string without worrying about what type of variable it
is.

Anyway, thanks for the information.
 
S

Stephen Lebans

Michael Kaplan told me this was the most efficient method to check for a
zero length string. I've been doing it ever since.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
T

Terry Kreft

Yes, I can see that as
"" & vbNullString = vbNullString

and there has been a long discusion elsewhere as to why testing for
Len(vbNullString) is more efficient than testing for Len("").


--

Terry Kreft


Stephen Lebans said:
Michael Kaplan told me this was the most efficient method to check for a
zero length string. I've been doing it ever since.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
T

Terry Kreft

I know, my statement was that "_originally_ Stephen ...".

Anyway Stephens replied elswhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top