Number comparison error

Discussion in 'ASP General' started by PW, May 23, 2004.

  1. PW

    PW Guest

    I'm trying to interrogate an incoming value from a previous ASP like this
    ....

    myCurrentQty = request.querystring("txtBCQty" & myRecordCounter)

    It returns a "2" as expected.

    But if I try to compare its value to another number, like this ...

    if myCurrentQty > 0 then

    .... I get this error ...

    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch: 'myCurrentQty'
    rep_barcode2.asp, line 57

    If I try to convert it to a number, like this ...

    if Cint(myCurrentQty) > 0 then

    I get another error ...

    Error Type:
    Microsoft VBScript runtime (0x800A000D)
    Type mismatch: 'Cint'
    rep_barcode2.asp, line 57



    Not quite sure where I'm going wrong here.

    Any help appreciated.

    Thanks,
    PW
     
    PW, May 23, 2004
    #1
    1. Advertising

  2. PW wrote:
    > I'm trying to interrogate an incoming value from a previous ASP like
    > this ...
    >
    > myCurrentQty = request.querystring("txtBCQty" & myRecordCounter)
    >
    > It returns a "2" as expected.
    >
    > But if I try to compare its value to another number, like this ...
    >
    > if myCurrentQty > 0 then
    >
    > ... I get this error ...
    >
    > Error Type:
    > Microsoft VBScript runtime (0x800A000D)
    > Type mismatch: 'myCurrentQty'
    > rep_barcode2.asp, line 57
    >
    > If I try to convert it to a number, like this ...
    >
    > if Cint(myCurrentQty) > 0 then
    >
    > I get another error ...
    >
    > Error Type:
    > Microsoft VBScript runtime (0x800A000D)
    > Type mismatch: 'Cint'
    > rep_barcode2.asp, line 57
    >


    Hmmm - show us the result of:

    response.write "myCurrentQty contains """ & myCurrentQty & """"

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], May 23, 2004
    #2
    1. Advertising

  3. PW

    PW Guest

    "Bob Barrows [MVP]" <> wrote in message
    news:...
    > Hmmm - show us the result of:
    > response.write "myCurrentQty contains """ & myCurrentQty & """"



    I'll go one further and show you the variable type as well ...

    myCurrentQty = request.querystring("txtBCQty" & myRecordCounter)
    response.write "myCurrentQty contains """ & myCurrentQty & """"
    if isnumeric("myCurrentQty") then
    response.write "number"
    else
    response.write "char"
    end if
    response.end


    Results are ...

    myCurrentQty contains "2"
    char
     
    PW, May 23, 2004
    #3
  4. PW

    dlbjr Guest

    myCurrentQty = Trim(myCurrentQty )
    If IsNumeric(myCurrentQty ) Then
    If CInt(myCurrentQty ) > 0 Then

    End If
    End If

    -dlbjr

    Discerning resolutions for the alms
     
    dlbjr, May 23, 2004
    #4
  5. PW

    PW Guest

    "dlbjr" <> wrote in message
    news:...
    > myCurrentQty = Trim(myCurrentQty )
    > If IsNumeric(myCurrentQty ) Then
    > If CInt(myCurrentQty ) > 0 Then
    >
    > End If
    > End If



    I don't think that will help. I know that myCurrentQty contains a number,
    the problem is that its a variable type of char and won't convert to a
    variable type of number.
     
    PW, May 24, 2004
    #5
  6. PW

    Roland Hall Guest

    "PW" wrote in message news:...
    :
    : "dlbjr" <> wrote in message
    : news:...
    : > myCurrentQty = Trim(myCurrentQty )
    : > If IsNumeric(myCurrentQty ) Then
    : > If CInt(myCurrentQty ) > 0 Then
    : >
    : > End If
    : > End If
    :
    : I don't think that will help. I know that myCurrentQty contains a number,
    : the problem is that its a variable type of char and won't convert to a
    : variable type of number.

    myCurrentQty = Int(Trim(Request.QueryString("txtBCQty"))) &
    Int(myRecordCounter)
    Response.Write("myCurrentQty contains " & myCurrentQty & " and is data type
    " & typename(myCurrentQty) & ".")
    if myCurrentQty > 0 Then
    ' do something
    else
    ' do nothing
    Response.End
    end if

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 24, 2004
    #6
  7. PW

    PW Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > myCurrentQty = Int(Trim(Request.QueryString("txtBCQty"))) &
    > Int(myRecordCounter)
    > Response.Write("myCurrentQty contains " & myCurrentQty & " and is data

    type
    > " & typename(myCurrentQty) & ".")
    > if myCurrentQty > 0 Then
    > ' do something
    > else
    > ' do nothing
    > Response.End
    > end if



    Now this is wierd !! I ran my code, and I got the error. I ran Rolands
    code, and no error. WHAT! Do it again. Run my code, get an error. Run
    Rolands code, no error! HUH!?!?

    I then realised that the error was not occurring on the first iteration of
    the loop, but on the 3rd, in which that label had not been given a quantity
    of labels to print, hence the variable was empty, and the error occurs. I
    fixed it by adding this little code snippet ...

    if myCurrentQty = "" then
    myCurrentQty = 0
    end if


    Thanks for your help guys,
    PW
     
    PW, May 25, 2004
    #7
  8. PW

    Roland Hall Guest

    "PW" wrote in message news:...
    :
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:...
    : > myCurrentQty = Int(Trim(Request.QueryString("txtBCQty"))) &
    : > Int(myRecordCounter)
    : > Response.Write("myCurrentQty contains " & myCurrentQty & " and is data
    : type
    : > " & typename(myCurrentQty) & ".")
    : > if myCurrentQty > 0 Then
    : > ' do something
    : > else
    : > ' do nothing
    : > Response.End
    : > end if
    :
    :
    : Now this is wierd !! I ran my code, and I got the error. I ran Rolands
    : code, and no error. WHAT! Do it again. Run my code, get an error. Run
    : Rolands code, no error! HUH!?!?
    :
    : I then realised that the error was not occurring on the first iteration of
    : the loop, but on the 3rd, in which that label had not been given a
    quantity
    : of labels to print, hence the variable was empty, and the error occurs. I
    : fixed it by adding this little code snippet ...
    :
    : if myCurrentQty = "" then
    : myCurrentQty = 0
    : end if

    So, persistance actually does pay off.

    : Thanks for your help guys,

    Anytime but you did it.
     
    Roland Hall, May 25, 2004
    #8
    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. Keith
    Replies:
    14
    Views:
    714
    Bengt Richter
    Mar 29, 2005
  2. Chandu
    Replies:
    3
    Views:
    336
    Emmanuel Delahaye
    Sep 19, 2005
  3. 一首诗
    Replies:
    2
    Views:
    336
  4. Deepu
    Replies:
    1
    Views:
    244
    ccc31807
    Feb 7, 2011
  5. Window Frog

    SIMPLE NUMBER COMPARISON

    Window Frog, Dec 28, 2007, in forum: Javascript
    Replies:
    8
    Views:
    143
    Dr J R Stockton
    Dec 31, 2007
Loading...

Share This Page