String functions run on empty string
am 11.07.2007 19:55:17 von Tim SlatteryI 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?
--
Tim Slattery
MS MVP(DTS)
Slattery_T@bls.gov
http://members.cox.net/slatteryt