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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Casting "" as an integer

Status
Not open for further replies.

kirk2364

Programmer
May 3, 2001
10
CA
What exactly happens when I caste a null character as an integer (i.e. CInt("")). When assigning the result to a variable, is the variable just populated with 0, or with a null character or what?
 
It won't work.
You should get an error something along the lines of "invalid parameter to cInt function" Mise Le Meas,

Mighty :)
 
Actually, this is what you get:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'cInt'
Mise Le Meas,

Mighty :)
 
So I need to explicitly set the variable to 0?

Code:
if varName = "" then
   varName = 0
end if

There's no easier way to do this?
 
If you are going to have several calls to cInt then you could just write your own cInt function. Something along the lines of:

function myCInt(value)
if value = "" then myCInt = 0
else myCInt = cInt(value)
end function

Then in the main body of your code all you need is:

varname = myCInt(value) Mise Le Meas,

Mighty :)
 
Forgot the end if:

function myCInt(value)
if value = "" then myCInt = 0
else myCInt = cInt(value)
end if
end function

Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top