|< Day Day Up >|
The things that an object knows how to do are called the object's methods. Invoking a method uses syntax very similar to setting a property. You separate the method name from the object name with a dot. Here's an example of invoking a method:
Sub InvokeMethod() ' Invoke a method of an object Dim frm As New Form_Projects frm.Visible = True frm.Move 0, 0, 1440, 1440 MsgBox "Click OK to continue" End Sub
This code calls the Move method of the Form class. Methods can have arguments, which follow the method name and are separated by commas; in this case, there are four arguments to the Move method, in this order:
Figure 8.3 shows the result of running the InvokeMethod procedure. As you can see, the form is scrunched up to the top-left side of the workspace, and has its width equal to its height.
Figure 8.3. Form after invoking the Move method.
In VBA, distances and sizes are measured in twips. There are 1440 twips in one inch.
Many methods have optional arguments. In fact, the last three arguments of the Move method are all optional. If you don't supply a value for one of these arguments, the corresponding property of the form doesn't change. You can skip over optional arguments by just putting nothing between the commas. For example, if you want to supply values for just the left and width arguments, you can use this line of code:
frm.Move 0, , 1440
As you can see, you don't have to even supply the commas if you're leaving out an optional argument at the end of the list. You can also refer to arguments by name, in which case you can supply them in any order:
frm.Move Width:=1440, Top:=0
The := characters separate an argument's name and its value.
|< Day Day Up >|