Prompting Error for user input
古いコメントを表示
Suppose I have a input box that requires an entry greater than zero before attempting to load a file.
function test_Callback(hObject, eventdata, handles)
test = str2double(get(hObject, 'String'));
if isnan(test)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
handles.backup.test= test;
guidata(hObject,handles)
function loaddata_Callback(hObject, eventdata, handles)
test_Callback(hObject, eventdata, handles)
[filename, pathname, Index] = ...
uigetfile({'*.txt';},['Select the File to load'],...
'\\MyDocuments\User');
This prompts the error "'Input must be a number','Error'' and allows the user to open and search for this file. What am I doing wrong?
6 件のコメント
per isakson
2013 年 2 月 16 日
You ask for too much guessing. Please describe in some detail
- how your code behaves and
- how you want it to behave
per isakson
2013 年 2 月 16 日
Current behavior in a possible use case (I have not tested):
- user clicks [loaddata]
- gui finds e.g. a character in [test]
- gui presents [errordlg] (,which is modal(1)) and continues
- gui presents [uigetfile]
- user clicks ok in [errordlg]
- user picks a file in [uigetfile]
- gui quits the [loaddata] callback without saving "filename"
Is this the way your code works?
(1) doc says: Note A modal dialog box prevents the user from interacting with other windows before responding. To block MATLAB program execution as well, use the uiwait function.
per isakson
2013 年 2 月 17 日
編集済み: per isakson
2013 年 2 月 17 日
- I cannot see how you want to provide a possibility to the user to correct the mistake (e.g. "a" in [test]).
- What is the problem "after isnan"
- What is the user supposed to do after clicking OK in [errordlg]?
- "basically how the code should work", however, we rather need detailed and exactly
Edited version of your comment:
user clicks [loaddata]
if gui finds e.g. a character in [test]
gui presents [errordlg]
elseif gui finds 0
gui presents [errordlg]
end
gui presents [uigetfile]
user picks a file in [uigetfile]
So basically how the code should work is described. But the problem is that when I add the elseif statement to test_callback after isnan.
per isakson
2013 年 2 月 19 日
編集済み: per isakson
2013 年 2 月 19 日
I insist that it is a good thing to first specify how the code should work. And it is easier to read code that is properly formatted; use [Smart Intent] in the editor. See code in my answer.
per isakson
2013 年 2 月 19 日
編集済み: per isakson
2013 年 2 月 20 日
Yes, but what does the code that I added to my answer do?
per isakson
2013 年 2 月 20 日
Change
for ii = 1 : 10
to
while true
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!