Example of conversion function for ASP

Source: Internet
Author: User
Tags date chr contains expression integer numeric numeric value variable
Functions | example | Conversion ASP Conversion Function Example

Variant variables typically automatically convert the data subtypes that they represent to the appropriate data type, but sometimes an automatic conversion can cause some data type mismatch errors. At this point, you can use the conversion function to cast the subtype of the data.

function function
The ASC function returns the ANSI character code corresponding to the first letter of the string.
The CHR function returns the character corresponding to the specified ANSI character code
The Hex function returns a string that represents a hexadecimal numeric value.
The OCT function returns a string representing the numeric octal value.
The CSTR function returns an expression that has been converted to a string subtype.

The CDate function returns an expression that has been converted to a date subtype.
The CInt function returns an expression that has been converted to an integer subtype.
CLng function returns an expression that has been converted to a long integer subtype
The CSng function returns an expression that has been converted to a single subtype
The CDBL function returns an expression that has been converted to a Double subtype
The CBool function returns an expression that has been converted to a Bourg type


1. Asc Function Example

In the following example, ASC returns the ANSI character code for the first letter of each string:

Dim MyNumber
MyNumber = ASC ("A") ' returns 65.
MyNumber = ASC ("a") ' returns 97.
MyNumber = ASC ("Apple") ' returns 65.


2, Chr Function Example


The following example uses the CHR function to return the character corresponding to the specified character code:

Dim MyChar
MyChar = CHR (65) ' returns A.
MyChar = CHR (97) ' Returns a.
MyChar = CHR (62) ' Back to >.
MyChar = Chr (37) ' returns%.
3, Hex Function Example
The following example uses the Hex function to return the hexadecimal number of a number:

Dim Myhex
Myhex = Hex (5) ' returns 5.
Myhex = Hex (10) ' Returns a.
Myhex = Hex (459) ' returns 1CB.


4. Oct Function Example

The following example uses the OCT function to return the number of octal for a value:
Dim myoct
Myoct = Oct (4) ' returns 4.
MYOCT = Oct (8) ' returns 10.
Myoct = Oct (459) ' returns 713.
5, the CSTR function example

<%num1=666strwelcome= "Welcome to &cstr" (NUM1) & "visitors"%>

CStr casts a variable num1 from an integer subtype to a string subtype

6, CDate Function Example

MyDate = "October 19, 1962" ' defines the date.
Myshortdate = CDate (mydate) ' Converts to date data type.
MyTime = "4:35:47 PM" defines time.
Myshorttime = CDate (mytime) ' Converts to date data type.

7, CInt Function Example

Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is Double.
MyInt = CInt (mydouble) ' MyInt contains 2346.

8, CLng Function Example

Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45:myval2 = 25427.55 ' MyVal1, MyVal2 is a double value.
MyLong1 = CLng (MyVal1) ' MyLong1 25427.
MyLong2 = CLng (MyVal2) ' MyLong2 contains 25428.

9, CBool Function Example

Dim A, B, Check
A = 5:B = 5 ' initialization variable.
Check = CBool (A = B) ' checkbox set to True.
A = 0 ' defines A variable.
Check = CBool (A) ' checkbox set to False.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.