473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Is Len(xx) = 0 check same as IsNull check?

Hi all

In my functions I'm using a double-check all the time to trap if a value has
nothing in it and my question is do I need this double-check.

My check line is:

IF IsNull(xxx) OR LEN(xxx) = 0 THEN

blah blah

ELSE

blah blah

END IF

xxx is usually an array built up of data from an ADO recordset so will
LEN(xxx) = 0 cover my zero values or do I still need the IsNull check as
well?

Thanks

Nov 22 '05 #1
4 10242
Laphan wrote on 15 nov 2005 in microsoft.public.inetserver.asp.general:
IF IsNull(xxx) OR LEN(xxx) = 0 THEN
blah blah
ELSE
blah blah
END IF

xxx is usually an array built up of data from an ADO recordset so will
LEN(xxx) = 0 cover my zero values or do I still need the IsNull check
as well?


What is "the zero values" of an array?
NonExisting or
Empty or
filled with empty strings?

The length of a vbs array is found by ubound()
len() returns the character length of a string
[This is different in javascript, where .length does both]

What were your test results?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 22 '05 #2
Laphan wrote:
Hi all

In my functions I'm using a double-check all the time to trap if a
value has nothing in it and my question is do I need this
double-check.

My check line is:

IF IsNull(xxx) OR LEN(xxx) = 0 THEN

blah blah

ELSE

blah blah

END IF

xxx is usually an array built up of data from an ADO recordset so will
LEN(xxx) = 0 cover my zero values or do I still need the IsNull check
as well?

To answer the question in the subject line:
No
IsNull("") will return false
IsNull(Null) will return true
(len(Null)=0) will return Null
(len("")=0) will return true

However, you can shorten your statement by taking advantage of a strange
behavior in vb/vbscript: concatenating a string to a null will result in a
string, NOT in a null. This is not the expected behavior because most other
operations involving Null will result in Null (1 + null results in null).
So:
IF len(xxx & "") = 0 THEN
will serve your purpose

The answer may not be the same in other languages.

However, if xxx should be an array, then you need to use IsArray to test
whether or not it is an array. If you mean that you want to test a
particular element in the array, i.e., xxx(0), then yes, use len(xxx(0) &
"")=0. Only use IsNull if you want to specifically check for Null.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Nov 22 '05 #3

"Laphan" <in**@SpamMeNot.com> wrote in message
news:ee**************@TK2MSFTNGP10.phx.gbl...
Hi all

In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check.

My check line is:

IF IsNull(xxx) OR LEN(xxx) = 0 THEN

blah blah

ELSE

blah blah

END IF

xxx is usually an array built up of data from an ADO recordset so will
LEN(xxx) = 0 cover my zero values or do I still need the IsNull check as
well?


I believe the short answer to your opening question is, "No."

Null is an undefined value and is used to indicate that a variable contains
no valid data.

Empty is used to indicate an uninitialized variable but it is not the same
thing as Null.

"" is a value whose Len() is zero but is not the same thing as either Null
or Empty.

To cover the bases you might want to consider something like:

If IsNull(str) Or IsEmpty(str) Or Len(str) = 0 Then

There is also an IsNothing() but it applies to objects that were Set.
Nov 22 '05 #4
Many thanks guys

brilliant advice as always.

Rgds Laphan
"MyndPhlyp" <no****@homeright.now> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Laphan" <in**@SpamMeNot.com> wrote in message
news:ee**************@TK2MSFTNGP10.phx.gbl...
Hi all

In my functions I'm using a double-check all the time to trap if a value has nothing in it and my question is do I need this double-check.

My check line is:

IF IsNull(xxx) OR LEN(xxx) = 0 THEN

blah blah

ELSE

blah blah

END IF

xxx is usually an array built up of data from an ADO recordset so will
LEN(xxx) = 0 cover my zero values or do I still need the IsNull check as
well?


I believe the short answer to your opening question is, "No."

Null is an undefined value and is used to indicate that a variable contains
no valid data.

Empty is used to indicate an uninitialized variable but it is not the same
thing as Null.

"" is a value whose Len() is zero but is not the same thing as either Null
or Empty.

To cover the bases you might want to consider something like:

If IsNull(str) Or IsEmpty(str) Or Len(str) = 0 Then

There is also an IsNothing() but it applies to objects that were Set.

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tu Quach | last post by:
Hi there, how are you? I have question, assume I have a text box and gave it a format date&time, how can I check when it is empty or not empty I use the code as if frm_form!txt_name1 = Null...
5
by: Krechting | last post by:
Hi ALl, I have a code that checks if the documents in a hyperlink field are still where they should be. I use fileexist(). First I want to filter out all the hyperlink fields that are empty. I...
4
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if...
4
by: briancfk | last post by:
I now converting vb6 code to vb.net code Let me descrip my problem first i got a Function e.g. Public Function Method1(Byval ar as object, Optional ByVal strWHFrom As String, Optional ByVal...
3
by: ferg | last post by:
I have a Customer table. The table has two different CHECK constraints. Then there is the Customer details dialog, which provides the user with an UI for changing users. I have some UPDATE sql,...
4
by: tlyczko | last post by:
I have this code to run in a form button OnClick event to make sure the start and end dates for reports have been entered, in case the end user goes right to the buttons without typing any dates,...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
5
by: Andrew Meador | last post by:
I have a form (Change Card List by Status) with a check box (cboNOT) and a list box (lstStatus). There is an Open Report button that opens a report (Report - Change Card List) which uses a query...
1
by: Lynx101 | last post by:
I've got the following code to work, but the problem is that it is check all fields on every record. Is there a way to make this work on one particular field AND only the current record? Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.