Compare number from DB to a form string in ASP

N

Noozer

I'm having a brainfart here...

Writing an ASP page and the following is never evaluating as true:
if request("Branch") = rsSet("BranchKey") then response.Write " selected
"

Branch is a SELECT value passed from a previous form submission.
BranchKey is a number stored in an MS Access database.

I'm assuming that the problem is that Branch returns a string (even though
it holds a number) and that rsSet("BranchKey") is returning a number and not
a string.

I've verified that both are returning similar values (ie Branch is "12" and
BranchKey is 12).

How can I make this comparison work? (or what group should I ask in - didn't
see anything ASP related)

Thanks!
 
A

Augustus

Noozer said:
I'm having a brainfart here...

Writing an ASP page and the following is never evaluating as true:
if request("Branch") = rsSet("BranchKey") then response.Write " selected
"

Branch is a SELECT value passed from a previous form submission.
BranchKey is a number stored in an MS Access database.

I'm assuming that the problem is that Branch returns a string (even though
it holds a number) and that rsSet("BranchKey") is returning a number and not
a string.

you are correct... all form items, even if its a number, come in as a string

First you want to check if request("branch") is numeric (just to be safe,
else you'll get a 500 asp error)

Then, if it is numeric you want to convert it to a number...

Something like:

IF ISNUMERIC(request("branch")) THEN
if CINT(request("Branch")) = rsSet("BranchKey") then response.Write "
selected"
END IF

ISNUMERIC() is a boolean function... it will return "true" if the item in
brackets is numeric... and "false" if it is not.
CINT() is a function that will convert a string or other number to an
integer. If it cannot convert the string it will return an error (I say "or
other number" because 12345 is an integer... 12345.678 is NOT an integer
because it has a decimal point with value other than 0 after it...
CINT(12345.678) would return 12345)
 
N

Noozer

Writing an ASP page and the following is never evaluating as true:
you are correct... all form items, even if its a number, come in as a string

First you want to check if request("branch") is numeric (just to be safe,
else you'll get a 500 asp error)

Then, if it is numeric you want to convert it to a number...

Something like:

IF ISNUMERIC(request("branch")) THEN
if CINT(request("Branch")) = rsSet("BranchKey") then response.Write "
selected"
END IF

ISNUMERIC() is a boolean function... it will return "true" if the item in
brackets is numeric... and "false" if it is not.
CINT() is a function that will convert a string or other number to an
integer. If it cannot convert the string it will return an error (I say "or
other number" because 12345 is an integer... 12345.678 is NOT an integer
because it has a decimal point with value other than 0 after it...
CINT(12345.678) would return 12345)

Thanks! That's just what I needed... I was trying to use VAL() .
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top