Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

classic asp cint

Tags:

asp-classic

I'm new to classic asp, all my experience is in c# .net and ColdFusion and php.

Anyway, this site I'm working on has this code all over the place

If (CInt("0" & myVar) > 0) Then
    myNewCar = CInt("0" & myVar)
End If

What I don't understand is why the "0" is append to the var in the cint() input? Am I just missing something? Is it some kind of safety thing? Is it efficient?

On a side note, any classic asp books recommended?

like image 387
pinniger Avatar asked Sep 04 '09 14:09

pinniger


2 Answers

Its an old hack to handle null values. Calling CInt on a null would result in an error. However concatenating a string with a null results in the string hence "0" & null returns "0". This prevents CInt from erroring when the value is null.

like image 101
AnthonyWJones Avatar answered Nov 18 '22 00:11

AnthonyWJones


myVar might be nothing, an object, empty string, or non-numeric. Pre-pending "0" guarantees you'll get some valid integer back out no matter what.

like image 25
Joel Coehoorn Avatar answered Nov 17 '22 23:11

Joel Coehoorn