Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Creating Timed Events w/Formulas Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
patc
Groupie
Groupie


Joined: December 02 2002
Location: United States
Online Status: Offline
Posts: 48
Posted: April 05 2003 at 18:13 | IP Logged Quote patc

If I create a timed event 10 seconds from now with:

ph_createtimedevent( 0, "FLASH USER MESSAGE", datetime(today(),relativetime(now(),10)) )

I get a return value of 0 and everything works as expected.

if I use a different macro as:

ph_createtimedevent( 0, "A ON", datetime(today(),relativetime(now(),10)) )

where A ON does an X10 A ON

I get a return value of -1 and a timed event of mm/dd/yyyy 00:00:00

What am I doing wrong?



__________________
PatC
Back to Top View patc's Profile Search for other posts by patc
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: April 07 2003 at 17:21 | IP Logged Quote dhoward

Pat,

Well I played with this and played with this and finally found the answer.  The problem is an undocumented bug within the PowerBuilder environment and really has nothing to do with the macro name but instead has to do with the relativetime function.

Apparently the relativetime function will return the time with 6 digits of precision (microseconds) in the fractional seconds field and the insert statement into the timedevents table really only wants to work with 3 digits of precision (milliseconds).  Sometimes it works and sometimes it doesnt.  It's very inconsistent.

Now the workaround...we'll first convert the time to a string and effectively round it to the second.  We then convert that back to a time.  Kludgy, but its the only way Ive been able to get it to work.  I'll create a new PowerHome function that will automatically do this for you for the next version.  Here is the reworked version of your statement:

ph_createtimedevent(0,"A ON",datetime(today(),time(string(relativetime(now(),10),"hh:mm:ss"))))

HTH,

Dave.

 

Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
patc
Groupie
Groupie


Joined: December 02 2002
Location: United States
Online Status: Offline
Posts: 48
Posted: April 08 2003 at 10:37 | IP Logged Quote patc

Thanks Dave. The workaround works OK.

__________________
PatC
Back to Top View patc's Profile Search for other posts by patc
 
Dean
Senior Member
Senior Member
Avatar

Joined: August 21 2003
Location: United States
Online Status: Offline
Posts: 109
Posted: December 22 2004 at 22:40 | IP Logged Quote Dean

Dave,

Does this work OK around midnight? Meaning, if it is today at 23:55:00 and you specify 10 minutes in the future, will the timed event be tomorrow at 00:05:00? When I use the formula evaluator the date/time given back is OK until it evaluates to a date/time past midnight. It says the formula evaluates to...it is blank.
Back to Top View Dean's Profile Search for other posts by Dean
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 22 2004 at 23:21 | IP Logged Quote dhoward

Dean,

Wow, a blast from the past .

The following statement:

ph_createtimedevent( 0, "FLASH USER MESSAGE", datetime(today(),relativetime(now(),10)) )

and

ph_createtimedevent(0,"A ON",datetime(today(),time(string(relativetime(now(),10),"hh:mm:ss"))))

will both fail in the situation that you specify (5 minutes to midnight and 10 minutes in the future). This is because the relativetime function is completely oblivious to the date. If we look at the formula, were just recalculating the time using the current date and combining it into the required datetime.

Since this original question was posed, PowerHome has several new date/time related functions. The one that will concern us in this situation is the ph_relativedatetime function. This function accepts a datetime value and will calculate a new datetime based on upon a supplied set of offset minutes so it has no problems crossing date boundaries. So, the above formula rewritten would be:

ph_createtimedevent(0,"A ON",ph_relativedatetime(today(),10))

Much simpler than it used to be

HTH,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
patc
Groupie
Groupie


Joined: December 02 2002
Location: United States
Online Status: Offline
Posts: 48
Posted: December 23 2004 at 20:51 | IP Logged Quote patc

Ah nuts! The whole house has been running fine since our last exchange. Obviously whatever I implemented is
just waiting to bite me. I'll go back and make the appropriate changes. Thanks to Dave and Dean and Merry Christmas Everyone.

__________________
PatC
Back to Top View patc's Profile Search for other posts by patc
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: December 23 2004 at 21:25 | IP Logged Quote dhoward

Pat,

Hehehe. I see you're keeping up with the board. Yep, the old way is just waiting to bite you around midnight.

Merry Christmas and hope we didnt cause you too much trouble

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
Dean
Senior Member
Senior Member
Avatar

Joined: August 21 2003
Location: United States
Online Status: Offline
Posts: 109
Posted: December 23 2004 at 23:34 | IP Logged Quote Dean

Thanks for the info Dave. I had created a macro that would turn off my snowman air balloon at 10:30pm. The same macro would also create another timed event that would run the same macro 5 minutes into the future. Call me paranoid, but I wanted to make sure if my snowman accidently turned on for some reason that PowerHome would send another off command every 5 minutes. It seemed to be working accept around midnight. According to the PowerHome event log, it started creating the timed event like every second or two. After midnight the log showed the timed event being created every 5 minutes as expected.

Happy Holidays to everyone.

-Dean
Back to Top View Dean's Profile Search for other posts by Dean
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum