<< Click to Display Table of Contents >>
Set Command |
VBScript implements the concept of object-oriented programming languages, allowing a variable of type Variant to assume the form of any object by using the Set command. This way, that variable works as a pointer to an object, which allows accessing its methods and properties, according to the next example.
Set rectangle = Screen.Item("Rectangle1")
rectangle.BackgroudColor = RGB(255, 0, 0)
'Without a Set command, the same call
'must be written like this
Screen.Item("Rectangle1").BackgroundColor = RGB(255, 0, 0)
Apparently, there is no advantage in this case, because users can execute the same task in a single line of code. However, if later in the same script other operations are needed, this process becomes easy and quick if that call to the Item method is not repeated on all lines.
'A bad example
Screen.Item("Rectangle1").BackgroundColor= RGB(212, 208, 20)
Screen.Item("Rectangle1").Height = 500
Screen.Item("Rectangle1").Width = 500
'A better example
Set Rectangle = Screen.Item("Rectangle1")
Rectangle.BackgroundColor = RGB(212, 208, 20)
Rectangle.Height = 500
Rectangle.Width = 500