Click to See Complete Forum and Search --> : isOdd or isEven vbScript functions
lcscne
03-29-2004, 11:06 AM
isOdd(number)
isEven(number)
I'm looking for a vbScript function that takes a numeric argument and returns a boolean. Is there such a thing?
buntine
03-29-2004, 11:25 AM
No, i dont think there is an isOdd() or isEven() function built-in to VBScript.
Though, you could write your own functions without too much trouble.
dim intOdd, intEven
intOdd = 11
intEven = 30
if intOdd mod 2 = 0 then
Response.write "intOdd is even."
else
Response.write "intOdd id odd."
end if
if intEven mod 2 = 0 then
Response.write "intEven is even."
else
Response.write "intEven is odd."
end if
The preceding example should work as expected. You could easily use this methodology to write your own custom isOdd() and isEven() functions.
The mod operater stands for 'modulus' -- it devides expression1 with expression2 and return the remainder.
Regards,
Andrew Buntine.
lcscne
03-29-2004, 11:33 AM
cool
I found on MS web a varType function too.
So I did:
if varType(intOdd/2) = 2 then
response.write "even"
else
response.write "odd"
end if
varType returns 2 if argument is an integer
be careful with this to use the '/' and not the '\\' for division as one is floating point division and the other is integer division.
thanks buntine.
buntine
03-29-2004, 11:37 AM
Ahh ok, good job, thats a handy bit of code.
Good luck with it ;)
lcscne
03-29-2004, 12:03 PM
Yaa, there is one slight difference between my code and yours.
Yours works and mine doesn't. The logic seems right but I don't have time to debug it so I'm going with yours.
thanks again buntine.
by the way did you ever find any docs on using the form and querystring collections simultaniously? I've been looking and can't find any mention of your arguement. Its been on the back of my mind and I'd like to get resolution.
buntine
03-29-2004, 12:31 PM
No.. Its not something i read, its just the way me and the guys that i have worked write our code.
I just dont see the point of it. The reason i explicitely tell people to aviod it is because i once had a problem in a script i was writing, it turned out to be the fact that i was using both the form-handling collections.
Regards.
lcscne
03-29-2004, 01:48 PM
was it just when using a querystring in the action property of the form or as a general rule?
Also what are your thoughts/experiences concerning the use of other request object collections simultaniously with the form/querystring collection (ie Cookies, ServerVariables), have you had any trouble using these collections simultaneously with the form or querystring collections?
I know I was rather crude in the original thread and I've determined that I won't be so now, I want to learn what known issues are out there in order to formulate my own sensible best practices. Also apploligize for my previous crudeness.
One more question: Concerning the time you had trouble, is it possible that it was some other issue maybe a misconfigured server or something, were you able to duplicate this trouble on another box?
buntine
03-29-2004, 09:28 PM
Hey, thats ok. I wasnt offended or anything. I get in arguments everyday on this forum. ;)
No, i have never had any problems with using other object collections simultaneously. The reason we suggest against using form and queryString is because they essentially do the same thing in a different manner. You also lose a tad of readability when using both form-handling collections.
Technically, it may have been something else which was causing the error. Though, i am highly doubtful.
Regards,
Andrew Buntine.