Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted

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.

Posted

"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.

Posted

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

Posted

You are very welcome - that's what family's for!

 

Best wishes on the code-learning.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...