Comparing

When you are comparing 2 strings you are actually comparing the ANSI value of each character to the value of the corresponding character in the other string.
To match the special characters, left bracket ([), question mark (?), number sign {#) and asterisk (*), enclose them in brackets.
The right bracket (]) cannot be used within a group to match itself, but it can be used outside a group as an individual character.
A quick way to return the character in a particular position in a string is to use the MID(sText,iCharNo,1)
However this can be changed by using the Option Compare statement.
To perform a string comparison within a procedure and override the string comparison setting for the module, you can use the StrComp function.


When assigning a zero-length string or doing comparisons you should use the vbNullString constant. Using the empty string "" will allocate a variable length string and use more resources.


Is the String Empty ?

To check if a string variable contains any data you could compare it to a zero-length string or compare it to the built-in constant vbNullString.

Dim sEmptyString As String 
sEmptyString = ""

The best way is to use the Len() function and check if it is zero.

If Len(sEmptyString) = 0 Then 
End If

You can use a hyphen to separate the lower and upper bounds, eg [A-Z]. There are no delimiters.


Comparison Operators

Character strings (like numbers) can be compared with the following numerical operators (=, <, >) and combinations of these.
Strings can be easily compared using any of the following operators.
When you use these operators the results depend on the string comparison setting for the module.
String comparisons are done by comparing each character in the string.
If one string matches all the characters on the left side of the other string the shorter string is always less than the longer string

<less than
<=less than or equal to
=equal to
<>not equal to
>=greater than or equal to
>greater than
LIKEThe LIKE operator can also be used

Using Comparison Operators

A < B < a < b
"3 A" < "3 C" < "3- B"

"russell" < "russellproctor" 

VBA.vbStrConv

vbUppercase1Converts a string to all uppercase characters
vbLowercase2Converts a string to all owercase characters
vbPropercase3Converts the first letter of every word in a string to uppercase

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