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

15 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

the cyclist
the cyclist el 1 de Nov. de 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

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by