Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Put simply, dynamic dialog control is all about the DialogFunc. A DialogFunc is a special type of function that is associated with the dialog GUI by entering a name in the field, like this:

Image RemovedImage Added

NOTE: To get to this dialog, you can do one of two things:

...

By setting the "Dialog Function" field to "DialogFunc", we are making the required link between the GUI and the event handlers. When you apply the changes from the dialog editor to the code, you will get a prompt:

Image RemovedImage Added

We recommend you always say "Yes". What happens when you say "Yes" is that a VB function is added at the end of your code, and it is populated in a very specific way. VERY IMPORTANT: A Dialog Function MUST take the form that is generated automatically as skeleton code. The individual cases in the Select Case block are predefined and can not be changed. We can, however, add event handlers within this framework and create many types of actions by our dialogs.

...

If you run this code, you will see the following dialog:

Image RemovedImage Added

All we have done so far is to place the controls, but we have not yet specified any behavior for the dialog. To do that, we will edit the DialogFunc to change how the dialog looks based on certain events.

...

Run the script and look at the text label for item 2. It should be disabled, as shown below:

Image RemovedImage Added

The DlgEnable statement was set to operate on the Text control whose Field parameter is "Text2", and the enable status is set to False, or not enabled.

...

When you run this modification, you will see that the text box that corresponds to the disabled label is now invisible (not just disabled):

Image RemovedImage Added

Text Labels

Finally, lets look at how we can change the string displayed by a text label. In the upper right corner of the dialog, up to now you have seen "MsgOut", which is the default label specified in the dialog definition (Text 280,14,210,14,"MsgOut",.msgOut). Again, there is a specific command to perform this task dynamically. Add the following line of code, again in the Case 1 code block:

...

Run the code and you will see that the message in the upper right now matches the default selection of "1":

Image RemovedImage Added

Wrapping Up Initialization

...

...and the dialog should appear like this:

Image RemovedImage Added

Case 2: Value Changing or Button Pressed

...

These code changes should produce the following 4 states (betond the initialization state, which we have already discussed) if your dialog is operating properly:


Image RemovedImage Added
Image RemovedImage Added
Image RemovedImage AddedImage Removed

Image Added

Case 3: TextBox or ComboBox Changing

...

When you run this, select either "1" or "2" for the drop-down control, then enter an alphanumeric string in TextBox1. If, after making these changes, you shift the focus away from TextBox1 (but don't click the OK button yet), you will get a VB message box telling you which TextBox has changed and the number of characters in the new string. Note that the number of characters is reported by SuppValue& in this case.

Image RemovedImage Added

Since a ComboBox also lets the user enter text, it works in exactly the same way. It triggers the event when it loses focus after a text change, and the number of characters in the new string is reported by SuppValue&.

...

When this code is executed and one of the above actions takes place, a MessageBox is displayed indicating which controls gained and lost focus. An example MessageBox is shown:

Image RemovedImage Added

Complete Code Listing

...