Functions $

Some of the VBA string functions have two forms.
One that returns a String data type and one that returns a String-Variant data type.
The names of the functions that return a string include a dollar sign ($).
The following table lists all the functions that return a string data type.
The String returning functions are faster; however you will get an error if you call them with a value that is Null.
The functions that return a string-type variant can handle Null values without an error.

FunctionComments
CHR$Returns the character with the corresponding ANSI number (String).
CHRB$Returns the character with the corresponding ANSI number (String).
CHRW$Returns the character with the corresponding ANSI number (String).
COMMAND$Returns the argument portion of the command line used to launch the application (Variant).
DIR$Returns the name of a file or directory matching a pattern or attribute (String).
ENVIRON$Returns information about the current operating system environment (String).
ERROR$Returns the error message corresponding to a given error number (String).
FORMAT$Returns the text string of a number or date in a particular format (String).
HEX$Returns the number converted to hexadecimal (String).
INSTR$Returns the position of a substring within a larger string (Long).
LCASE$Returns the text string with all characters converted to lowercase (String).
LEFT$Returns a number of characters from the left of a string (String).
LEFTB$Returns a number of characters from the left of a string (String).
LTRIM$Returns the text string without leading spaces (String).
MID$Returns the text string which is a substring of a larger string (String).
MIDB$Returns the text string which is a substring of a larger string (String).
OCT$Returns the number converted to octal (Variant).
REPLACE$REPLACE(expression, find, replace [,start] [,count] [,compare])
RIGHT$Returns the number of characters from the right of a text string (String).
RIGHTB$Returns the number of characters from the right of a text string (String).
RTRIM$Returns the text string without trailing spaces (String).
SPACE$Returns the specified number of spaces (String).
STR$Returns the text string of a number (String).
STRCOMP$Returns the result of a string comparison (Integer).
STRING$Returns a repeating character of a given length (String).
TRIM$Returns the text string removing leading and trailing spaces (String).
UCASE$Returns the text string with all the characters converted to uppercase (String).

Exceptions

The Date function should always be used because the Date$ function doesn't behave correctly.
The Date$ always returns information in mm-dd-yyyy format regardless of the Windows localization settings, whereas the Date function uses the localization settings.



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext