Pushbutton callback not working

5 views (last 30 days)
Ali on 3 Oct 2022
Commented: Ali on 3 Oct 2022
I am working on a gui which is composed of 2 listbox and 2 pushbutton ok and cancel. The first part of my programe calculate the items that will go in the listboxes. The next part allow the user when he press on ok to get the number of the selected elements in each listbox and return it in an excel file. I put an exemple of what it is supposed to do (exemple is the gui and exemple 2 is the function that run it)
My exemples work great but the actual program when it comes to the part with the switch (all the above works fine) :
function res=kgexec4e(cn,OptPref)
%kgexec4e Création de la boite de dialogue "Choix Export" associée à
% Detailed explanation goes here
persistent res1 Varlist1 Varlist2%[] Initialement
%Appel du menu
h0 = kgui4e
%Calcul contenue listbox barre
Varlist1 = cn.Barres.Nom(1:end);
if OptPref.CacheBarr
Varlist1=Varlist1(~strncmp(Varlist1,'@',1)); %suppression des noms auto en fonction du menu Pref
%Calcul contenue listbox Element
Varlist2 = cn.Elements.Nom(1:end);
if OptPref.CacheElem
Varlist2=Varlist2(~strncmp(Varlist2,'@',1)); %suppression des noms auto en fonction du menu Pref
%%%Mise à jour contenu des listboxs
res = res1
switch get(h0,'Tag')
case 'OptOK'
nb = get(findobj(h0,'Tag','Barres'),'Value')
ne = get(findobj(h0,'Tag','ELement'),'Value')
it always gives me this error which i don't understand as the part of this programe that is slightly different from the exemple works but the similar part won't work.
here is the error message : (kguie is the gui which is the exact same as exemple gui)
Error in Caviar\private\kgui4e (line 5)
gris=[0.75 0.75 0.75];
Output argument "h0" (and maybe others) not assigned
during call to
Error in kgexec4e (line 8)
h0 = kgui4e
Error while evaluating uicontrol Callback
Ali on 3 Oct 2022
So there is some confussion you run the exemple2.m first which launch the gui once that is done the function will populate the twolistboxes and then when you click on ok it will go through the switch statement.
The file is always the same because i didnt yet work on it as i wanted first the program to work it does now thanks to benjamin kraus answer. As for the line numbers that's an error from my part the line at which it start are not the same one is A1 and the other is A2 that's why.

Sign in to comment.

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 3 Oct 2022
This looks like the same question/issue you were having in this other post. I've responded there.

More Answers (0)


Find more on Migrate GUIDE Apps 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!