From: Squall Mania on
Hello,

I've built a GUI using GUIDE and it includes a popup menu and a pushbutton. There are 2 choices to select from the popup menu. If the user selected the second choice (i.e. if handles.popupmenu==2;) a certain code must be implemented and then I used Guidata(hObject, handles) to store the data necessary for other functions. I also predefined the value of the popup menu to be 1 (i.e. set(handles.popupmenu,'value',1) after pressing the pushbutton. Here is the problem, when the user runs the program and then selects the first choice and presses the pushbutton, everything works great, but then when the user selects the second choice and presses again the pushbutton (in this case the value of the popup menu should return to 1), the value does NOT return to 1 as it gives me an error saying:

Error using ==> set
Invalid handle object.

To simply resolve this, I deleted "guidata(hObject, handles)" and it works like a charm. BUT, this guidata is important for other functions to work and it should be there.

Is there a way that I can delete the stored value of the popupmenu just after I press the pushbutton?

Your solution is highly appreciated.

Thanks.
From: Nicolas on
Hello. I understand you want to run function A when you press pushbutton and popupmenu value is 1; and run function B when you press pushbutton and popupmenu value is 2, also setting popupmenu value again to 1. In both cases, you want to store some value in the handles structure.

If I'm right, your programm in the pushbutton should looks like the following:

value = get(handles.popupmenu1,'Value');
if value == 1
display('Function 1');
handles.data = 1;
guidata(hObject, handles);
elseif value == 2
display('Function 2');
handles.data = 2;
guidata(hObject, handles);
end
set(handles.popupmenu1,'Value',1)

Best,

Nicolas

"Squall Mania" <r_skeik(a)hotmail.com> wrote in message <hiil4g$33u$1(a)fred.mathworks.com>...
> Hello,
>
> I've built a GUI using GUIDE and it includes a popup menu and a pushbutton. There are 2 choices to select from the popup menu. If the user selected the second choice (i.e. if handles.popupmenu==2;) a certain code must be implemented and then I used Guidata(hObject, handles) to store the data necessary for other functions. I also predefined the value of the popup menu to be 1 (i.e. set(handles.popupmenu,'value',1) after pressing the pushbutton. Here is the problem, when the user runs the program and then selects the first choice and presses the pushbutton, everything works great, but then when the user selects the second choice and presses again the pushbutton (in this case the value of the popup menu should return to 1), the value does NOT return to 1 as it gives me an error saying:
>
> Error using ==> set
> Invalid handle object.
>
> To simply resolve this, I deleted "guidata(hObject, handles)" and it works like a charm. BUT, this guidata is important for other functions to work and it should be there.
>
> Is there a way that I can delete the stored value of the popupmenu just after I press the pushbutton?
>
> Your solution is highly appreciated.
>
> Thanks.