MsgBox Default Button

Yes, I know I can use MsgDialog but this case fits as a simple “yes/No” question


Have a MsgBox(“Are you sure you do not want to encrypt the Database?”), 52)
Yes and No buttons with a Caution Icon - works except “Yes” is default and I want it to be “No”
Changed the Code to 308 (52+256) to make the 2nd button the Default.
The order of the buttons in the MsgBox is No then Yes.
The Docs say that the 2nd is the order from the group 1 list and “No” is listed 2nd. But it doesn’t work when choosing 1st since that is 52
When 308 is used - no button is the default

[code]dim iResult As Integer

if me.Value = False then
iResult = MsgBox(“Are you sure you do not want to secure the Database?”, 308)
if iResult = 7 then me.Value = True
end if


How do I make “No” the default or am I going to have to use MsgDialog?

I just tried this in 2016r4.1 under macOS Sierra and the ORDER does not change “it is NO YES” regardless of the parameters
although I would have expected ONE of the buttons to be highlighted, and in none of the cases is this true

Don’t need to change the ORDER they are displayed, I just want to make the “No” button the default or highlighted button. “Yes” is shown 2nd but it is highlighted when I use 52.

Well you are doing better than me… under no circumstances can I get it to DEFAULT anything… Group 3 has no affect for me

even this doesn’t default anything… and it should

Public Function Yes_or_No() as integer
  Dim d as New MessageDialog                  //declare the MessageDialog object
  Dim b as MessageDialogButton                //for handling the result
  d.icon=MessageDialog.GraphicCaution         //display warning icon
  d.CancelButton.Visible=True                 //show the Cancel button
  d.Message="Are you sure you do not want to encrypt the Database?"
  d.ActionButton.Default=true // Yes is Default 
  // d.CancelButton.default=true
  b=d.ShowModal                              //display the dialog
  Select Case b                              //determine which button was pressed.
  Case d.ActionButton
    return  6 // Yes Pressed
  Case d.CancelButton
      return 7 // No Pressed
  End select
End Function

If I use 52 instead of 308 in my statement above I get the Yes button defaulted…

Disclaimer: This is Mac UX. I’m not certain if Windows has a similar rule. I am also totally ignoring the fact that Xojo isn’t behaving as the documentation states it should.

No should never be the default for a dialog.

You are asking to confirm, but not to slow the user down. On these Yes / No dialogs, Enter/Return will be Yes, and Esc will be No. This should not ever be changed. Doing so with a MessageDialog is disrespectful to the overall user experience of the operating system.

I might recommend a small tweak to make your UX fit right in. In your original question, it says “Are you sure you do not want to secure the Database?” If you would like your default action to be securing the database, consider rewording the question so that “Yes” becomes the default, more secure answer. Perhaps:

dim iResult as Integer = MsgBox("Database Insecure" + EndOfLine + EndOfLine + "The database is not secured, would you like to secure it now?", 52)

With this message you’ve changed the default action to be more secure and are maintaining the system level Enter=Yes Esc=No flow of the buttons.

good thought Tim, I will do that.