I have a GUI that when launched will show two listbox and what i want at the end is that when i press the OK button on the gui it finds what where the last element selected on each of the two listbox for that i use this 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 nb ne%[] Initialement
%Appel du menu
H1 = kgui4e;
%Calcul contenue listbox barre
Varlist1 = cn.Barres.Nom(2: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(H1,'Tag','Barres'),'String',Varlist1)
set(findobj(H1,'Tag','ELement'),'String',Varlist2)
res = res1;
uiwait(H1)
switch action %l'objet ayant provoqué l'appel
case 'optOK'
uiresume(H1)
nb = get(findobj(H1,'Tag','Barres'),'Value');
ne = get(findobj(H1,'Tag','ELement'),'Value');
end
here is the function the gui is set in another file.m which is in the same folder. The nb and ne variables are the one that tells me the rank of the last selected items on each listbox but if i place them right before the res=res1 it will return 1 for both of them because when the gui opens the first element is selected on both listbox but if i move it after the uiresume so that i have time to change the items selected it will return empty and i don't understand why. I want to add that i use matlab 2012a so i can't use the getselecteditems function that is not available prior to matlab 2019 version
Thx for your help.