Other Operators


Is Operator

Is 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 Operator

Like 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 "RICHARD" 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 Compare parameter used in the Instr 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 ? denotes a single character and a * denotes a string of characters. It is exactly the same as doing a file search when you use wildcard characters. A table of pattern characters is shown here:

Character

Meaning

?

Any single character

*

Zero or more characters

#

Any single digit (0 ‚ 9)

[ charlist ]

Any single character in charlist

[ !charlist ]

Any single character not in charlist

The following examples will return True:

 MsgBox "RICHARD" Like "ri?hard" 

MsgBox "RICHARD" Like "ric*"



Excel VBA Macro Programming
Excel VBA Macro Programming
ISBN: 0072231440
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net