Cstr() - String Conversion Function - TestingQ.com

-->Exclusive Portal for Testing Jobs

Cstr() - String Conversion Function

CStr() - Convert to String Value
Converts an expression into a string value.

String = CStr(Expression)
Returns  String

If expression is:
  • Boolean - then the CStr function will return a string containing true or false.
  • Date - then the CStr function will return a string that contains a date in the short-date format.
  • Null - then a run-time error will occur.
  • Empty - then the CStr function will return an empty string ("").
  • Error - then the CStr function will return a string that contains the word "Error" followed by an error number.
  • Other numeric - then the CStr function will return a string that contains the number.
Example1
    a = 10
    msgbox typename(a)      'Output --> Integer

    b = Cstr(a)
    msgbox typename(b)      'Output --> String
    msgbox b                        'Output --> 10   

Example2
    a = "#10/10/2009"
    msgbox typename(a)      'Output --> Date

    b = Cstr(a)
    msgbox typename(b)      'Output --> String
    msgbox b                        'Output --> 10 /10/2009 

Example3
    a = True
    msgbox typename(a)      'Output --> Boolean

    b = Cstr(a)
    msgbox typename(b)      'Output --> String
    msgbox b                        'Output --> True

No comments:

Post a Comment