Create a form similar to vbYesNo

BryanKipp
BryanKipp used Ask the Experts™
on
I read that you can't change the default vbYesNo message box, but I need a similar box to come up on a button click that has "Enable" and "Disable" as the text for the buttons with the ability to confirm enable similar to the functionality of the vbYesNo message box.

I'm also rookie enough that it would be very helpful to know where this form needs to reside in my code to be able to be called via the button click.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Hi BryanKipp,

From your description, it's apparent that you're using Visual Basic...but what VERSION?

Author

Commented:
This is Visual Basic 6.3 and is an embedded part of a software package I use at work called DeltaV. I can see in the Project tree where there are several folders called "Forms". Just not sure where I would put this new form to be able to call it in "Click" sub routine
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Hmmm...never used DeltaV so I have no idea how to integrate forms in there.  =\

There's no built-in "Project --> Add Form" kind of menu option?  (wishful thinking probably)
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Author

Commented:
If I open the Visual Basic Editor, it does open to the current project. On the top menus, I do have options under "Insert" for "Procedure", UserForm", "Module", "Class Module" or "File".

If I select "Insert/UserForm", it does create that form in the project.

Just not sure how to set it up and use it. My current setup is, with a command button on my operator interface graphic, on Click, I utilize an If, Then, Else statement and call a MsgBox that asks i("f the operator wants to ENABLE", vbYesNo, Confirm ENABLE) ....then If vbYes, I write a value out to several data points. The issue is, that in one scenario, I need to ask if they want to Enable or Disable. So, I need a box I can bring up that functions just like the vbYesNo in the MsgBox but allows me to lable the buttons and have my confirmation be based on which button they press.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Gotcha...OK.

*Take with a grain of salt as I've never used DeltaV and differences may occur...

So you create the new form and add two buttons to it.

Let's assume the form is called frmEnableBox and the two buttons are cmdEnable and cmdDisable.

Add a boolean flag to the form and toggle it accordingly based on the button clicked:

    ' ... within "frmEnableBox" ...
   
    Public EnableSelection As Boolean

    Public Sub cmdEnable_Click()
        Me.EnableSelection = True
        Me.Hide
    End Sub

    Public Sub cmdDisable_Click()
        Me.EnableSelection = False
        Me.Hide
    End Sub

Now, in the calling form, you would create an instance of "frmEnableBox" and show it modally like this:

    ' ... in the "calling" form ...
    Dim frmEB As New frmEnableBox
    frmEnableBox.Show vbModal ' <-- code STOPS here until "frmEB" is hidden/closed

When the "dialog" is hidden by the buttons, execution will return and you can find out which selection was made:


    ' ... in the "calling" form ...
    Dim frmEB As New frmEnableBox
    frmEnableBox.Show vbModal ' <-- code STOPS here until "frmEB" is hidden/closed
    If frmEB.EnableSelection Then
        ' ... "Enable" was selected ...
    Else
        ' ... "Disable" was selected ...
    End If

Hope that helps...

Author

Commented:
I believe tis will do what I'm looking for. One more minor question......does this allow the addition of a text box that I can use similar to the MsgBox?

Example: MsgBox ("Do you want to ENABLE the heaters?", vbYesNo, Confirm ENABLE)
IF vbYes THEN
'Take action based on a "yes" confirmation"
End IF

In this instance, I write my value based on the confirmation. It would be very helful to be able to massage the text to whatever part of the process we might be trying to Enable or Disable.
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Sure...note that in my code I failed to use the instance of frmEnableBox that I created!  =(

This:

    Dim frmEB As New frmEnableBox
    frmEnableBox.Show vbModal ' <-- code STOPS here until "frmEB" is hidden/closed

Should be:

    Dim frmEB As New frmEnableBox
    frmEB.Show vbModal ' <-- code STOPS here until "frmEB" is hidden/closed

If you added a Label (Label1) to frmEnableBox then you can set it before displaying the dialog:

    Dim frmEB As New frmEnableBox
    frmEB.Label1.Caption = "Do you want to ENABLE the heaters?"
    frmEB.Show vbModal ' <-- code STOPS here until "frmEB" is hidden/closed

Author

Commented:
Excellent....works perfectly!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial