Timer Object & handles error

  • Follow


Below is some code I am trying to include in part of my program. It
is essentially a timer function that counts the number of seconds,
minutes and hours since the timer was started (on a button press)
When I am using the 'disp' feature the correct outputs are displayed.
However, when I try to include this with the gui I have created I run
into problems. I use three edit boxes to display the hours, minutes
and seconds since the timer was started. The problem is when I try to
replace the 'disp' function with the line
set(handles.ClockSeconds,'string',num2str(x));
an error is raised with the message that says
 Undefined variable 'handles' or class 'handles.ClockSeconds'.

The edit box being addressed has the ClockSeconds tag and the rest of
the code works correctly when using the disp function so I am
confused to what the problem is.
I have the same problem if either of the ClockMinutes or ClockHours
handles are used also, they also have the correct tags.

Any ideas on what could be wrong/
Thanks
Iain

function t = clockmain
global x y z
% Main function for building a timed application
t = timer;
set(t,'ExecutionMode','fixedRate')
set(t,'Period',1)
set(t,'TimerFcn',@myclock)

start(t)
x=0;
y=0;
z=0;

function myclock(t,event)
global x y z
% MYCLOCK Timer Callback function for clockmain
x=x+1;
disp(z)
disp(y)
disp(x)
if x==59
    y=y+1;
    x=0;
end
if y==59
    z=z+1;
    y=0;
end
0
Reply imurdoch (17) 1/22/2004 9:00:03 AM

Iain wrote:
> Below is some code I am trying to include in part of my program. It
> is essentially a timer function that counts the number of seconds,
> minutes and hours since the timer was started (on a button press)
> When I am using the 'disp' feature the correct outputs are displayed.
> However, when I try to include this with the gui I have created I run
> into problems. I use three edit boxes to display the hours, minutes
> and seconds since the timer was started. The problem is when I try to
> replace the 'disp' function with the line
> set(handles.ClockSeconds,'string',num2str(x));
> an error is raised with the message that says
>  Undefined variable 'handles' or class 'handles.ClockSeconds'.
>
> The edit box being addressed has the ClockSeconds tag and the rest of
> the code works correctly when using the disp function so I am
> confused to what the problem is.
> I have the same problem if either of the ClockMinutes or ClockHours
> handles are used also, they also have the correct tags.

*snip*

> function myclock(t,event)
> global x y z
> % MYCLOCK Timer Callback function for clockmain
> x=x+1;
> disp(z)
> disp(y)
> disp(x)
> if x==59
>     y=y+1;
>     x=0;
> end
> if y==59
>     z=z+1;
>     y=0;
> end

Where in this code are you retrieving the handles structure from the GUI?
Call GUIHANDLES before attempting to call your SET call above.  This way,
the handles structure is defined when you try to index into it to get the
handles to your text boxes.

-- 
Steve Lord
slord@mathworks.com


0
Reply slord (13276) 1/22/2004 1:06:17 PM


Thank you for the info - I now have it working as required, your
assistance is appreciated.
Iain
0
Reply imurdoch (17) 1/23/2004 7:07:02 AM

2 Replies
45 Views

(page loaded in 0.02 seconds)

Similiar Articles:













7/20/2012 4:12:32 PM


Reply: