Pushbutton callback not working

8 views (last 30 days)
Ali
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 à
%kgexec4
% 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
end
%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
end
%%%Mise à jour contenu des listboxs
set(findobj(h0,'Tag','Barres'),'String',Varlist1)
set(findobj(h0,'Tag','ELement'),'String',Varlist2)
res = res1
switch get(h0,'Tag')
case 'OptOK'
nb = get(findobj(h0,'Tag','Barres'),'Value')
ne = get(findobj(h0,'Tag','ELement'),'Value')
end
end
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
"C:\Users\223080038\Documents\m\CAVIAR3.1.2
_m_original\R2012a\Caviar\private\kgui4e.m>kgui4e".
Error in kgexec4e (line 8)
h0 = kgui4e
Error while evaluating uicontrol Callback
  4 Comments
Cris LaPierre
Cris LaPierre on 3 Oct 2022
Edited: Cris LaPierre on 3 Oct 2022
I think there is some confusion caused by how you have chosen to name your files. My understanding is that example.m is the main file, and the one to run to launch the gui. Clicking the OK button runs the callback function, which is example2.m. This will populate the two listboxes in the gui with numbers. Is that correct?
That is the workflow I followed and did not get any errors. I selected the current folder when the popup appeared. When I select a number from either listbox, an xlsx file is added to the folder I'd selected in the popup and the app closes (file attached). The file appears to always be the same, no matter what number or listbox I select.
I am noticing line numbers in the files you have shared do not align with line numbers in the error message you pasted.
Ali
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)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2012a

Community Treasure Hunt

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

Start Hunting!