Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

2 visualizzazioni (ultimi 30 giorni)
Sameer
Sameer il 4 Mar 2014
Chiuso: MATLAB Answer Bot il 20 Ago 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);

Risposte (1)

dpb
dpb il 4 Mar 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...

Questa domanda è chiusa.

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by