samporras Posted November 3, 2004 Posted November 3, 2004 Hey guys. I was creating a validation on one of the sites I was working on using VB Script and for some reason I could not get it to work. My question does not pertain to VB script alone... If (len(trim(Request.Form("input_variable"))) < "7" or len(trim(Request.Form("input_variable"))) > "10") then error message... blah.. blah.. End IF I inputed a variable that had a length of 9 positions. The first part of the condition was not being met (as it should), but for some reason the second condition was being met. We all know that 9 is not greater than 10 but for some reason the error message that i created kept on being triggered. It wasn't until i removed the quotes from the 7 and 10 that the validation was working correctly. Is this because the code was interpreting number 10 in quotes as a string? Does "10" have a different value than 10 in binary? If this is true, ? The code is working, but i'm truely stumped by this... Thanks. -Sam Any suggestions Quote
Deverill Posted November 3, 2004 Posted November 3, 2004 It's checking to see if the string "9" > "10" which the character "9" is greater than the character "1". Remember, as strings the computer looks character by character. Quote
samporras Posted November 3, 2004 Author Posted November 3, 2004 So does it just disregards the "0" in "10"? it just compares the first character in one string to the first character in another string? Thanks for the response by the way. Quote
Deverill Posted November 4, 2004 Posted November 4, 2004 "9-nothing" is after "1-0" alphabetically. It doesn't ignore it but it looks at it like saying "BBC" is after "American Broadcasting Service" - remember, the computer does not understand that these are numbers. Quote
samporras Posted November 4, 2004 Author Posted November 4, 2004 Thanks for clearing that up Jim. I didn't understand the logic behind it...but now I do. Great to keep in the back of my mind as i continue to learn to code. -Sam Quote
Deverill Posted November 4, 2004 Posted November 4, 2004 You are very welcome - that's what family's for! Best wishes on the code-learning. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.