0

Got strange Access project, where found this line:

strUserName = String$(39, 0)

What String$ means?

HansUp
  • 95,961
  • 11
  • 77
  • 135
Arman Hayots
  • 2,459
  • 6
  • 29
  • 53
  • I guess "String" refers to a value type and "$" is a reference to target a particular information (ie. in the cell 39,0). So it could mean... get the value at cell 39,0 and interpret it as a String to initialize the username. String usually refers to a "character-based" type which is convenient to store words, sentence, ... – floppy12 Jan 29 '16 at 16:21
  • string means a string of length x of character y, so string (5,33)="!!!!!", thats 39 chr(0)'s – Nathan_Sav Jan 29 '16 at 16:27
  • Possible duplicate of [what is the meaning of the dollar sign after a method name in vb.net](http://stackoverflow.com/questions/8341524/what-is-the-meaning-of-the-dollar-sign-after-a-method-name-in-vb-net) – Chrismas007 Jan 29 '16 at 16:28
  • 1
    @Chrismas007: depends on whether the question was mainly about the `$` or about the (rarely used) `String()` function. – Andre Jan 29 '16 at 16:30
  • 1
    I don't agree that this **VBA** question should be closed as a duplicate of a **VB.Net** question. – HansUp Jan 29 '16 at 16:51
  • Simply looking in the VBA Help / Language Reference would have turned up this information. On StackOverflow you are expected to do some basic research... – Cindy Meister Jan 29 '16 at 17:01

3 Answers3

6

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.

HansUp
  • 95,961
  • 11
  • 77
  • 135
2

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).

Andre
  • 26,751
  • 7
  • 36
  • 80
0

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

Nathan_Sav
  • 8,466
  • 2
  • 13
  • 20