pushbutton callback doesn't work
Show older comments
i have a gui that i want to do a specific task when i press on the pushbutton ok which is to give me the number of the selected items in the two listbox that are in the gui for that i use this specific code :
function res=kgexec4e(action,cm,cp,cn,OptPref,OptAff)
%kgexec4e Création de la boite de dialogue "Choix Export" associée à
%kgexec4
% Detailed explanation goes here
persistent res1 Varlist1 Varlist2 %[] Initialement
%Open GUI
H1 = kgui4e;
%Calculate the barre listbox content
Varlist1 = cn.Barres.Nom(2:end);
%Calculate the element listbox content
Varlist2 = cn.Elements.Nom(1:end);
%%%the listbox takes the value of one array each
set(findobj(H1,'Tag','Barres'),'String',Varlist1)
set(findobj(H1,'Tag','Element'),'String',Varlist2)
res = res1
switch action
case 'OptionsOK' %When the pusbutton ok is pressed
nb = get(findobj(H1,'Tag','Barres'),'Value'); %find the selected item in the listbox barres
ne = get(findobj(H1,'Tag','ELement'),'Value');%find the selected item in the listbox element
close(gcbf)
end
end
The gui is set in another .m file called kgui4e.m and i set the pushbutton this way
uicontrol(h0,'Style','pushbutton',...
'Callback','kgexec4e',...
'Position',[250 30 65 35],...
'String','OK',...
'Tag','OptionsOK');
and my problem is when i remove the switch and case i will get the item that are selected when the gui opens and not after i press ok and when i use this code i will get this error message :
Error in Caviar\private\kgui4e (line 6)
blanc=[1 1 1];
Output argument "h0" (and maybe others) not assigned during
call to "C:\Users\223080038\Documents\m\CAVIAR3.1.2
_m_original\R2012a\Caviar\private\kgui4e.m>kgui4e".
Error in kgexec4e (line 8)
H1 = kgui4e;
Error while evaluating uicontrol Callback
which i don't understand if anyone could lighten me on the probleme it would be a great help.
PS : I work on matlab 2012a
2 Comments
Geoff Hayes
on 26 Sep 2022
@Ali - it isn't clear to me how the code is supposed to work. For example, you have this callback (for the OK button) as
function res=kgexec4e(action,cm,cp,cn,OptPref,OptAff)
%kgexec4e Création de la boite de dialogue "Choix Export" associée à
%kgexec4
% Detailed explanation goes here
persistent res1 Varlist1 Varlist2 %[] Initialement
%Open GUI
H1 = kgui4e;
%Calculate the barre listbox content
Varlist1 = cn.Barres.Nom(2:end);
which has the comment "Open GUI" which suggests that it is trying to launch the GUI. But then you mention that this callback kgexec43 is assigned to the push button in the kgui4e GUI:
uicontrol(h0,'Style','pushbutton',...
'Callback','kgexec4e',...
'Position',[250 30 65 35],...
'String','OK',...
'Tag','OptionsOK');
Is this intentional? Or is it a source of the problem?
Note that the error message is indicating that h0 does not exist (and the error is presumably coming from the above line of code). Is that the case? Can you post the full error message and perhaps your code for the GUI?
Ali
on 27 Sep 2022
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!