Microsoft Office Tutorials and References
In Depth Information
Emulating the MsgBox Function
h Determines how tall to make the dialog box
h Displays the UserForm
Figure 15-12: The UserForm for the MyMsgBox function.
Three additional event-handler procedures are included (one for each CommandButton). These
routines determine which button was clicked and return a value for the function by setting a
value for the UserClick variable.
Interpreting the second argument ( buttons ) is a bit challenging. This argument can consist of a
number of constants added together. For example, the second argument can be something like
this:
VbYesNoCancel + VbQuestion + VbDefaultButton3
This argument creates a three-button MsgBox (with Yes, No, and Cancel buttons), displays the
question mark icon, and makes the third button the default button. The actual argument is 547 (3
+ 32 + 512).
The challenge was pulling three pieces of information from a single number. The solution involves
converting the argument to a binary number and then examining specific bits. For example, 547
in binary is 1000100011. Binary digits 4 through 6 determine the image displayed; digits 8
through 10 determine which buttons to display; and digits 1 and 2 determine which button is the
default button.
Using the MyMsgBox function
To use this function in your own project, export the MyMsgBoxMod module and the
MyMsgBoxForm UserForm. Then import these two files into your project. You can then use
the MyMsgBox function in your code just as you’d use the MsgBox function.
 
Search JabSto ::




Custom Search