Jump to content
Macro Express Forums

Stop Macro after a specific time


Recommended Posts

I own Macro Express Pro and I am trying to create a macro that stops after a specific time captured from the computer system time.

 

For example: After 2:00 AM STOP the macro otherwise just continue. . I need to put it into the macro because I need to stop after other events have been launched (so not using a schedule).

 

So basically I started with something like this but it is not working:

 

[this is the rest of the macro]

Date/Time: Set %T1[1]% to the current date/time using "hh':'nn':'ss ampm" as the format
If variable %T[1]% is Greater Than "2:00:00 am"
  Program Shut Down: notepad
  Macro Stop
Else
End If

[this is the rest of the macro]

 

Any help would be very much appreciated!

Link to comment
Share on other sites

I'm assuming this is in a loop where it will be tested periodically.

 

At startup set a var to the current time. Use the Date/Time command but choose to "Store date/time in a Date/Time variable" from the operation tab. Then add how ever much time you want with the Variable Modify Date/Time. Notice in the bottom right you can do things like add 2 hours with the "Integer or Value" box. Now in your loop set a second time variable and then see if that variable is greater than the first variable. If it is then abort or go to your egress routine.

Date/Time: Set %Start Time% to the current date/time
Variable Modify Date/Time: %End Time% = %Start Time% + 2 Hours
Repeat Until %Test2% Does not Equal "%Test2%"
 Date/Time: Set %Time Now% to the current date/time
 If Variable %Time Now% Is Greater Than "%Time end%"
Macro Stop
 End If
 Delay: 60 seconds, without ability to halt
End Repeat

<DATE/TIME Flags="\xB0" Date="10/1/2009 11:43:30 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="%Start Time%" IsDateVar="TRUE"/>
<VARIABLE MODIFY DATE/TIME DateVar="%End Time%" Option="\x00" LeftVar="%Start Time%" RightVal="2" UseInteger="FALSE" MathOpt="\x03"/>
<REPEAT UNTIL Variable="%Test2%" Condition="\x01" Value="%Test2%"/>
<DATE/TIME Flags="\xB0" Date="10/1/2009 11:43:30 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="%Time Now%" IsDateVar="TRUE"/>
<IF VARIABLE Variable="%Time Now%" Condition="\x03" Value="%Time end%" IgnoreCase="FALSE"/>
<MACRO STOP/>
<END IF/>
<DELAY Flags="\x00" Time="60"/>
<END REPEAT/>

Is this what you had in mind?

Link to comment
Share on other sites

[this is the rest of the macro]

Date/Time: Set %T1[1]% to the current date/time using "hh':'nn':'ss ampm" as the format
If variable %T[1]% is Greater Than "2:00:00 am"
  Program Shut Down: notepad
  Macro Stop
Else
End If

[this is the rest of the macro]

Hi there,

 

My first thought was "you're using an If Greater Than" comparison on a text variable. I didn't think that would work, but I just ran a basic test and it seems to be not a problem for MEP. So that's good.

 

The next thing I noticed is that you're setting the Date/Time to %T1[1]% but then your If statement is checking against %T[1]% Very minor and easy to miss. Also easy to fix.

 

Further tests lead me to conclude that this is the only problem with the macro.

Link to comment
Share on other sites

My first thought was "you're using an If Greater Than" comparison on a text variable. I didn't think that would work, but I just ran a basic test and it seems to be not a problem for MEP. So that's good.
Not always. He's saving the time to a text variable and depending on the time and format a greater than comparison could result in a less than time passing muster. If one had a time text of YYYYMMDDHHNNSS it could work. But it's just way easier to use a time variable which is essentially a decimal value.
Link to comment
Share on other sites

Thanks for the responses. I am defiantly not a programmer just trying to do something simple.

 

Cory,

 

I added the code straight into Macro Express and I get "Line 5: Debug Error: undefined variable or the variable is the wrong type."

 

Is there a setting I need to set or am I adding the macro correctly.

Link to comment
Share on other sites

Two possible problems. First you didn't define the variable. If you hit the save button in the scripting editor it should prompt you that there are undefined variable and then ask if you would like to define them. However there are a few places it will not prompt you for so make sure all variables are defined. Second you have a variable defined with incorrect type. In my script I use a date/time variable, not a text variable as you had used. Make sure all the variables used in line 5 have the correct type.

 

If you're a newb you need to understand the difference between variable types. Please search your help file for a subject named "About Variables". Now chrono variables are actually decimals and this is how all computers understand time. A day has a value of one and time started (in most cases) as zero on 12/31/1899. This was so 1/1/1900 was 1. IE noon on that day would be 1.5. To understand more about serial time see my web page here which explains it and the MEP twist on it.

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...
 Share

×
×
  • Create New...