When using listdlg, what is the value assigned when the user exits without making a selection?

15 Ansichten (letzte 30 Tage)
I'm using listdlg to give the user a dropdown list to make a selection of. While debugging, I tried exiting the listdlg without making a selection, and I got an error.
I tried to validate the data underneath by using a while loop. Normally when a user exits a menu without making a selection, the variable is assigned to 0. My error is occurring almost 90 lines later, so as long as the data is validated, there shouldn't be any errors.
choice = listdlg("PromptString",{"Select a plant to learn more about."},"SelectionMode","single","ListString",CP);
while choice == 0 % forces user to make selection
choice = listdlg("PromptString",{"Select a plant to learn more about."},"SelectionMode","single","ListString",CP);
end
Since my while loop is just bypassed if the user exits without making a selection, that means the variable choice is not 0. If it's not assigned to 0 when the user exits without making a selection, what is the value assigned?

Akzeptierte Antwort

the cyclist
the cyclist am 1 Nov. 2019
"If the user clicks Cancel, presses Esc, or clicks the close button in the dialog box title bar, then the indx value is returned as an empty array."
So, I think you need
while isempty(choice)
instead of
while choice == 0

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by