Does VBS have a to string method?
If it does not, how would I go about converting ints, doubles, longs, etc to a string? Thanks.
Re: Does VBS have a to string method?
Yes, VBScript has conversion methods for variable types.
- CBool() - Convert to Boolean Type
- CByte() - Convert to Byte Value
- CCur() - Convert to Currency Type
- CDate() - Convert to Date Value
- CDbl() - Convert to a Double Value
- CInt() - Convert to Integer Value
- CLng() - Convert to Long Integer Value
- CSng() - Convert to a Single Value
- CStr() - Convert to String Value
Re: Does VBS have a to string method?
Ok thanks.
What would happen if I used CDbl or CInt on a string without any numbers in it?
Re: Does VBS have a to string method?
Re: Does VBS have a to string method?
Quote:
Originally Posted by
dizou
Ok thanks.
What would happen if I used CDbl or CInt on a string without any numbers in it?
IMHO, you could test whether or not a number is present first, before converting it. - Call me old fashioned, but to me, it just makes a bit more sense.
Re: Does VBS have a to string method?
Quote:
Originally Posted by
PeejAvery
It should return 0.
Shouldn't it be type mismatch? To be honest I don't do VBS but they should be similar to VB6.0 and the following code raises an error.
Code:
Private Sub Command1_Click()
MsgBox CInt("x")
End Sub
Re: Does VBS have a to string method?
Quote:
Originally Posted by
dee-u
Shouldn't it be type mismatch?
Yes, it does. I was confusing it with an old basic language.
Re: Does VBS have a to string method?
Quote:
Originally Posted by
PeejAvery
Yes, it does. I was confusing it with an old basic language.
Thanks for the clarification, in my part and for the OP's sake also. :wave: