OS. To dimension the variables and add initial values in the dialog
You must dimension all the values you will use in the program. Further, it's a good idea to populate the dialog with initial values for the user.
- Select the automatically generated line of code Dialog dlg (i.e., line 23) and delete the line contents.
-
With your cursor after the line of code
Dim dlg as UserDialog, type the following to
dimension the variables in use:
Dim dlgResult As Integer Dim crdx As Double Dim crdy As Double Dim crdz As Double Dim n1 As Long Dim n2 As Long Dim i1 As Long Dim s1 As Long
-
Type a single quote mark followed by
Initialization.
The single quote mark is used to denote a comment. It
is best practice to add clear comments to document your source code.
'Initialization
-
Type the following values to populate the dialog input fields:
dlg.clmn = "3" dlg.row = "5" dlg.ht = "3" dlg.wdth = "5"
-
Type the following commands to open the dialog upon starting the
macro.
You'll also add a comment and a debugging command
which is helpful for resolving any issues with your macro.
'Popup the dialog dlgResult = Dialog(dlg) Debug.Clear
-
Type the following command to capture the result of the user
action in the dialog:
If dlgResult = -1 Then 'OK button pressed Debug.Print "OK button pressed" ElseIf dlgResult = 0 Then 'Cancel button pressed Debug.Print "Cancel button pressed" End If
Note: The single quote mark after the world Then also indicates a comment. Comments like this can follow the programming instruction on the same line.The EndIf statement is automatically added by the editor to close the If statement if you press <Enter>.
You have now
created the general set of instructions to the program what to do with the user
action in the form.