Jump to content
Macro Express Forums

stop macro at 3pm


Recommended Posts

Hello, i am using ME Pro 4.2.2.1. I have a macro that runs and runs and runs. I want that macro to stop at 3pm. It can be 3:10pm or 3:35pm. really does not matter. I read the post http://pgmacros.invisionzone.com/index.php?showtopic=4277 But I am stuck. Here is how I am approaching it. Forgive me, as I am not good with taking a "how it works" and translating it into the actual code. So, I am posting my code here. And if you are replying, please please post code.

 

ok... so using the Note Pad method that I read from the post....

 

This is what I created. The name of my macro is P4612

Line 01. Activate or Launch: Window "Notepad", Program "NOTEPAD.EXE", Parameters ""

Line 02. Delay: 1 seconds

Line 03. Variable Set Integer %N[5]%: Set to the Current Hour

Line 04. Delay: 1 seconds

Line 05. Activate or Launch: Window "Notepad", Program "NOTEPAD.EXE", Parameters ""

Line 06. Text Type (Simulate Keystrokes): <ALT>

Line 07. Text Type (Simulate Keystrokes): e

Line 08. Text Type (Simulate Keystrokes): a

Line 09. Text Type (Simulate Keystrokes): <DELETE>

Line 10. Text Type (Simulate Keystrokes): %N[5]%

 

ok....those ten lines gave me the Hour in NotePad. When the value in NotePad says 15 (15 is 3pm), I want macro P4612 to stop running. So I created a macro named P4613. However, I have no idea as to how to write the code that says: check the value in NotePad. If the value in NotePad is 15, then Macro Stop. Any help is appreciated.

Link to comment
Share on other sites

I would approach is completely differently. But before I get to that please explain how it is your macro "runs and runs". A macro should run and complete in short order unless it's performing some huge processes. What I'm trying to get here is that you really shouldn't need to have something that stops it this way. IE if you set things up properly you don't need to have something that kills it. So please explain first what you're doing then I'll give you some pointers.

Link to comment
Share on other sites

I am running a scrape of web pages beginning at 5am. The macro scrapes thousands of pages, takes the text, and dumps the text into an Access database for further modification and analysis. I really do not want to define how many pages the macro actually scrapes. I use the Repeat 100000 times counter. All the different pages are in a excel spreadsheet. so, i go to excel, copy and paste the address, then do the copy of the entire web page. I just want it to continue running the macro forever, until it hits 3pm. At 3pm, i want this macro to stop, and have another macro begin, so that the data can be processed in the database. thanks.

Link to comment
Share on other sites

Edit: Small code error corrected

 

Maybe insert something like this in your loop. Macro Express seems to assume a 24 hour clock with the Current Hour variable.

 

Variable Set Integer %Hour%: Set to the Current Hour
Variable Set Integer %Minute%: Set to the Current Minute
If Variable %Hour% Equals "15"
 And
If Variable %Minute% Equals "0"
 Macro Stop
End If

 

This could fail if the loop takes longer than a minute to run. So you might want to change the code to something like this, which will stop the macro between 3:00 and 3:05:

 

Variable Set Integer %Hour%: Set to the Current Hour
Variable Set Integer %Minute%: Set to the Current Minute
If Variable %Hour% Equals "15"
 And
If Variable %Minute% Is Less or Equal to "5"
 Macro Stop
End If

Link to comment
Share on other sites

Bob,

 

Here's one way to do it. (Edit: Alan got there while I was writing it!)

 

// Demonstrating how to stop a macro at a specific time of day, for bobaol.

Program Launch: "notepad.exe" (Normal)

Parameters: // To illustrate the method clearly.

Repeat Until %tCurrentTime% Equals "15:00" // This will stop the macro at 3 pm.

Date/Time: Set %dtCurrentTime% to the current date/time

Variable Modify Date/Time: Convert to Text String

Text Type (Simulate Keystrokes): Current Hour:Minute as text is %tCurrentTime%<ENTER><ENTER>

Delay: 5 seconds // Set this depending on the accuracy required. In your case perhaps 60 seconds.

// Perform all your web scraping etc.

End Repeat

 

<COMMENT Value="Demonstrating how to stop a macro at a specific time of day, for bobaol."/>
<PROGRAM LAUNCH Path="C:\\windows\\notepad.exe" Mode="\x00" Default_Path="TRUE" Wait="1" Get_Console="FALSE" _COMMENT="To illustrate the method clearly."/>
<REPEAT UNTIL Variable="%tCurrentTime%" Condition="\x00" Value="15:00" _COMMENT="This will stop the macro at 3 pm."/>
<DATE/TIME Flags="\xB0" Date="10/06/2012 08:08:57" 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="%dtCurrentTime%" IsDateVar="TRUE"/>
<VARIABLE MODIFY DATE/TIME DateVar="%dtCurrentTime%" Option="\x09" LeftVar="HH:mm" RightVal="%tCurrentTime%" UseInteger="FALSE" MathOpt="\x00"/>
<TEXT TYPE Action="0" Text="Current Hour:Minute as text is %tCurrentTime%<ENTER><ENTER>"/>
<DELAY Flags="\x01" Time="5" _COMMENT="Set this depending on the accuracy required. In your case perhaps 60 seconds."/>
<COMMENT Value="Perform all your web scraping etc."/>
<END REPEAT/>[/b]
[b]

 

Here's the exported macro:

https://dl.dropbox.c...edTime-Demo.mex

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Bobaol if your running a long repeat process I would simply check on each iteration. Use the date/time commands and variables. 3PM is 0.625 so if the current time is greater than that execute a Macro Stop.

Link to comment
Share on other sites

Never fails to surprise me how often users post here with a problem that they've apparently been wrestling with yet they either never bother to read later posts or, if they do, fail to offer any feedback.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Hi Terry, You make a good point, as I usually never provide additional feedback after the issue is resolved. Thanks for bringing this to my attention. I will be more diligent on this matter in the future.

 

As for feedback regarding this particular issue, the issue is resolved. The method I ended up using is looking for the words inside the Clipboard. I will post the code below.

 

As for your solution in itself, yes, it worked. And I really appreciate the code, and I understand the code. However, it is not exactly what it was I was asking for. I guess what I was really looking for is a way to evaluate the data inside Notepad. That is, today I am looking for the number 15 inside Notepad, but tomorrow, I want to use the same method to look for the letters Hello_World, and so on... In my code below, it asks if Clipboard contains 15, then stop. I want it to say is if Notepad contains 15, then stop.

 

 

<DELAY Flags="\x01" Time="1"/>

<REPEAT START Start="1" Step="1" Count="10000" Save="FALSE"/>

<DELAY Flags="\x01" Time="1"/>

<ACTIVATE OR LAUNCH Title="Notepad" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\WINNT\\NOTEPAD.EXE" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/>

<DELAY Flags="\x01" Time="1"/>

<VARIABLE SET INTEGER Option="\x13" Destination="%N[5]%"/>

<DELAY Flags="\x01" Time="1"/>

<ACTIVATE OR LAUNCH Title="Notepad" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\WINNT\\NOTEPAD.EXE" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/>

<COMMENT Value="// select all and clear all of it, in case there is anything in the NotePad"/>

<TEXT TYPE Action="0" Text="<ALT>"/>

<TEXT TYPE Action="0" Text="e"/>

<TEXT TYPE Action="0" Text="a"/>

<TEXT TYPE Action="0" Text="<DELETE>"/>

<TEXT TYPE Action="0" Text="%N[5]%"/>

<DELAY Flags="\x01" Time="1"/>

<ACTIVATE OR LAUNCH Title="Notepad" Exact_Match="FALSE" Wildcards="FALSE" Path="C:\\WINNT\\NOTEPAD.EXE" Mode="\x00" Default_Path="TRUE" Wait="1" Wait_For_Program="12"/>

<DELAY Flags="\x01" Time="1"/>

<COMMENT Value="// select all"/>

<TEXT TYPE Action="0" Text="<ALT>"/>

<TEXT TYPE Action="0" Text="e"/>

<TEXT TYPE Action="0" Text="a"/>

<DELAY Flags="\x01" Time="1"/>

<COMMENT Value="// copy"/>

<TEXT TYPE Action="0" Text="<ALT>"/>

<TEXT TYPE Action="0" Text="e"/>

<TEXT TYPE Action="0" Text="c"/>

<COMMENT Value="// select all"/>

<DELAY Flags="\x01" Time="1"/>

<COMMENT Value="// http://pgmacros.invisionzone.com/index.php?showtopic=5081"/>

<COMMENT Value="says, if the clipboard contain the value 15 then stop the macro. 15 is for 3pm."/>

<IF CLIPBOARD Option="\x01" Text="15" CaseSensitive="FALSE"/>

<MACRO STOP/>

<END IF/>

 

thanks.

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