本帖最后由 adders 于 2011-12-30 00:07 编辑
Select 发表于 2011-12-29 23:30
谢谢 adders !
不知道中文版的帮助是否相同...我用的英文版,这是F1文件,以及示例.功能说明是:在文本中返回字符数,或在变量中返回储存变量要求的字节数.
例子中说明了String和Variant的处理是一样的,Integer返回2,Currency返回8,示例中用户自定义的CustomerRecord由于包括了Integer (2), Name (10), Address (30),所以len的返回值是2+10+30 = 42
Len Function
Returns a Long containing the number of characters in a string or the number of bytes required to store a variable. Syntax
Len(string | varname) The Len function syntax has these parts: Part | Description | string | Any valid string expression. If string contains Null, Null is returned. | Varname | Any valid variable name. If varname contains Null, Null is returned. If varname is a Variant, Len treats it the same as a String and always returns the number of characters it contains. |
Remarks
One (and only one) of the two possible arguments must be specified. With user-defined types, Len returns the size as it will be written to the file. Note Len may not be able to determine the actual number of storage bytes required when used with variable-length strings in user-defined data types.
Len Function Example The first example uses Len to return the number of characters in a string or the number of bytes required to store a variable. The Type...End Type block defining CustomerRecord must be preceded by the keyword Private if it appears in a class module. In a standard module, a Type statement can be Public.
Type CustomerRecord ' Define user-defined type.
ID As Integer
Name As String * 10
Address As String * 30
End Type
Dim Customer As CustomerRecord
Dim MyInt As Integer, MyCur As Currency
Dim MyString, MyLen
MyString = "Hello World"
MyLen = Len(MyInt) ' Returns 2.
MyLen = Len(Customer) ' Returns 42.
MyLen = Len(MyString) ' Returns 11.
MyLen = Len(MyCur) ' Returns 8.
|