Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem on pop up menu

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 27 Apr, 2011 20:53:04

Message: 1 of 9

hi all
I have a problem on pop up menu
file.txt
2 5
3 4

function popup1_Callback(hObject, eventdata, handles)
switch get(handles.popup1,'Value')
    case 1
        Type ='method1'
    case 2
        Type ='method2'
    end

function pustbutton1_Callback(hObject, eventdata, handles)
A=uigetfile({'*.txt';})
switch Type
     case {'method1'}
          B=A+[2 6;3 2];
     case {'method2'}
         B=A
end

Error in ==> main>pushbutton1_Callback at 113
    switch Type
Error in ==> gui_mainfcn at 96
        feval(varargin{:});
Error in ==> main at 42
    gui_mainfcn(gui_State, varargin{:});

Error in ==>
@(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))

Subject: problem on pop up menu

From: Nasser M. Abbasi

Date: 27 Apr, 2011 21:34:57

Message: 2 of 9

On 4/27/2011 1:53 PM, wahyoe Unggul wrote:
> hi all
> I have a problem on pop up menu
> file.txt
> 2 5
> 3 4
>
> function popup1_Callback(hObject, eventdata, handles)
> switch get(handles.popup1,'Value')
> case 1
> Type ='method1'
> case 2
> Type ='method2'
> end
>
> function pustbutton1_Callback(hObject, eventdata, handles)
> A=uigetfile({'*.txt';})
> switch Type
> case {'method1'}
> B=A+[2 6;3 2];
> case {'method2'}
> B=A
> end
>
> Error in ==> main>pushbutton1_Callback at 113
> switch Type
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
> Error in ==> main at 42
> gui_mainfcn(gui_State, varargin{:});
>
> Error in ==>
> @(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))

I have a question for you:

In the function pustbutton1_Callback(), when you say

"switch Type"

Where do you think the variable "Type" lives?

--Nasser

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 28 Apr, 2011 04:01:05

Message: 3 of 9

"Nasser M. Abbasi" <nma@12000.org> wrote in message <ipa264$248$1@speranza.aioe.org>...
> On 4/27/2011 1:53 PM, wahyoe Unggul wrote:
> > hi all
> > I have a problem on pop up menu
> > file.txt
> > 2 5
> > 3 4
> >
> > function popup1_Callback(hObject, eventdata, handles)
> > switch get(handles.popup1,'Value')
> > case 1
> > Type ='method1'
> > case 2
> > Type ='method2'
> > end
> >
> > function pustbutton1_Callback(hObject, eventdata, handles)
> > A=uigetfile({'*.txt';})
> > switch Type
> > case {'method1'}
> > B=A+[2 6;3 2];
> > case {'method2'}
> > B=A
> > end
> >
> > Error in ==> main>pushbutton1_Callback at 113
> > switch Type
> > Error in ==> gui_mainfcn at 96
> > feval(varargin{:});
> > Error in ==> main at 42
> > gui_mainfcn(gui_State, varargin{:});
> >
> > Error in ==>
> > @(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))
>
> I have a question for you:
>
> In the function pustbutton1_Callback(), when you say
>
> "switch Type"
>
> Where do you think the variable "Type" lives?
>
> --Nasser
hai nasser
variable "type" is in the popup1_Callback(hObject, eventdata, handles)
switch get(handles.popup1,'Value')
case 1
          Type ='method1'
case 2
         Type ='method2'
end

i can run pussbutton1, but I write code on.
pussbutton1_Callback (hObject,...)
switch get(handles.popup1,'Value')
case 1
          Type ='method1'
case 2
         Type ='method2'
end
A=uigetfile({'*.txt';})
 switch Type
   case {'method1'}
           B=A+[2 6;3 2];
   case {'method2'}
          B=A
end
the problem is the amount of "push button callbacks" that I use and there are many variables "Type" is also used in some other functions,do I have to write code popup1 at every function?
can the code in the "popup1_Callback"is read by all functions without having to write code "popup1_Callback"on every function?

Subject: problem on pop up menu

From: Nasser M. Abbasi

Date: 28 Apr, 2011 04:08:20

Message: 4 of 9

On 4/27/2011 9:01 PM, wahyoe Unggul wrote:
> "Nasser M. Abbasi"<nma@12000.org> wrote in message<ipa264$248$1@speranza.aioe.org>...
>> On 4/27/2011 1:53 PM, wahyoe Unggul wrote:
>>> hi all
>>> I have a problem on pop up menu
>>> file.txt
>>> 2 5
>>> 3 4
>>>
>>> function popup1_Callback(hObject, eventdata, handles)
>>> switch get(handles.popup1,'Value')
>>> case 1
>>> Type ='method1'
>>> case 2
>>> Type ='method2'
>>> end
>>>
>>> function pustbutton1_Callback(hObject, eventdata, handles)
>>> A=uigetfile({'*.txt';})
>>> switch Type
>>> case {'method1'}
>>> B=A+[2 6;3 2];
>>> case {'method2'}
>>> B=A
>>> end
>>>
>>> Error in ==> main>pushbutton1_Callback at 113
>>> switch Type
>>> Error in ==> gui_mainfcn at 96
>>> feval(varargin{:});
>>> Error in ==> main at 42
>>> gui_mainfcn(gui_State, varargin{:});
>>>
>>> Error in ==>
>>> @(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))
>>
>> I have a question for you:
>>
>> In the function pustbutton1_Callback(), when you say
>>
>> "switch Type"
>>
>> Where do you think the variable "Type" lives?
>>
>> --Nasser


> hai nasser
> variable "type" is in the popup1_Callback(hObject, eventdata, handles)
> switch get(handles.popup1,'Value')

Humm...ok, but you are trying to reference that variable 'Type'
in another callback, right? from pustbutton1_Callback()

You think it is ok to do so? Do you think by the time you are
in that other callback, that the variable 'Type' is still
available for you to access? Even though they are 2 different
functions?

--Nasser

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 28 Apr, 2011 04:29:05

Message: 5 of 9

"Nasser M. Abbasi" <nma@12000.org> wrote in message <ipap7p$heo$1@speranza.aioe.org>...
> On 4/27/2011 9:01 PM, wahyoe Unggul wrote:
> > "Nasser M. Abbasi"<nma@12000.org> wrote in message<ipa264$248$1@speranza.aioe.org>...
> >> On 4/27/2011 1:53 PM, wahyoe Unggul wrote:
> >>> hi all
> >>> I have a problem on pop up menu
> >>> file.txt
> >>> 2 5
> >>> 3 4
> >>>
> >>> function popup1_Callback(hObject, eventdata, handles)
> >>> switch get(handles.popup1,'Value')
> >>> case 1
> >>> Type ='method1'
> >>> case 2
> >>> Type ='method2'
> >>> end
> >>>
> >>> function pustbutton1_Callback(hObject, eventdata, handles)
> >>> A=uigetfile({'*.txt';})
> >>> switch Type
> >>> case {'method1'}
> >>> B=A+[2 6;3 2];
> >>> case {'method2'}
> >>> B=A
> >>> end
> >>>
> >>> Error in ==> main>pushbutton1_Callback at 113
> >>> switch Type
> >>> Error in ==> gui_mainfcn at 96
> >>> feval(varargin{:});
> >>> Error in ==> main at 42
> >>> gui_mainfcn(gui_State, varargin{:});
> >>>
> >>> Error in ==>
> >>> @(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))
> >>
> >> I have a question for you:
> >>
> >> In the function pustbutton1_Callback(), when you say
> >>
> >> "switch Type"
> >>
> >> Where do you think the variable "Type" lives?
> >>
> >> --Nasser
>
>
> > hai nasser
> > variable "type" is in the popup1_Callback(hObject, eventdata, handles)
> > switch get(handles.popup1,'Value')
>
> Humm...ok, but you are trying to reference that variable 'Type'
> in another callback, right? from pustbutton1_Callback()
>
> You think it is ok to do so? Do you think by the time you are
> in that other callback, that the variable 'Type' is still
> available for you to access? Even though they are 2 different
> functions?
>
> --Nasser
yes nasser
Can I write just once variable "Type "on "popup1_Callback. (hObject. ..) but it is accessible to all functions or do you have other ideas that can facilitate the variable"Type "to be accessible by some function

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 28 Apr, 2011 04:34:04

Message: 6 of 9

"Nasser M. Abbasi" <nma@12000.org> wrote in message <ipap7p$heo$1@speranza.aioe.org>...
> On 4/27/2011 9:01 PM, wahyoe Unggul wrote:
> > "Nasser M. Abbasi"<nma@12000.org> wrote in message<ipa264$248$1@speranza.aioe.org>...
> >> On 4/27/2011 1:53 PM, wahyoe Unggul wrote:
> >>> hi all
> >>> I have a problem on pop up menu
> >>> file.txt
> >>> 2 5
> >>> 3 4
> >>>
> >>> function popup1_Callback(hObject, eventdata, handles)
> >>> switch get(handles.popup1,'Value')
> >>> case 1
> >>> Type ='method1'
> >>> case 2
> >>> Type ='method2'
> >>> end
> >>>
> >>> function pustbutton1_Callback(hObject, eventdata, handles)
> >>> A=uigetfile({'*.txt';})
> >>> switch Type
> >>> case {'method1'}
> >>> B=A+[2 6;3 2];
> >>> case {'method2'}
> >>> B=A
> >>> end
> >>>
> >>> Error in ==> main>pushbutton1_Callback at 113
> >>> switch Type
> >>> Error in ==> gui_mainfcn at 96
> >>> feval(varargin{:});
> >>> Error in ==> main at 42
> >>> gui_mainfcn(gui_State, varargin{:});
> >>>
> >>> Error in ==>
> >>> @(hObject,eventdata)main('coordinatbutton_Callback',hObject,eventdata,guidata(hObject))
> >>
> >> I have a question for you:
> >>
> >> In the function pustbutton1_Callback(), when you say
> >>
> >> "switch Type"
> >>
> >> Where do you think the variable "Type" lives?
> >>
> >> --Nasser
>
>
> > hai nasser
> > variable "type" is in the popup1_Callback(hObject, eventdata, handles)
> > switch get(handles.popup1,'Value')
>
> Humm...ok, but you are trying to reference that variable 'Type'
> in another callback, right? from pustbutton1_Callback()
>
> You think it is ok to do so? Do you think by the time you are
> in that other callback, that the variable 'Type' is still
> available for you to access? Even though they are 2 different
> functions?
>
> --Nasser
yes,nasser
Can I write just once variable "Type "on "popup1_Callback. (hObject. ..) but it is accessible to all functions or do you have other ideas that can facilitate the variable"Type "to be accessible by some function

Subject: problem on pop up menu

From: Nasser M. Abbasi

Date: 28 Apr, 2011 05:20:50

Message: 7 of 9

On 4/27/2011 9:34 PM, wahyoe Unggul wrote:

> yes,nasser
> Can I write just once variable "Type "on "popup1_Callback. (hObject. ..) but it
>is accessible to all functions

I do not think you can. You really have to think where each
variable lives when you write software. After you return from
a function, all its local variables will be as dead as a
cold stone on a winter night.

>or do you have other ideas that can facilitate
>the variable"Type "to be accessible by some function

Yes, use userData buffer, as in

set(figHandle,'UserData',myData)
myData = get(figHandle,'UserData')

do help on UserData on the documentation for more details.

HTH

--Nasser

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 28 Apr, 2011 05:48:04

Message: 8 of 9

"Nasser M. Abbasi" <nma@12000.org> wrote in message <ipatfn$p5m$1@speranza.aioe.org>...
> On 4/27/2011 9:34 PM, wahyoe Unggul wrote:
>
> > yes,nasser
> > Can I write just once variable "Type "on "popup1_Callback. (hObject. ..) but it
> >is accessible to all functions
>
> I do not think you can. You really have to think where each
> variable lives when you write software. After you return from
> a function, all its local variables will be as dead as a
> cold stone on a winter night.
>
> >or do you have other ideas that can facilitate
> >the variable"Type "to be accessible by some function
>
> Yes, use userData buffer, as in
>
> set(figHandle,'UserData',myData)
> myData = get(figHandle,'UserData')
>
> do help on UserData on the documentation for more details.
>
> HTH
>
> --Nasser
hai nasser
I'm sorry, I do not understand how it works
Can give examples of its application in my case
thanks

Subject: problem on pop up menu

From: wahyoe Unggul

Date: 28 Apr, 2011 06:11:04

Message: 9 of 9

thanks nasser
I was able to run code

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us