Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dear Ovatvvon,For you 2

Status
Not open for further replies.

RushiShroff

Programmer
Jan 23, 2002
216
IN
aT WHAT PLACES SHOLD WE BE CAREFUL ABOUT VARIABLES IN ASP ?

I mean that while coparing sometimes String can not be compared to Numeric or vice a versa.

So just bring light on variables in ASP. Rushi Shroff Rushi@emqube.com
"Life is beautiful."
 
I know this is directed toward ovatvvon, but I'd like to throw my 2 cents in too :)

Personally, whenever types are very important I always cast them before comparing them. This way, you know you get exactly what you need. From what I understand, variants (which VBScript variables are by default) get compared depending on the data within them.

While this is fine and dandy for most things, what if you want to compare a
0 vs. a "0"? This is where CStr comes in so handy (sidenote: I never use CInt, because it has a lower boundary than Int. I think it loses precision at some instances.)

Remember when datatypes are important, and when they can vary, don't compare against other types. Rather, use the VBScript functions given to you. Is something a number?
If (IsNumeric(myVar)) Then...
this tends to be alot nicer looking and cleaner than anything else you could come up with.

like I said, my 2 cents :) leo

------------
Leo Mendoza
lmendoza@garbersoft.net
 
On lunch right now, so have an opportunity to respond...

I think Leo summed it up pretty good. I usually try to declare variables anytime I think they may be used to compare in the future before I'm done developing a site...sometimes even if I'm not. One thing to remember is that the more the server has to figure out, the slower it'll run and return results to the client. So, if you declare the variables, that's one less thing the server has to do and speeds up the process...this combined with the fact that you don't have to worry about running into problems with comparisons in the future are two reasons I try to declare the variable type as much as possible.

Granted, the speed factor won't help too much unless you are thinking about performance all-around...i.e. using disconnected recordsets whenever possible, declaring variable types, using local variables instead of global ones, etc. All these combined will have an impact, but any one alone will usually not have a great impact. This is related to the famous statement: "Many hands make light work". The more there is contributing to an effort, the easier it becomes to obtain.

Hope between Leo's and my replies that you had your question answered. :)
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top