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

13 次查看(过去 30 天)
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?

采纳的回答

the cyclist
the cyclist 2019-11-1
"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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by