String functions run on empty string

Discussion in 'ASP General' started by Tim Slattery, Jul 11, 2007.

  1. Tim Slattery

    Tim Slattery Guest

    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)

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jul 11, 2007
    #1
    1. Advertising

  2. Tim Slattery

    Tim Slattery Guest

    Tim Slattery <> wrote:

    >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)

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jul 11, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,062
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    864
    spiff
    Nov 10, 2005
  3. Xiangliang Meng
    Replies:
    1
    Views:
    1,659
    Victor Bazarov
    Jun 21, 2004
  4. Tzury Bar Yochay
    Replies:
    1
    Views:
    420
    Gabriel Genellina
    Mar 24, 2008
  5. Savvoulidis Iordanis

    Empty gridview cells and checking for empty string

    Savvoulidis Iordanis, Sep 5, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    557
    Savvoulidis Iordanis
    Sep 5, 2008
Loading...

Share This Page