View Full Version : form validation Greater than not a number

10-10-2007, 07:20 AM
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)

dim InputError,Reason

If Len(inventory) > Len(allocation) Then
Reason = "<strong>ERROR:</strong> inventory can not be greater than allocation!!"
end if
if InputError = 0 then


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?

10-10-2007, 12:46 PM
The variables inventory and allocation are the values you're getting from your form?

They're numbers?

If so, stop using Len(). Len() (http://www.devguru.com/technologies/vbscript/13947.asp)returns the number of characters in a string. What you want to do is:

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

10-11-2007, 05:46 PM
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

10-11-2007, 05:49 PM
I would also check that correct INT values exist before comparing, this will help to avoid casting errors

10-11-2007, 09:58 PM
I am having problems with using asp because I am using this

Set rsHotelblock = Server.CreateObject("ADODB.Recordset")

to pull the value


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.

10-12-2007, 11:06 AM
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.