Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

greater than or less than when numeric

Status
Not open for further replies.

camillaj

Programmer
Sep 18, 2003
31
AU
I'm very new to ASP and VB, but this doesn't make sense to me at all.

I'm checking whether a value is greater than an other, i.e.

If questNr > Session("LastAdded") Then
..do something
Session("LastAdded") = questNr
End If

This works fine until questNr is '10' and lastAdded is '9'. Then it says that questNr (10) is les than lastAdded (9). I write these values out to the screen, so I know that for sure.

How can 10 be less than 9? I guess this mayhave something to do with the datatype. questNr is just a number I retrieve from Request.Form("questNr")

Thanks :)
 
All the built-in ASP objects return STRINGs as a general rule - that's Session, Request etc etc.

So if you want to compare them to a number, you need to explicitly convert them to a number. Otherwise they get compared alphabetically: "100" gets filed before "9" in the phonebook (if they were business names).

To convert: try CInt() or CDbl() or whatever suits.

Good luck

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
yep this must work...
If cint(questNr) > cint(Session("LastAdded")) Then
..do something
Session("LastAdded") = questNr
End If


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top