Navigation

Operators and Keywords

Function List:

C++ API

: btn = questdlg (msg)
: btn = questdlg (msg, title)
: btn = questdlg (msg, title, default)
: btn = questdlg (msg, title, btn1, btn2, default)
: btn = questdlg (msg, title, btn1, btn2, btn3, default)

Display msg using a question dialog box and return the caption of the activated button.

The message may have multiple lines separated by newline characters ("\n"), or it may be a cellstr array with one element for each line.

The optional title (character string) can be used to specify the dialog caption. It defaults to "Question Dialog".

The dialog may contain two or three buttons which will all close the dialog.

The string default identifies the default button, which is activated by pressing the ENTER key. It must match one of the strings given in btn1, btn2, or btn3.

If only msg and title are specified, three buttons with the default captions "Yes", "No", and "Cancel" are used.

If only two button captions, btn1 and btn2, are specified the dialog will have only these two buttons.

Examples:

btn = questdlg ("Close Octave?", "Some fancy title", "Yes", "No", "No");
if (strcmp (btn, "Yes"))
  exit ();
endif

See also: errordlg, helpdlg, inputdlg, listdlg, msgbox, warndlg.

Demonstration 1

The following code

 disp ('- test questdlg with two buttons');
 a = questdlg ('Would you like some free money?',...
               '$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $',...
               'No', 'Cancel', 'Cancel');
 if (strcmp (a, 'No'))
   msgbox ('Suit yourself.', 'Message Box');
 endif

Produces the following output

- test questdlg with two buttons

Demonstration 2

The following code

 disp ('- test questdlg with message and title only.');
 a = 'No';
 c = 0;
 while (strcmp (a, 'No') || ! c)
   a = questdlg ('Close this Question Dialog?', 'Reductio Ad Absurdum');
   if (strcmp (a, 'Yes'))
     q = 'Are you sure?';
     while (strcmp (a, 'Yes') && ! c)
       a = questdlg (q, 'Reductio Ad Absurdum');
       word = ' really';
       i = strfind (q, word);
       if (isempty (i))
         i = strfind (q, ' sure');
         q = [q '!'];
       else
         word = [word ','];
       endif
       q = [q(1:i-1) word q(i:end)];
     endwhile
   endif
   if (strcmp (a, 'Cancel'))
     warndlg ('Answer "Yes" or "No".', 'Warning Dialog');
     a = 'No';
     c = 1;
   endif
 endwhile
 msgbox ('Whew!');

Produces the following output

- test questdlg with message and title only.

Demonstration 3

The following code

 disp ('- test questdlg with five inputs');
 ans = questdlg ('Are you ready Steve?', 'Brian', 'No', 'Uh huh', 'Uh huh');
 if (! strcmp (ans, 'No'))
   ans = questdlg ('Andy?', 'Brian', 'No', 'Yeah', 'Yeah');
   if (! strcmp (ans, 'No'))
     ans = questdlg ('Mick?', 'Brian', 'No', 'Okay', 'Okay');
     if (! strcmp (ans, 'No'))
       ans = msgbox ("Well all right, fellas.    \n\n     Let''s GO!!!!!",...
                     'Ballroom Blitz', 'none');
     endif
   endif
 endif

Produces the following output

- test questdlg with five inputs

Package: octave