When a user clicks on the red close button in an application in macOS, I have this in the Close event… When I run it and try to close the window the application quits as expected when I hit YES. I’m not sure of what to do when hitting NO. I don’t want the window to close but it does so when I run the application.
Dim n As Integer
n = MsgBox(“Do you wish to quit Application?”, 4)
If n = 6 Then
// User clicked Yes
// Testing: MsgBox(“User clicked Yes”)
Quit
ElseIf n = 7 Then
// User clicked No
// Testing: MsgBox(“User clicked No”)
I would also urge you to move to the more usable and code-clear MessageDialog instead of the old MsgBox. You have much more control over what is displayed, how it’s displayed, and how you handle the users’ choices.
// Show the Cancel button
d.CancelButton.Visible = True
// Display the message dialog
d.Message = “Do you wish to quit Application?”
b = d.ShowModal
// Determine which button was pressed.
Select Case b
Case d.ActionButton
// User pressed Yes
Return False
Case d.CancelButton
// User pressed No
Return True
End Select
Also, you can now use situation specific icons that use enum mnemonic values like MessageBox.GraphicCaution instead of needing to do math and come up with a number.
@Dave S
OK. Done. Do I add the Quit to the following?
// Determine which button was pressed.
Select Case b
Case d.ActionButton
// User pressed Yes
Return False
Quit
Case d.CancelButton
// User pressed No
Return True
End Select