Link to home
Start Free TrialLog in
Avatar of BryanKipp
BryanKipp

asked on

Create a form similar to vbYesNo

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!
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Hi BryanKipp,

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

ASKER

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
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)
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.
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...
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.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent....works perfectly!