i want to evaluate this textbox for validation. but i got this error.

2 ビュー (過去 30 日間)
ARYA NAYAK
ARYA NAYAK 2016 年 12 月 24 日
コメント済み: ARYA NAYAK 2016 年 12 月 25 日
Error
Undefined variable "handles" or class "handles.t1".
Error in DESIGN>b1_Callback (line 292)
x=get(handles.t1,'string');
Error while evaluating UIControl Callback
For this code
f=figure;
t1= uicontrol(f,'Style','edit','String','','Position',[180 580 130 20]);
b1 = uicontrol(f,'Style','pushbutton','String','GENERATE','Position',[100 365 100 40],'Callback',@b1_Callback);
function b1_Callback(source,eventdata)
x=get(handles.t1,'string');
if(isempty(x))
msgbox('enter the text');
else
msgbox('ds');
end
Please solve this error
  2 件のコメント
Stephen23
Stephen23 2016 年 12 月 24 日
編集済み: Stephen23 2016 年 12 月 24 日
Where in your code is the variable handles defined?
ARYA NAYAK
ARYA NAYAK 2016 年 12 月 24 日
i don't know.
i'm learning matlab one week ago. i don't know anything.
will you please make that code proper to execute.
in script i want to make one textbox and one push button.
then i wrote push button call back. then i got that error.
please help me to solve that particular error

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 12 月 24 日
handles is not automatically passed by MATLAB. When you create a callback using GUIDE then GUIDE arranges for the callback to be passed but when you create your own callback then you have to pass it yourself if you want it. (You also have to create the handles structure yourself)
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 12 月 24 日
handles.f=figure;
handles.t1= uicontrol(f,'Style','edit','String','','Position',[180 580 130 20]);
handles.b1 = uicontrol(f,'Style','pushbutton','String','GENERATE','Position',[100 365 100 40],);
set(handles.b1, 'Callback', {@b1_Callback, handles});
function b1_Callback(source, eventdata, handles)
x=get(handles.t1,'string');
if(isempty(x))
msgbox('enter the text');
else
msgbox('ds');
end
ARYA NAYAK
ARYA NAYAK 2016 年 12 月 25 日
Thank you so much sir. it works

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by