PDA

View Full Version : Variable Type Confusion


gorilla1
11-07-2002, 07:44 PM
I am passing a variable to a routine with a query string like so:
?id=0 In the called routine, I assign fPtr equal to the value from id, and I compare the id value with a counter (cntr) and break from a loop if equal by way of this statement:
if cntr = fPtr then break
. To debug this, i wrote the counter and the id variable out to the screen. Even though cntr and ptr both show up as zero in the writes to the screen, the loop never breaks. Is this because cntr somehow is an integer and fPtr is a character string? How do I get them to both be numeric variables?

G

whammy
11-07-2002, 09:55 PM
You can use a type conversion function... i.e.:

Asc()
CBool()
CByte()
CCur()
CDate()
CDbl()
CInt()
CLng()
CSng()
CStr()

If you want to see what type of variable each one is, use TypeName() around them both. ;)

P.S. If you're using whole integers, use CInt() to convert from anything to Integer; if you're using floating point numbers, use CDbl().

But before you do that, you probably want to check to make sure it's numeric... i.e.:

If IsNumeric(yourvariable) Then
If CInt(yourvariable) = thevariableyouknowisaninteger Then
'Do something
End If
Else
Response.Write("It isn't a number! Yikes!")
End If

allida77
11-07-2002, 11:36 PM
I always use VarType() (http://www.devguru.com/Technologies/vbscript/quickref/vartype.html)

Then see what value is returned to determine variable type. From there you should be able debug.

whammy
11-08-2002, 12:07 AM
That too! :)

As a matter of fact I put that in my TextPad ClipBook (along with countless other commands) less than 2 horus ago. LOL.

P.S. I'm not sure who recommended TextPad, but geez, it rocks.

gorilla1
11-08-2002, 01:15 AM
Ah, thanks. That did the trick.

G