String, String$ Function

See AlsoI02XZ0              Example4OOPBV>Low

Returns a string whose characters all have a given ANSI5221FB code or are all the first character of a string expression1330R89.

Syntax 1

String[$](number, charcode)

Syntax 2

String[$](number, string)

Remarks

String returns a Variant8PHEAW3; String$ returns a String.

Use String[$] to create a string that consists of one character repeated over and over.

The String[$] function has these parts:

Part               Description

 

number          Numeric expression71RISN indicating the length of the returned string.  It must be between 0 and approximately 65,535.

charcode       ANSI code of the character to use to build the return string.  It is a numeric expression that evaluates to an Integer between 0 and 255, inclusive.

string             String expression whose first character is used to build the return string.

 

If the second argument (charcode or string) in either syntax is a Variant, the underlying data type3GYXY7 determines how String[$] uses that argument.  If the argument is a Variant of VarType7A68ZTZ 8 (String), String[$] uses the first character to create the return string.  If the argument is a Variant of VarType 2-7 (any numeric type), String[$] uses the numeric value as the ANSI code for the character used to create the return String.  A Variant of VarType 1 (Null1DDW7C0) produces an error.  To convert numeric values greater than 255 to an ANSI code between 0 and 255, String [$] uses the remainder after the value is divided by 256 (argument Mod 256).


See Also

ANSI Character Set108ABF

Space, Space$ Function3TBE7D

Str, Str$ FunctionLANSTR


String, String$ Function Example

The example uses the String function to return a Variant consisting of 10 asterisks.  The ANSI code of the asterisk character is 42.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Msg, NL                           ' Declare variables.

   NL = Chr(10)                          ' Define newline.

   Msg = "This demo generates two strings of 10 asterisks.  Both "

   Msg = Msg & "forms of String[$] syntax are illustrated.  " & NL

   Msg = Msg & NL & "Here is the 1st: " & String(10, "*") & NL

   Msg = Msg & "Here is the 2nd: " & String(10, 42)

   MsgBox Msg                            ' Display message.

End Sub