Type conversion in VBScript

We can check the variable type by using TypeName. To change from one type to other we can use different functions.

Expression to Integer by Cint
Dim v1
v1=5.43    	
Response.Write "Type of " & TypeName(v1)
Response.Write "<br>"
Response.Write CInt(v1)  ' Output will be 5
On this page — Show page sectionsHide page sections
If the last line is changed by using Cdbl then output will be like this
Response.Write CDbl(v1) ' Output will be 5.43

CDate

CDate() converts an expression to a Date value. String-to-date conversion depends on the server locale, so avoid ambiguous numeric date strings when possible.

Dim eventDate
eventDate = CDate("September 22, 2026")
Response.Write eventDate

When you already have numeric year, month, and day components, DateSerial() is usually clearer.

Validate a numeric string before converting

Dim raw
raw = "42"
If IsNumeric(raw) Then
    Response.Write CInt(raw) + 1
Else
    Response.Write "Please enter a number"
End If

Output:

43

This avoids calling CInt() on arbitrary text. Real form submissions also need error handling and range checks.

Locale-sensitive conversions

CDate() can depend on regional date settings, and CInt() rounds rather than truncating. Check IsNumeric() or IsDate() and handle conversion errors before processing user input.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer