function UpdateClock(obj,e)
text3 = getappdata(0,'ClockHandle');
set(text3,'String',datestr(clock,13))
-----------------------------------------------------------------------------------
can anyone tell what I'm doing wrong?...an error occurs..replay asap
kind regards
someone please reply
Never post and just mention that "an error occurs". Be sure to copy
and paste the error message here, as well as the code that it relates
to.
Having said that:
What did the error message tell you? Where did it error in your code?
-Nathan
P.S. Let me know if there is an error before I publish this, thanks.
function [] = GUI_clock()
% Demonstrate how to have a running clock in a GUI.
% Creates a small little GUI which displays the correct time and is updated
% every minute according to the system clock.
%
% Author: Matt Fig
% Date: 1/15/2010
S.fh = figure('units','pixels',...
'position',[300 300 180 50],...
'menubar','none',...
'name','GUI_clock',...
'numbertitle','off',...
'resize','off');
S.tx = uicontrol('style','text',...
'unit','pix',...
'position',[35 10 110 30],...
'string',datestr(now,16),...
'backgroundc',get(S.fh,'color'),...
'fontsize',18,...
'fontweight','bold',...
'foregroundcolor',[.9 .1 .1]);
STRT = 60 - str2double(datestr(now,'ss')); % So we can update every minute.
tmr = timer('Name','Reminder',...
'Period',60,... % Update the time every 60 seconds.
'StartDelay',STRT,... % In seconds.
'TasksToExecute',inf,... % number of times to update
'ExecutionMode','fixedSpacing',...
'TimerFcn',{@updater});
start(tmr); % Start the timer object.
set(S.fh,'deletefcn',{@deleter}) % Kill timer if fig is closed.
function [] = updater(varargin)
% timerfcn for the timer. If figure is deleted, so is timer.
% I use a try-catch here because timers are finicky in my
% experience.
try
set(S.tx,'string',datestr(now,16))
if ~str2double(datestr(now,'MM'))
X = load('gong');
player = audioplayer(X.y, X.Fs);
play(player) % Gong at the top of the hour.
end
clear y Fs player
catch
delete(S.fh) % Close it all down.
end
end
function [] = deleter(varargin)
% If figure is deleted, so is timer.
stop(tmr);
delete(tmr);
end
end
Thanks for your reply but this is actually the problem. the code relates to a static textbox within the application gui I created..it is stand alone.....ok let me retype my original code:
--------------------------------------------------------------------------
function text3_CreateFcn(hObject, eventdata, handles)
t = timer;
set(t,'ExecutionMode','fixedRate',...
'Period',1,'TimerFcn',@UpdateClock);
setappdata(0,'ClockHandle',text3)
start(t)
function UpdateClock(obj,e)
text3 = getappdata(0,'ClockHandle');
set(text3,'String',datestr(clock,13))
----------------------------------------------------------------------
Here is the error:
------------------------------------------------------------------------------
Error in ==> ControllerBuilder>text3_CreateFcn at 1617
setappdata(0,'ClockHandle',text3)
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> ControllerBuilder at 42
gui_mainfcn(gui_State, varargin{:});
??? Error using ==> struct2handle
Error while evaluating uicontrol CreateFcn
--------------------------------------------------------------------------------------------
all I want is that when I open/load my application GUI called "controllerBuilderv1.1", This particular static textbox within my GUI displays the time in a digital format with seconds running (like a normal clock HH:MM:SS).
Your assistance would be much appreciated. thanks
if anyone out there can also hel please do so.
Good work mate.....however, that is not quite what I was looking for...Your code creates a small gui that displays the time. However, what I want is that instead of having another gui display the time, I want a textbox within my own application gui to do the same job (i.e: display the time in HH:MM:SS that updates every seconds).
Can you help? thanks in advance.
btw, your code works well.
Good Day!
Your code in making a real time clock in a GUI works perfectly..
Is it possible for me to put your real time clock in the GUI I made?
What codes do i need to put in the GUI i made so that the clock will appear in my GUI?
Thanks a lot for the help..
kent