I am trying to compare two values in an if statement using the greater than operator <. This isn't working. I get a negative response regardless of the data entered. Any help would be appreciated.
Code:
dbRate =rstemp(20)
If minimum > dbRate Then
response.write("The entered number is bigger <br>")
Else
response.write("The entered number is smaller <br>")
End If
response.write(minimum & " is what was entered, compared to what is in the valid rate "& dbRate & "<br>")
And for the values entered where minimum = 200 and dbRate = 216 I get this response
The entered number is bigger
200 is what was entered, compared to what is in the valid rate 216.
Just wondering if I am using the wrong operators. Or how I can get this to work.
I am pulling the dbRate number from a database and I know it is a number. The other numbre is coming from a text box on the calling page. Should I convert that to a number. And if so how would I go about that?
Form fields and SQL data fields in ASP pages are always strings. VBScript automatically converts strings and numbers, but not always as you would expect. If you use some math then you can guarantee that it will use numeric compare. Something like:
you can look at adding some error handling to stop people crashing it by entering characters
Code:
dbRate =rstemp(20)
IF isNumeric(minimum) = TRUE THEN
If minimum > dbRate Then
response.write("The entered number is bigger <br>")
Else
response.write("The entered number is smaller <br>")
End If
response.write(minimum & " is what was entered, compared to what is in the valid rate "& dbRate & "<br>")
ELSE
response.write "not a number entered"
END IF
If the field in the database type is number/numeric it will always return that way, the form field however may not. If your numbers are always going to be less that approx (32,000) you count use cint(minimum) to make sure it is in a number format.
Thanks, that actually seems alot easier then what I found. I found an article that used a function to "scrub" any non-numeric characters from then string, then i multiplied times one to be sure it was a number.
Question, actually two. Would the IsNumeric accept it if it has a decimal, and is there such a thing as a CDouble just in case there might be a larger number?
Bookmarks