Msg Box emulation MyMsg Box code

The MyMsgBox function makes use of a UserForm named MyMsgBoxForm. The function itself, which follows, is very short. The bulk of the work is done in the

UserForm_Initialize procedure.

The complete code for the MyMsgBox function is too lengthy to list here, but it's available in a workbook on the companion CD-ROM.

Public Promptl As String Public Buttonsl As Integer Public Titlel As String Public UserClick As Integer

Function MyMsgBox(ByVal Prompt As String, _ Optional ByVal Buttons As Integer, _ Optional ByVal Title As String) As Integer Promptl = Prompt Buttonsl = Buttons Titlel = Title MyMsgBoxForm.Show MyMsgBox = UserClick End Function

Figure 15-6 shows MyMsgBox in action. (I used a different font for the message text.)

Figure 15-6: The result of the MsgBox emulation function (using a different font).

Figure 15-6: The result of the MsgBox emulation function (using a different font).

Here's the code that I used to execute the function:

Prompt = "You are about to wipe out your hard drive." Prompt = Prompt & vbCrLf & vbCrLf & "OK to continue?" Buttons = vbQuestion + vbYesNo

Title = "We have a problem"

Ans = MyMsgBox(Prompt, Buttons, Title)

0 0

Post a comment