VBScript type conversion function

Source: Internet
Author: User
CBool function
Describe
Returns an expression that has been converted to a Variant (variable) of a Boolean (Boolean type/subtype) subtype.
Grammar
CBool (expression)
expression is any valid expression.
Description
Returns False if expression is zero, otherwise returns TRUE. If expression cannot be interpreted as a numeric value, a run-time error occurs.
The following example uses the CBool function to convert a expression (expression) to a Boolean. If expression is not zero, CBool returns TRUE, otherwise, returns FALSE.
Dim A, B, Check
A = 5:B = 5 ' initialization variable
Check = CBool (A = B) ' Check has a value of True
A = 0 ' define Variable
Check = CBool (A) ' checkbox set to False
CByte function
Describe
Returns an expression that has been converted to a Variant of the byte-type subtype.
Grammar
CByte (expression)
The expression parameter is any valid expression.
Description
In general, you can use a subtype conversion function to write code to show that the results of some operations should be represented as a specific data type, not the default type. For example, when currency, single-precision, double, or integer operations occur, use CByte to force byte operations.
The CByte function is used for internationally recognized format conversions from other data types to Byte subtypes. For example, the recognition of decimal separators, such as thousands, may depend on the locale of the system.
An error occurs if the expression is outside the acceptable range of Byte subtypes. The following example uses the CByte function to convert expression to byte:
Dim MyDouble, MyByte
MyDouble = 125.5678 ' MyDouble is a double value
MyByte = CByte (mydouble) ' MyByte contains 126
CCur function
Describe
Returns an expression that has been converted to a Variant of the Currency subtype.
Grammar
CCur (expression)
The expression parameter is any valid expression.
Description
Typically, you can use subtype data conversion functions to write code to show that the results of certain operations should be expressed as a specific data type, not as a default data type. For example, in the case of an integer operation, the CCur function is used to force a currency calculation.
The CCur function is used for internationally recognized format conversions from other data types to Currency subtypes. For example, the recognition of the decimal separator and the thousand separator depends on the locale of the system.
The following example uses the CCur function to convert expression to Currency:
Dim MyDouble, Mycurr
MyDouble = 543.214588 ' mydouble is double precision

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.