String, String$ Function
See Also Example
Returns a string whose characters all have a given ANSI code or are all the first character of a string expression .
String returns a Variant; 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:
number Numeric expression 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 type If the argument is a Variant of VarType 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 (Null ) 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). determines how String[$] uses that argument.
ANSI Character Set
Space, Space$ Function
Str, Str$ Function
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.