www.webdeveloper.com
Results 1 to 7 of 7

Thread: Less Than Greater Than Issue

  1. #1
    Join Date
    Feb 2006
    Location
    Springfield, MO
    Posts
    71

    Less Than Greater Than Issue

    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.
    Buzzards got to eat same as worms.

  2. #2
    Join Date
    Nov 2002
    Posts
    4,473
    Maybe it is a string instead of a number?

  3. #3
    Join Date
    Feb 2006
    Location
    Springfield, MO
    Posts
    71
    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?
    Buzzards got to eat same as worms.

  4. #4
    Join Date
    Nov 2002
    Posts
    4,473
    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:
    Code:
    If (minimum * 1) > (dbRate * 1) Then

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia
    Posts
    125
    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.

    If only we could declare variable types in ASP
    </VANNY>

  6. #6
    Join Date
    Feb 2006
    Location
    Springfield, MO
    Posts
    71
    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?

    The article was http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=53
    Buzzards got to eat same as worms.

  7. #7
    Join Date
    Feb 2003
    Posts
    2,745
    always cast the values.

    If cdbl(minimum) > cdbl(dbRate) Then

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles