Hi everyone,
How to show datetime in a static text ?
i want to show it on o form with format like dd-mm-yyyy HH:mm:ss
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: Date time and hour
How to get formatted time:
It's up to you to determine if, how often and how you want to update the text box.
If you are just displaying it once when time the dialog or form is displayed you can do that either in the constructor ( new:( window ParentWin):- ... or in the onShow predicate.
Code: Select all
clauses
run() :-
Tnow = time::now(),
TimeStamp = Tnow:formatDateTime("dd-MM-yyyy", " HH:mm:ss"),
stdio::write("\nTime now: ", TimeStamp),
_ = console::readLine().
If you are just displaying it once when time the dialog or form is displayed you can do that either in the constructor ( new:( window ParentWin):- ... or in the onShow predicate.
Code: Select all
...
myStaticTextCtrl:setText( TimeStamp),
...
-
- Posts: 5
- Joined: 26 Jul 2022 5:50
Re: Date time and hour
i want to update it every second. but i cannot configure to run infinite on a different thread . i have limited knowledge of visual prolog.
-
- VIP Member
- Posts: 458
- Joined: 5 Nov 2000 0:01
Re: Date time and hour
This code snippet should do it for you.
On dialog creation you can start a timer with the interval you want, e.g. 1000 milliseconds.
Store the timer's handle in a static fact.
Use the IDE to create an onTimer/2 event that is invoked whenever the timer passes the threshold.
Update the time display in the onTimer/2 event clause.
On dialog creation you can start a timer with the interval you want, e.g. 1000 milliseconds.
Store the timer's handle in a static fact.
Use the IDE to create an onTimer/2 event that is invoked whenever the timer passes the threshold.
Update the time display in the onTimer/2 event clause.
Code: Select all
facts
dlgTimer : timerHandle := erroneous.
clauses
display(Parent) = Dialog :-
Dialog = new(Parent),
Dialog:show().
clauses
new(Parent) :-
dialog::new(Parent),
generatedInitialize(),
%--
dlgTimer := This:timerSet(1000).
predicates
onTimer : window::timerListener.
clauses
onTimer(_Source, dlgTimer) :-
Tnow = time::now(),
TimeStamp = Tnow:formatDateTime("dd-MM-yyyy", " HH:mm:ss"),
staticText_ctl:setText(TimeStamp),
!.
onTimer(_, _).
-
- VIP Member
- Posts: 1466
- Joined: 28 Feb 2000 0:01
Re: Date time and hour
Using timers like that is somewhat "old fashioned", it has the disadvantage that it "mixes" all your timers in a single handler. Using tickAction's (and delayCall for one shots) has a more direct handler approach:
Here I ignore the returned timerHandle because you only need it for killing (=stopping) the tickAction, which I don't believe is relevant here.
Code: Select all
clauses
new() :-
applicationWindow::new(),
generatedInitialize(),
_ =
tickAction(1000,
{ :-
Tnow = time::now(),
TimeStamp = Tnow:formatDateTime("dd-MM-yyyy", " HH:mm:ss"),
staticText_ctl:setText(TimeStamp)
}).
Regards Thomas Linder Puls
PDC
PDC