VBScript: Converting and Formatting with Functions - CSng, the Loneliest Function of them All!
(Page 4 of 5 )
Again, to convert an expression to a single, use this member of the lonely hearts club:
<html>
<head>
<script type="text/vbscript">
dim this, that, theOther
this=900.23
that=800.63
theOther=this*that+(this+that)
document.write(CSng(theOther))
</script>
</head>
<body>
</body>
</html>
Here we have the same result as before, except that the value is now a single:
722452
I Have a Secret...I CStr
The CStr() function is used to convert an expression to a string, whether that expression is a boolean, numeric, empty (but not null), or date. If it returns a date, keep in mind that it will be formatted as a short-date format:
<html>
<head>
<script type="text/vbscript">
dim value, when, huh
value=#12:10:59 AM#
when=#Jan 12, 1998#
huh=19
document.write(CStr(value)) & "<br />"
document.write(CStr(when)) & "<br />"
document.write(CStr(huh))
</script>
</head>
<body>
</body>
</html>
The result:
12:10:59 AM
1/12/1998
19
Next: Witchy Woman Put a Hex On You >>
More Windows Scripting Articles
More By James Payne