|
"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
|