Thread Subject: limit callback function?

Subject: limit callback function?

From: ching l

Date: 18 Jul, 2008 01:27:01

Message: 1 of 5

is it possible to limit the callback function?

for example, the gui button can only be pressed for 10
times, then the callback function is not valid anymore after
10 times.

thanks.

Subject: limit callback function?

From: Rodney Thomson

Date: 18 Jul, 2008 02:18:01

Message: 2 of 5

"ching l" <chinglnc@hotmail.com> wrote in message
<g5orh5$kc7$1@fred.mathworks.com>...
> is it possible to limit the callback function?
>
> for example, the gui button can only be pressed for 10
> times, then the callback function is not valid anymore after
> 10 times.
>
> thanks.
>
>

You could just set up a field in the handles structure
called count that is initialised to 1 in the OpeningFcn.
Then the button callback becomes:

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see GUIDATA)

    handles = guidata(gcbo);

    if (handles.count <= 10)
        fprintf(1, 'Pressed %d times\n', handles.count);
        handles.count = handles.count + 1;
    end
    
    guidata(gcbo, handles);

%-------------

Note, the callback is still valid and executed on each
button press, just nothing really happens. However, you can
allow the call back to function as before by resetting the
value in handles.count to 1 by another callback.

--
http://iheartmatlab.blogspot.com

Subject: limit callback function?

From: Titus

Date: 18 Jul, 2008 10:37:55

Message: 3 of 5


"Rodney Thomson" <readmore@iheartmatlab.blogspot.com> schrieb im Newsbeitrag
news:g5ougp$hj3$1@fred.mathworks.com...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g5orh5$kc7$1@fred.mathworks.com>...
>> is it possible to limit the callback function?
>>
>> for example, the gui button can only be pressed for 10
>> times, then the callback function is not valid anymore after
>> 10 times.
>>
>> thanks.
>>
>>
>
> You could just set up a field in the handles structure
> called count that is initialised to 1 in the OpeningFcn.
> Then the button callback becomes:
>
> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject handle to pushbutton1 (see GCBO)
> % eventdata reserved - to be defined in a future version of
> MATLAB
> % handles structure with handles and user data (see GUIDATA)
>
> handles = guidata(gcbo);
>
> if (handles.count <= 10)
> fprintf(1, 'Pressed %d times\n', handles.count);
> handles.count = handles.count + 1;
> end
>
> guidata(gcbo, handles);
>
> %-------------
>
> Note, the callback is still valid and executed on each
> button press, just nothing really happens. However, you can
> allow the call back to function as before by resetting the
> value in handles.count to 1 by another callback.
>
> --
> http://iheartmatlab.blogspot.com

additionally, you may disable the button completely:
when you reach the max count in your callback:

set(hObject, 'enable', 'off')

Titus

Subject: limit callback function?

From: ching l

Date: 18 Jul, 2008 14:36:01

Message: 4 of 5

"Rodney Thomson" <readmore@iheartmatlab.blogspot.com> wrote
in message <g5ougp$hj3$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g5orh5$kc7$1@fred.mathworks.com>...
> > is it possible to limit the callback function?
> >
> > for example, the gui button can only be pressed for 10
> > times, then the callback function is not valid anymore after
> > 10 times.
> >
> > thanks.
> >
> >
>
> You could just set up a field in the handles structure
> called count that is initialised to 1 in the OpeningFcn.
> Then the button callback becomes:
>
> % --- Executes on button press in pushbutton1.
> function pushbutton1_Callback(hObject, eventdata, handles)
> % hObject handle to pushbutton1 (see GCBO)
> % eventdata reserved - to be defined in a future version of
> MATLAB
> % handles structure with handles and user data (see
GUIDATA)
>
> handles = guidata(gcbo);
>
> if (handles.count <= 10)
> fprintf(1, 'Pressed %d times\n', handles.count);
> handles.count = handles.count + 1;
> end
>
> guidata(gcbo, handles);
>
> %-------------
>
> Note, the callback is still valid and executed on each
> button press, just nothing really happens. However, you can
> allow the call back to function as before by resetting the
> value in handles.count to 1 by another callback.
>
> --
> http://iheartmatlab.blogspot.com


I always have this kind of errors, and it happens again...
What can I do about it?

??? Reference to non-existent field 'count'.

Error in ==> listening>answer_faster_Callback at 110
if(handles.count<=3)

Error in ==> gui_mainfcn at 75
        feval(varargin{:});

Error in ==> listening at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback.

Subject: limit callback function?

From: Titus

Date: 18 Jul, 2008 15:00:28

Message: 5 of 5


"ching l" <chinglnc@hotmail.com> schrieb im Newsbeitrag
news:g5q9oh$bq6$1@fred.mathworks.com...
> "Rodney Thomson" <readmore@iheartmatlab.blogspot.com> wrote
> in message <g5ougp$hj3$1@fred.mathworks.com>...
>> "ching l" <chinglnc@hotmail.com> wrote in message
>> <g5orh5$kc7$1@fred.mathworks.com>...
>> > is it possible to limit the callback function?
>> >
>> > for example, the gui button can only be pressed for 10
>> > times, then the callback function is not valid anymore after
>> > 10 times.
>> >
>> > thanks.
>> >
>> >
>>
>> You could just set up a field in the handles structure
>> called count that is initialised to 1 in the OpeningFcn.
>> Then the button callback becomes:
>>
>> % --- Executes on button press in pushbutton1.
>> function pushbutton1_Callback(hObject, eventdata, handles)
>> % hObject handle to pushbutton1 (see GCBO)
>> % eventdata reserved - to be defined in a future version of
>> MATLAB
>> % handles structure with handles and user data (see
> GUIDATA)
>>
>> handles = guidata(gcbo);
>>
>> if (handles.count <= 10)
>> fprintf(1, 'Pressed %d times\n', handles.count);
>> handles.count = handles.count + 1;
>> end
>>
>> guidata(gcbo, handles);
>>
>> %-------------
>>
>> Note, the callback is still valid and executed on each
>> button press, just nothing really happens. However, you can
>> allow the call back to function as before by resetting the
>> value in handles.count to 1 by another callback.
>>
>> --
>> http://iheartmatlab.blogspot.com
>
>
> I always have this kind of errors, and it happens again...
> What can I do about it?
>
> ??? Reference to non-existent field 'count'.
>
> Error in ==> listening>answer_faster_Callback at 110
> if(handles.count<=3)
>
> Error in ==> gui_mainfcn at 75
> feval(varargin{:});
>
> Error in ==> listening at 42
> gui_mainfcn(gui_State, varargin{:});
>
> ??? Error while evaluating uicontrol Callback.

Hi,
you oversaw this sentence in the last post of Rodney:

You could just set up a field in the handles structure
called count that is initialised to 1 in the OpeningFcn.

This means you should add
handles.count = 1;
in your GUI_OpeningFcn.

Titus

Tags for this Thread

Everyone's Tags:

gui

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
gui ching l 17 Jul, 2008 21:30:23
rssFeed for this Thread

Contact us at files@mathworks.com