Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

2 Ansichten (letzte 30 Tage)
Sameer
Sameer am 4 Mär. 2014
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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);

Antworten (1)

dpb
dpb am 4 Mär. 2014
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...

Diese Frage ist geschlossen.

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by