Number comparison error

P

PW

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
 
B

Bob Barrows [MVP]

PW said:
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
 
P

PW

Bob Barrows said:
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
 
D

dlbjr

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

End If
End If

-dlbjr

Discerning resolutions for the alms
 
P

PW

dlbjr said:
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.
 
R

Roland Hall

in message :
: : > 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
 
P

PW

Roland Hall said:
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
 
R

Roland Hall

in message :
: : > 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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top