Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

2 vues (au cours des 30 derniers jours)
Sameer
Sameer le 4 Mar 2014
Clôturé : MATLAB Answer Bot le 20 Août 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);

Réponses (1)

dpb
dpb le 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...

Cette question est clôturée.

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by