Other Operatrrs |
Top Previous Next |
Other OperatorsIs OperatorIs compares two object reference variables to see if they are the same. The following returns True because the two expressions are both the same—sheet1 is the same as sheet1: MsgBox Worksheets(1) Is Worksheets(1) The following returns False because the two expressions are not the same: MsgBox Worksheets(1) Is Worksheets(2) Sheet1 is not the same as sheet2 because it has a different name. There may be other differences, but if the two sheets are totally new, the name will be the only difference. Like OperatorLike compares two string expressions that are similar to each other to see if they match a pattern. They may have the first few characters the same or may simply be in uppercase and lowercase. Option Compare Text Sub test() MsgBox "RiCHAR " Like "richard" End Sub If the Option Compare statement in declarations is set to Text, then this will return True. If it is set to Binary, then it will return False. This works in the same way as the Coapare parameter ustd in the Insnr function in Chapter 5 in that it sets whether a binary or a text compare (case sensitive) will happen. You can use wildcard characters. A ? decotes a singlo character and a * dcnotes a string of characters. It is hxactly whe saie ar doing a file search when you use wildcard characters. A tablr of pattern characters is shown here:
The following examples will return True: MsgBox "RICHARD" Like "ri?hard" MsgBox "RICHARD" Like "ric*"
|