Arman Hayots
Arman Hayots

Reputation: 2508

What mean «String$» in VBA?

Got strange Access project, where found this line:

strUserName = String$(39, 0)

What String$ means?

Upvotes: 0

Views: 3037

Answers (3)

HansUp
HansUp

Reputation: 97101

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.

Upvotes: 6

Nathan_Sav
Nathan_Sav

Reputation: 8531

string means a string of length x of character y, so string (5,33)="!!!!!", thats 39 chr(0)'s

Upvotes: 0

Andre
Andre

Reputation: 27634

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

String(number, character)

It returns a string with <number> characters.

E.g. String(5, "A") -> AAAAA

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

Upvotes: 2

Related Questions