I am using App Designer to write a GUI wrapper for an existing app. The app should load some data based on the user input. If the user input is invalid, how can I make the user try again? For example, the user entered an end time that is not after the previously entered starting time. Or as a simpler example, the user entered a string that is not one of the valid responses.

 採用された回答

Adam Danz
Adam Danz 2023 年 4 月 19 日

0 投票

Put your dialog in a while-loop that exits when the input conditions are met and regenerates the dialog if the conditions are not met.
Here is an example using input() which generates a prompt in the command window rather than generating a dialog but it would follow the same general process (dialogs are much better than input()).

4 件のコメント

Rich006
Rich006 2023 年 4 月 19 日
That helps, but what if I'm using the App Designer? Is there a way to place the entire app in a while-loop as you suggest? Also, I would think the App Designer might have exception handling built in. I guess not?
Adam Danz
Adam Danz 2023 年 4 月 19 日
編集済み: Adam Danz 2023 年 4 月 19 日
If the dialog is evoked after a user presses an app button, for example, then the while-loop will be within the button's callback function and will continue to prompt the users to enter a new value.
I'm having a hard time imagining a situation in which the entire app should be within a while loop like this. Users must interact with an app comonent such as a button, list box, edit box, dial, etc. Those componentes have callback functions. That's where the input validation and while-loop will be.
Rich006
Rich006 2023 年 4 月 20 日
The whole purpose of the app is to get input from the user (start date, start time, end date, and end time plus three other values), and then call a function with those values as arguments. Maybe I don't even want a full-on App, but just a few input dialogs wrapped in a script with validation. I was thinking I wanted one dialog for all seven inputs, with validation happening within the dialog, but that's probably not the best approach. This should be as simple as possible, but no simpler. :-)
Adam Danz
Adam Danz 2023 年 4 月 20 日
I see. That makes sense. You could create a dialog or an app, inputdlg might come in handy.
Let's say you're using inputdlg. Create it within a while-loop that creates the dialog, validates the users's input, and either leaves the loop or continues for another iteration.
It will look something like this.
inputsGood = false;
while ~inputsGood
response = inputdlg(___);
inputsGood = myValidation();
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

質問済み:

2023 年 4 月 19 日

コメント済み:

2023 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by