String functions run on empty string

T

Tim Slattery

I have a form in which several elements are expected to be all digits.
Some of those elements can be left empty, but if specified they must
be all digits. I have this Sub to edit them:

Sub NumEdit(ByRef Req, ByVal value, ByRef size, ByRef name, ByRef tag)
Dim allDigs
Set allDigs = new RegExp
allDigs.Pattern = "^\d+$"

If IsNull(value) Then
value = ""
Else
value = trim(value)
End If

If len(value) = 0 Then
If Req = false Then
Return
Else
AddMessage name & " must be supplied.", tag
End if
ElseIf size > 0 And len(value) <> size Then
AddMessage name & " must be " & size & " characters.", tag
ElseIf allDigs.test(value) = false Then
AddMessage name & " must be numeric.", tag
End If
End Sub


It's invoked by a line like this:
NumEdit false, Request.Form("zip"), 5, "Zip code", "zip"

In this case, the "zip" element is not required, but if present it
must be exactly five digits. (AddMessage stores an error message. It
works fine).

When zip is not given, the page blows up. I've experimented with
taking the values of various functions of Request.Form("zip"), with
the following results:

zip=
IsEmpty(zip)=False
IsNull(zip)=False
Len(zip)=0
Trim(zip)=
IsEmpty(Trim(zip))=
IsNull(Trim(zip))=
len(Trim(Zip))=

So Request.Form("zip") is not Empty, it's not Null, and its Len is 0.
But once I apply Trim to it, everything goes to heck. IsEmpty, IsNull,
and Len return nothing at all, and I get no error message.

What's happeneing?
 
T

Tim Slattery

Tim Slattery said:
I have a form in which several elements are expected to be all digits.
Some of those elements can be left empty, but if specified they must
be all digits. I have this Sub to edit them:

Sub NumEdit(ByRef Req, ByVal value, ByRef size, ByRef name, ByRef tag)
Dim allDigs
Set allDigs = new RegExp
allDigs.Pattern = "^\d+$"

If IsNull(value) Then
value = ""
Else
value = trim(value)
End If

If len(value) = 0 Then
If Req = false Then
Return

Ugh! Now I find out that "Return" is not valid VBScript, I have to use
Exit Sub.

That makes the Sub work. I still don't understand the results I
reported lower down, but it doesn't matter much now.
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top