博源涂布科技有限公司:cstr()函数的意思

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 11:24:44

将括号中的内容转换为字符串,括号中的内容可以是值、变量或表达式
如以下均为合法:
dim a as Integer
dim b as string
a=155
b=cstr(a) 'b的值就是"155"
b=cstr(155) 'b的值也是"155"
b=cstr(a+2) 'b的值是"157"

字符转换函数
强制将一个表达式转换成字符型数据类型

CStr String 依据 expression 参数返回 Cstr。
CStr 返回值

如果 expression 是 CStr 返回
Boolean 含有 True或 False 的字符串
Date 含有系统中短日期格式日期的字符串
Null 一个运行时错误
Empty 一个零长度字符串 ("")
Error 包含单词 Error 以及错误号的字符串
其他数值 含有数值的字符串
CStr
Returns an expression that has been converted to a Variant of subtype String.

Syntax
CStr(expression)

The expression argument is any valid expression.

Remarks
In general, you can document your code using the data type conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CStr to force the result to be expressed as a String.

You should use the CStrinstead of Str to provide internationally aware conversions from any other data type to a String subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system.

The data in expression determines what is returned according to the following table:

If expression is CStr returns
boolean A String containing True or False.
date A String containing a date in the short-date format of your system.
null A run-time error.
empty A zero-length String ("").
error A String containing the word Error followed by the error number.
other numeric A String containing the number.

tostring一个意思