472,145 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

String functions run on empty string

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?

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
http://members.cox.net/slatteryt
Jul 11 '07 #1
1 2512
Tim Slattery <Sl********@bls.govwrote:
>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.

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
http://members.cox.net/slatteryt
Jul 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

99 posts views Thread by David MacQuigg | last post: by
8 posts views Thread by Duncan Winn | last post: by
4 posts views Thread by AVL | last post: by
35 posts views Thread by jacob navia | last post: by
9 posts views Thread by WebArchitect | last post: by
reply views Thread by leo001 | last post: by

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.