Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form validation Greater than not a number

    I am trying to validate the value of one text box to the value of another. The text box hold a number and I want it to check if it is greater than the value of another number (this number is dynamic depending on the page loaded)

    Code:
    dim InputError,Reason
    InputError=0
    
    If Len(inventory) > Len(allocation) Then
    	Reason = "<strong>ERROR:</strong> inventory can not be greater than allocation!!"
    	InputError=InputError+1
    end if
    if InputError = 0 then
    
    
    rsUpdateEntry.Update
    As you can see I'm trying to get the inventory value=5 to check if it is greater that the allocation value=4, if it is, return error message.

    This is not working, does anyone know how to validate the values of two fields that will who's values will change dependent upon the page loaded?

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    The variables inventory and allocation are the values you're getting from your form?

    They're numbers?

    If so, stop using Len(). Len() returns the number of characters in a string. What you want to do is:

    Code:
    if cInt(inventory) > cInt(allocation) then
    ' the integer value of inventory is greater than the integer value of allocation and you need to throw an error
    end if

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,070
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Or you may want to use

    CLng(inventory) > CLng(allocation)

    depending on the value of the number since CInt is limited to numbers between -32768 and 32767

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    I would also check that correct INT values exist before comparing, this will help to avoid casting errors

  • #5
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am having problems with using asp because I am using this

    Code:
    Set rsHotelblock = Server.CreateObject("ADODB.Recordset")
    to pull the value

    AND THIS

    Code:
    Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
    to update the same value. I can't seem to connect (Set rsHotelblock), run the validation without closing and then reopen connection when it errors.

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    We probably need to see your full code. But as a rule of thumb - don't use recordsets to do UPDATEs. Just build a SQL statement and get the connection to execute it.


  •  

    Posting Permissions

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