简体   繁体   中英

What mean «String$» in VBA?

Got strange Access project, where found this line:

strUserName = String$(39, 0)

What String$ means?

What String$ means?

String$() means almost the same as String() , but String() can accept and return a Variant and String$() can not.

For example, String() will accept Null for the character argument and return Null ...

? String(5, Null)
Null

But substituting String$() for String() triggers error 94, "Invalid use of Null" ...

? String$(5, Null)

Regarding your example ... String$(39, 0) ... that returns a string of 39 null-byte characters ( Chr(0) ), which is not the same as Null.

It's an inbuilt function, normally used without the $ :

String(number, character)

It returns a string with <number> characters.

Eg String(5, "A") -> AAAAA

Apparently you can also use the Ascii code for character , so your example returns 39 * Chr(0).

string表示字符y的长度为x的字符串,因此string(5,33)=“ !!!!!”,即39 chr(0)的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM