Convert Expression to String Method
The Convert Expression to String method converts an expression to a string. It returns one of the values described in the following table depending on the data type of the expression.
Data Type of Expression | Return Value |
---|---|
Date |
A string that contains a date. |
Empty |
A zero-length string (""). |
Error |
A string that contains the following information:
|
Null |
A run-time error. |
Other Numeric |
A string that contains the number. |
Format
CStr(expression)
For information about the arguments that you can use with this method, see Argument That You Can Use with Conversion Methods.
Example
The following example uses the Convert Expression to String method to operate on a string that the user enters as a number:
Sub Button_Click
Dim var1, msgtext as String, code as Integer
var1 = 77
msgtext = Cstr(var1)
msgtext = Left(var1,1)
code = Asc(msgtext)
msgtext = "The first digit you entered was," & msgtext
msgtext = msgtext & ". Its ANSI code is " & code & "."
End Sub