eWebProgrammer
Distributednetworks GofPatterns
prev prev
  Course navigation
   
ASP constants and variables
What is Data Conversion?
All variables defined in ASP are of the Variant data type. The Variant can further be classed into subtypes depending on the type of data it contains. A variable with a string assigned to it has a string subtype, while a variable with a whole number assigned to it has an integer subtype.
To change the subtype of a variable, you need to convert it. This allows you to gain more control over how ASP treats the variable. For example, suppose you have a variable holding the value of pi, and you want to convert its subtype to integer.
Here is how you might do it:
<%
  Dim varPi
  varPi = "3.142"      'subbtype automatically assigned as a string
  varPi = CInt(varPi)  'subtype converted to an integer
  Response.write varPi 'returns 3
%>
The variable varPi will return the number 3.
Because the data type was converted to an integer, the decimal was dropped. If the variable is then converted to a double, the number will change to 3.0.
Here is a list of the most commonly used data conversion functions.
Function Description
Cbool Returns the variable that has been converted into a variant with the subtype Boolean.
Cbyte Returns the variable that has been converted into a variant with the subtype Byte.
Ccur Returns the variable that has been converted into a variant with the subtype Currency.
Cdate Returns the variable that has been converted into a variant with the subtype Date.
CDbl Returns the variable that has been converted into a variant with the subtype Double.
Cint Returns the variable that has been converted into a variant with the subtype Integer.
CLng Returns the variable that has been converted into a variant with the subtype Long.
CSng Returns the variable that has been converted into a variant with the subtype Single.
CStr Returns the variable that has been converted into a variant with the subtype String.
DateSerial Returns the variable that has been converted into a variant with the subtype Date for given year, month, day.
DateValue Returns a value representing a variant of subtype Date.
Hex Returns a string containing the hexadecimal value of a number.
Oct Returns a string containing the octal value of a number.
Fix Returns the integer portion of a number.
Int Also returns the integer portion of a number.
  Course navigation