Info

此问题已关闭。 请重新打开它进行编辑或回答。

What is the problem in the code? I am using R2011a

2 次查看(过去 30 天)
Undefined function or variable 'myname'.
Error in ==> SAM_1>pushbutton1_Callback at 82 if (length(myname) ~= NULL) && (length(mypass) ~= NULL)
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> SAM_1 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)SAM_1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
MY CODE IS :
function pushbutton1_Callback(hObject, eventdata, handles) handles = guidata(hObject); if (length(myname) ~= NULL) && (length(mypass) ~= NULL) open('hr.jpg'); end guidata(hObject,handles);
function uname_Callback(hObject, eventdata, handles) handles = guidata(hObject); handles.myname = get(hObject,'String'); guidata(hObject,handles);
function tpass_Callback(hObject, eventdata, handles) handles = guidata(hObject); handles.mypass = get(hObject,'String'); guidata(hObject,handles);

回答(1 个)

dpb
dpb 2014-3-4
Please format your code so I don't have to... :(
function pushbutton1_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
if (length(myname) ~= NULL) && (length(mypass) ~= NULL)
open('hr.jpg');
end
guidata(hObject,handles);
function uname_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.myname = get(hObject,'String');
guidata(hObject,handles);
function tpass_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
handles.mypass = get(hObject,'String');
guidata(hObject,handles);
I don't do GUIs so I don't "know nuthink" about the callbacks and the objects but you refer to a variable myname in the pushbutton1_Callback function whereas the uname_Callback function stuffs it into the handles object as a named field.
Whether the right object is getting passed or not is at a deeper level thatn I know; only that you'll have to refer to it as handles.myname to retrieve it...

此问题已关闭。

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by