Path: news.mathworks.com!not-for-mail
From: "Titus" <titus.edelhofer@mathworks.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: limit callback function?
Date: Fri, 18 Jul 2008 12:37:55 +0200
Organization: The MathWorks, Inc.
Lines: 53
Message-ID: <g5prq3$qoj$1@fred.mathworks.com>
References: <g5orh5$kc7$1@fred.mathworks.com> <g5ougp$hj3$1@fred.mathworks.com>
NNTP-Posting-Host: de-edelhoft-x.ac.mathworks.de
X-Trace: fred.mathworks.com 1216377475 27411 172.16.75.150 (18 Jul 2008 10:37:55 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Jul 2008 10:37:55 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:480223




"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