Jump to content
Macro Express Forums

end macro at certain time


Recommended Posts

this may have been covered, but I haven't found it yet. 
Anyway, what I want to do sounds like it would be easy enough, but I haven't been able to get it working. I have a 40 part macro, each part calls the next macro in line. I am trying to get it to stop the macro all together at the first part if the time of day is 6AM to 7AM. it can either completely stop at 6am, or if possible, stop at 6AM and restart at 7AM, either way. I saw something a while back (seems like years ago) that mentioned something along those lines but haven't been able to find it again. 

Link to comment
Share on other sites

I don't understand your problem. It sounds like a simple condition. If the macro starts and evaluates the time to meet your criteria, then exit the macro. That am I missing?

Link to comment
Share on other sites

Do note that the "EndIf" command does not mean "end the macro if xyz is true."   Rather is marks the end of a logic statement, similar to how "End Repeat" marks the end of a loop.  I suspect that your macro would need something like:

 

-Set variable to current date/time.

-Convert variable to decimal

-IF variable is greater than 6 

- -IF variable is less than 7

- -End Macro

- -End IF

-End IF

 

I haven't actually tried this however, so I'm not sure.  

 

EDIT:  Scratch that.  It's wrong.  Maybe this?

 

<MESSAGEBOX Caption="Starting" Message="Macro Stated." Icon="0"/>
<DATE/TIME Format="h" Flags="\xB0" Date="7/29/2019 7:41:26 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%timeTexTVar%" IsDateVar="FALSE"/>
<VARIABLE MODIFY STRING Option="\x04" Destination="%timeTexTVar%" Variable="%timeIntegerVar%"/>
<MESSAGEBOX Caption="Progress" Message="Variable is %timeIntegerVar%" Icon="0"/>
<IF VARIABLE Variable="%timeIntegerVar%" Condition="\x04" Value="6" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%timeIntegerVar%" Condition="\x02" Value="8" IgnoreCase="FALSE"/>
<MESSAGEBOX Caption="Logic TRUE Result" Message="The hour is 6 or greater, but less than 8." Icon="0"/>
<ELSE/>
<MESSAGEBOX Caption="Logic FALSE Result" Message="The hour IS NOT 6 or greater, but less than 8." Icon="0"/>
<END IF/>


This one checks for a 2 hour time window (6 to 8).  Important:  I'm not sure, but I think it won't know the different between AM and PM.  

Link to comment
Share on other sites

kunkel321
yea, I know the EnfIf doesn't "end the macro" it just ends the if condition. ran a test on mine for a few hours using variable times, so far seems to be working. now to incorporate it into other areas of my macros. This was simple and effective enough

<VARIABLE SET INTEGER Option="\x00" Destination="%TargetHour%" Value="5"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%TargetMinute%" Value="30"/>
<VARIABLE SET INTEGER Option="\x13" Destination="%Hour%"/>
<VARIABLE SET INTEGER Option="\x14" Destination="%Minute%"/>
<MACRO PLAYBACK SPEED Speed="1"/>
<IF VARIABLE Variable="%Hour%" Condition="\x04" Value="%TargetHour%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%Minute%" Condition="\x04" Value="%TargetMinute%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Closing" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs24 Closing Macro \r\n\\par Due to Time\\b0\\f1\\fs16 \r\n\\par }\r\n" Left="641" Top="360" Width="167" Height="143" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x02" Delay="0"/>
<DELAY Flags="\x03" Time="1857"/>
<TEXT BOX CLOSE Header="Closing"/>
<MACRO STOP/>
<END IF/>

 

Link to comment
Share on other sites

  • 2 weeks later...

ok, back to this again. I have noticed that the above isn't exactly doing what I want it to do after all. it is set to stop the macro if the time is equal to or greater than 5:30am, well, the problem I have is the macro will not run at all with this setup until it's after 12am and then stops at 5:30, so it won't run during the day. what I really need is the command for the macro to stop running between 5:30am and then start back up at 7am.
what I tried was this, seems to do nothing at all lol

<VARIABLE SET INTEGER Option="\x00" Destination="%TargetHour%" Value="5"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%TargetMinute%" Value="30"/>

<VARIABLE SET INTEGER Option="\x00" Destination="%TargetHour2%" Value="7"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%TargetMinute2%" Value="00"/>
<VARIABLE SET INTEGER Option="\x13" Destination="%Hour%"/>
<VARIABLE SET INTEGER Option="\x14" Destination="%Minute%"/>
<IF VARIABLE Variable="%Hour%" Condition="\x04" Value="%TargetHour%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%Hour%" Condition="\x05" Value="%TargetHour2%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%Minute%" Condition="\x04" Value="%TargetMinute%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%Minute%" Condition="\x05" Value="%TargetMinute2%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Closing" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs24 Closing Macro \r\n\\par Due to Time\\b0\\f1\\fs16 \r\n\\par }\r\n" Left="641" Top="360" Width="167" Height="143" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x02" Delay="0"/>
<DELAY Flags="\x03" Time="1857"/>
<TEXT BOX CLOSE Header="Closing"/>
<MACRO STOP/>
<END IF/>

Link to comment
Share on other sites

Not sure, but it might be your "if less than 7:00" part.  The "< 7" part is fine, but the "< 00" part will always be true, because ME is not looking at it as a time, but as an integer (zero).  

 

EDIT:   Actually I guess "< 0" would always be FALSE, because the time will never  be a negative number...  

Link to comment
Share on other sites

28 minutes ago, terrypin said:

It looks as if you're stopping the macro if it meets the conditions for running?

 

And presumably those TBD commands at the end are temporary? (BTW, why such an odd time delay? Come to that, why a delay at all?)

this is being used for an application that goes off line around 6am and then comes back online around 6:30am, thats why the weird times. I start it before I go to bed (usually around 1am) and let it run until I wake up (usually around 10 or 11am) and then if I am not home of a day I let it run as well. the way I originally had it set up it would stop the macro at 5:30am, but then after that you could not run it at all unless you disabled those commands in the macro because I guess since anything after 5:30am is greater than that set time up until 12am. so basically I was just messing around trying to figure out how to have it stop at 5:30 and then restart at 7. 

Link to comment
Share on other sites

It would be easier to use decimals. Try this:

// Change the following start date and time to your requirement, e.g. 07/08/19 05:00:00
Date/Time: Set %dtStart% to "07/08/19 16:00:00" // Set start = 4pm = 16:00
Convert Date/Time to Decimal: %dtStart% => %dStart%
 
// Change the following end date and time to your requirement, e.g. 07/08/19 07:30:00
Date/Time: Set %dtEnd% to "07/08/19 16:58:00" // Set end = 16:44
Convert Date/Time to Decimal: %dtEnd% => %dEnd%
 
Date/Time: Set %dtCurrent% to the current date/time
Convert Date/Time to Decimal: %dtCurrent% => %dCurrent%
Text Box Display:  // TEMP, remove after testing
If Variable %dCurrent% Is Greater Than or Equal To "%dStart%"
  AND
If Variable %dCurrent% Is Less Than or Equal To "%dEnd%"
  Text Box Display: Continue
Else
  Text Box Display: Close // TEMP, remove after testing
  Macro Stop
End If

 

 

 

CODE

<COMMENT Value="Change the following start date and time to your requirement, e.g. 07/08/19 05:00:00"/>
<DATE/TIME Flags="\xB1" Date="07/08/19 16:00:00" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Prompt="What is the start time for macro running?" Left="Center" Top="Center" Monitor="0" Variable="%dtStart%" IsDateVar="TRUE" _COMMENT="Set start = 4pm = 16:00"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtStart%" Dest="%dStart%"/>
<COMMENT/>
<COMMENT Value="Change the following end date and time to your requirement, e.g. 07/08/19 07:30:00"/>
<DATE/TIME Flags="\xB1" Date="07/08/19 16:58:00" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Prompt="What is end time for macro running?" Left="Center" Top="Center" Monitor="0" Variable="%dtEnd%" IsDateVar="TRUE" _COMMENT="Set end = 16:44"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtEnd%" Dest="%dEnd%"/>
<COMMENT/>
<DATE/TIME Flags="\xB0" Date="07/08/19 15:48:26" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%dtCurrent%" IsDateVar="TRUE"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtCurrent%" Dest="%dCurrent%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 dtCurrent\\f1  = \\f0 %dtCurrent%\\f1  (Date/Time format)\\f0 \r\n\\par dCurrent\\f1  = \\f0 %dCurrent%\\f1  (Decimal format)\r\n\\par \r\n\\par dtStart = %dtStart% (Date/Time format)\r\n\\par dStart = %dStart%\r\n\\par \\f0 \r\n\\par \\f1 dtEnd = %dtEnd% (Date/Time format)\\f0 \r\n\\par \\f1 dEnd = %dEnd%\r\n\\par \r\n\\par \\f0 \r\n\\par \r\n\\par \r\n\\par \r\n\\par }\r\n" Left="584" Top="485" Width="515" Height="296" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE" _COMMENT="TEMP, remove after testing"/>
<IF VARIABLE Variable="%dCurrent%" Condition="\x04" Value="%dStart%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%dCurrent%" Condition="\x05" Value="%dEnd%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Continue" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Current time is inside the allowed period of\r\n\\par %dtStart% to %dtEnd%\r\n\\par \r\n\\par so run the rest of your macro here.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="Close" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Current time is outside the allowed period, so the macro will now stop.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _COMMENT="TEMP, remove after testing"/>
<MACRO STOP/>
<END IF/>

 

Link to comment
Share on other sites

11 minutes ago, terrypin said:

It would be easier to use decimals. Try this:


// Change the following start date and time to your requirement, e.g. 07/08/19 05:00:00
Date/Time: Set %dtStart% to "07/08/19 16:00:00" // Set start = 4pm = 16:00
Convert Date/Time to Decimal: %dtStart% => %dStart%
 
// Change the following end date and time to your requirement, e.g. 07/08/19 07:30:00
Date/Time: Set %dtEnd% to "07/08/19 16:58:00" // Set end = 16:44
Convert Date/Time to Decimal: %dtEnd% => %dEnd%
 
Date/Time: Set %dtCurrent% to the current date/time
Convert Date/Time to Decimal: %dtCurrent% => %dCurrent%
Text Box Display:  // TEMP, remove after testing
If Variable %dCurrent% Is Greater Than or Equal To "%dStart%"
  AND
If Variable %dCurrent% Is Less Than or Equal To "%dEnd%"
  Text Box Display: Continue
Else
  Text Box Display: Close // TEMP, remove after testing
  Macro Stop
End If

 

 

 

CODE


<COMMENT Value="Change the following start date and time to your requirement, e.g. 07/08/19 05:00:00"/>
<DATE/TIME Flags="\xB1" Date="07/08/19 16:00:00" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Prompt="What is the start time for macro running?" Left="Center" Top="Center" Monitor="0" Variable="%dtStart%" IsDateVar="TRUE" _COMMENT="Set start = 4pm = 16:00"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtStart%" Dest="%dStart%"/>
<COMMENT/>
<COMMENT Value="Change the following end date and time to your requirement, e.g. 07/08/19 07:30:00"/>
<DATE/TIME Flags="\xB1" Date="07/08/19 16:58:00" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Prompt="What is end time for macro running?" Left="Center" Top="Center" Monitor="0" Variable="%dtEnd%" IsDateVar="TRUE" _COMMENT="Set end = 16:44"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtEnd%" Dest="%dEnd%"/>
<COMMENT/>
<DATE/TIME Flags="\xB0" Date="07/08/19 15:48:26" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%dtCurrent%" IsDateVar="TRUE"/>
<CONVERT DATE/TIME TO DECIMAL Source="%dtCurrent%" Dest="%dCurrent%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 dtCurrent\\f1  = \\f0 %dtCurrent%\\f1  (Date/Time format)\\f0 \r\n\\par dCurrent\\f1  = \\f0 %dCurrent%\\f1  (Decimal format)\r\n\\par \r\n\\par dtStart = %dtStart% (Date/Time format)\r\n\\par dStart = %dStart%\r\n\\par \\f0 \r\n\\par \\f1 dtEnd = %dtEnd% (Date/Time format)\\f0 \r\n\\par \\f1 dEnd = %dEnd%\r\n\\par \r\n\\par \\f0 \r\n\\par \r\n\\par \r\n\\par \r\n\\par }\r\n" Left="584" Top="485" Width="515" Height="296" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE" _COMMENT="TEMP, remove after testing"/>
<IF VARIABLE Variable="%dCurrent%" Condition="\x04" Value="%dStart%" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%dCurrent%" Condition="\x05" Value="%dEnd%" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="Continue" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Current time is inside the allowed period of\r\n\\par %dtStart% to %dtEnd%\r\n\\par \r\n\\par so run the rest of your macro here.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="Close" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Current time is outside the allowed period, so the macro will now stop.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _COMMENT="TEMP, remove after testing"/>
<MACRO STOP/>
<END IF/>

 

ok, I'll give this a shot. question, being it has the date as well as the time in this, will I have to change the date in the code every day? or can this be done with strictly time and not  have the date at all? or does this automatically adjust for the date, or does the date not matter at all? sorry, making "time based" macros is completely new to me. the most I have really done until a few months ago was basically doing "screen recordings" and then editing that as needed lol

Link to comment
Share on other sites

I think there may be a simpler way to monitor the time and stop the macro:

 

Repeat Until %0% Equals "1" // Start an infinite loop
  Delay: 1000 milliseconds // Do whatever you need to do while the macro is running
  Date/Time: Set %Time% to the current date/time using "hhmm" as the format // Extract the time as a four digit number, e.g., 5:30 a.m. =  "0530"
  If Variable %Time% Equals "0530"
    Repeat Exit // Break out of the infinite loop
  End If
End Repeat
Text Box Display: Stopped at 5:30 a.m.

It's based on the idea that Macro Express can extract the current time in a format that you can choose:, e.g.,  If I express the time as "hhmm" then the macro can periodically look for "0530"

 

<REPEAT UNTIL Variable="%0%" Condition="\x00" Value="1" _COMMENT="Start an infinite loop"/>
<DELAY Flags="\x02" Time="1000" _COMMENT="Do whatever you need to do while the macro is running"/>
<DATE/TIME Format="hhmm" Flags="\xB0" Date="30-Dec-99" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%Time%" IsDateVar="FALSE" _COMMENT="Extract the time as a four digit number, e.g., 5:30 a.m. =  \"0530\""/>
<IF VARIABLE Variable="%Time%" Condition="\x00" Value="0530" IgnoreCase="FALSE"/>
<REPEAT EXIT _COMMENT="Break out of the infinite loop"/>
<END IF/>
<END REPEAT/>
<TEXT BOX DISPLAY Title="Stopped at 5:30 a.m." Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

To restart the macro at a particular time, set its activation to "Schedule" and specify the daily start time.

Link to comment
Share on other sites

18 hours ago, ellinarac said:

ok, I'll give this a shot. question, being it has the date as well as the time in this, will I have to change the date in the code every day? or can this be done with strictly time and not  have the date at all? or does this automatically adjust for the date, or does the date not matter at all? sorry, making "time based" macros is completely new to me. the most I have really done until a few months ago was basically doing "screen recordings" and then editing that as needed lol

 

It all depends on how much flexibility you want. Your own code indicated that you may at least want to change the start and stop time. The start date in my code can be any date after you want the program to run, and the end date similarly sets the before target. If you run the macro exactly as it stands you'll quickly get it.

 

But now that I understand your objective more clearly I'd suggest you use @acantor's much simpler method.

 

EDIT: And I see that my macro has inverted the 'Off' period!

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...