How to close EndIf loop when Notepad message is open...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
zerp
Newbie
Posts: 5
Joined: Mon Nov 30, 2009 10:24 pm

How to close EndIf loop when Notepad message is open...

Post by zerp » Mon Nov 30, 2009 11:08 pm

I was created macro to edit some csv reports, that i want import to mdb or Excel.
This macro must delete lots of headers in text. When script find "PAGE", delete 3 lines.
Macro find and edit all lines with "PAGE", but when I want to stop and close loop program, quickly send Notepad message Cannot find "PAGE" and continue making changes. :?

How to close loop, save automaticaly this file and close this macro?
or ... how to WaitWindowOpen recognize Notepad message Cannot find "PAGE"?

Thanks!

--------------------

Code: Select all

Run>notepad.exe
WaitWindowOpen>Untitled - Notepad

Press Alt
Send>fo
Release Alt
WaitWindowOpen>Open
Wait>0.5
WaitWindowClosed>Open

Let>Label1=PAGE
Label>START
GoSub>FindDATA
GoSub>DeletePAGE

Srt>FindDATA
'Find all "PAGE" in opened textfile
Press Alt
Send>ef
Release Alt
Send>Label1
Press ENTER

Press Alt
Press F4
Release Alt
End>FindDATA

If FindDATA=Page

Srt>DeletePAGE
'Delete rows
Press Shift
Press Home
Release Shift
Press Up
Press Shift
Press Down * 3
Release Shift
Press Del
END>DeletePAGE
'Here is problem!
Else

Let>MSG_STAYONTOP=1
MessageModal>"PAGE" NOT FOUND!

Endif

Goto>START

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Dec 01, 2009 2:58 am

Might be able to use a single RegEx command to remove the lnes vs. the looping process.

Can you provide good samples of files showing them before and after the replacements of the header lines?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Dec 01, 2009 3:45 am

Quite cumbersome using Notepad, MacroScheduler can write a new file skipping 3 lines each time it hits a line with PAGE and (you probably want to keep the original file anyway). You could use variables for the filenames, and/or automatically create a list of all csv's in a directory, or matching a wildcard to fully automate the process. Here's a suggestion for the file rewrite part. You could also read the whole file into memory and use Separate> to put the lines into an array rather than reading line by line.

Code: Select all

Let>lnum=1
Label>start
ReadLn>c:\temp\testdat.txt,lnum,newline
If>newline=##EOF##,finish
Position>PAGE,newline,1,ppos
If>ppos<>0,linedel
WriteLn>c:/temp/testdat2.txt,res,newline
Let>lnum=lnum+1
Goto>start
Label>linedel
Let>lnum=lnum+3
Goto>start
Label>finish



zerp
Newbie
Posts: 5
Joined: Mon Nov 30, 2009 10:24 pm

Skip empty

Post by zerp » Tue Dec 01, 2009 8:32 am

Great, work's fine! :D
I'm new with this program...
Can you help me how to avoid empty lines copied in new file?
When code find empty " " skip this line.

Example, in my new file is remained this:
*** Unit T2 -- Journal Complete ***
11/14/09

and this:

Thanks!

Me_again wrote:Quite cumbersome using Notepad, MacroScheduler can write a new file skipping 3 lines each time it hits a line with PAGE and
(you probably want to keep the original file anyway). You could use variables for the filenames, and/or automatically create a list of all csv's in a directory, or matching a wildcard to fully automate the process. Here's a suggestion for the file rewrite part. You could also read the whole file into memory and use Separate> to put the lines into an array rather than reading line by line.

Code: Select all

Let>lnum=1
Label>start
ReadLn>c:\temp\testdat.txt,lnum,newline
If>newline=##EOF##,finish
Position>PAGE,newline,1,ppos
If>ppos<0>c:/temp/testdat2.txt,res,newline
Let>lnum=lnum+1
Goto>start
Label>linedel
Let>lnum=lnum+3
Goto>start
Label>finish



Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Dec 01, 2009 3:14 pm

Does the date line always follow the "Journal Complete" line? If not what is unique about the date line, are there never dates in the data lines, or what?

Are the blank lines truly blank, or could there be one or more space characters there?
[/code]

zerp
Newbie
Posts: 5
Joined: Mon Nov 30, 2009 10:24 pm

Post by zerp » Tue Dec 01, 2009 9:38 pm

Me_again wrote:Does the date line always follow the "Journal Complete" line? If not what is unique about the date line, are there never dates in the data lines, or what?

Are the blank lines truly blank, or could there be one or more space characters there?
[/code]

Code: Select all


Thanks to the efforts...
Here is example (short) of lines between text:

 
PAGE 001            PROCESS ALARM JOURNAL       
------------------------------------------------
     11/14/09                                   
ALM 07:49:55     21PC1            PVHI          
ACK 07:50:40     21PC1            PVHI          
RTN 07:50:56     21PC1            PVHI          
ALM 08:37:25     21PC1            PVHI          
ACK 23:20:35     21PC1            PVHH          
ACK 23:20:35     21PC1            PVHI          
     *** Unit T2  --  Journal Complete ***    
     11/14/09                                   
RTN 07:36:21     21PI524          PVLO          
RTN 07:37:55     21TC518          PVLO          
ALM 07:39:10     21HSM02          OVRDI2        
RTN 07:39:12     21HSM02          OVRDI2        
ALM 07:40:13     21HSM02          OVRDI0        
RTN 07:40:13     21HSM02          OVRDI0        
RTN 08:01:16     21HSM12          OVRDI2        
 
PAGE 002            PROCESS ALARM JOURNAL       
------------------------------------------------
ALM 08:02:16     21HSM12          OVRDI0        
RTN 08:02:16     21HSM12          OVRDI0        
ALM 08:02:45     21PI524          PVLO          
ALM 08:03:07     21FC512          BADPV         
RTN 08:03:17     21FC512          BADPV         
ACK 08:03:20     21FC512          BADPV         
 
PAGE 003            PROCESS ALARM JOURNAL       
------------------------------------------------
RTN 09:16:13     21FI004          PVHH          
RTN 09:16:56     21AI402A         PVLO          
RTN 09:18:22     21FI004          PVHI          
ALM 09:20:03     21TI1123         PVHI          
ACK 09:22:01     21TI1123         PVHI          
 
PAGE 004            PROCESS ALARM JOURNAL       
------------------------------------------------
ACK 11:13:54     21FI004          PVHI          
ALM 11:14:54     21FI004          PVHH          
ALM 11:15:13     21FI004          BADPV         
ACK 11:15:26     21FI004          PVHH          
ACK 11:15:32     21FI004          BADPV 

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Dec 02, 2009 2:01 am

Again, looks like a job for RegEx

Find any line NOT formatted as ^[A-Z]{3} [0-2].*\n and replace it with nothing. The result should be just the lines with the data, all the other lines should be gone.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Dec 02, 2009 3:15 am

Yep, that should do it.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Dec 02, 2009 6:29 am

Here is a RegEx solution.

I copied the sample text you provided into C:\Temp\Temp.txt to load the Haystack.

The syntax for something NOT IN THE LINE is: ^((?!regexp).)*$
So I had to get the "regexp" value first. The following script does that.

Code: Select all

Let>vNeedle=(?m)^[A-Z]{3}%space%[0-2].*?$
// Let>vHaystack=
ReadFile>C:\temp\temp.txt,vHaystack
Let>vReplacement=
RegEx>%vNeedle%,%vHaystack%,0,vMatch,vMatchCount,0,%vReplacement%,vNewString
MessageModal>Matching line count is %vMatchCount%
This results in a count of 29 lines that match the format you want. Each of the lines is now a variable named vMatch_1 through vMatch_29. You could now use the vMatchCount in a loop to write each of the matching lines into a new file or concatenate a variable and you will be all done.
--------------------------------
Or you could do a RegEx Replacement per my original suggestion.

No time to do it now, but you should be able to use the needle in the code above in a new needle using the NOT IN THE LINE syntax ^((?!regexp).)*$, replacing "regexp" with the original needle.

It will need some modification to handle the ^ and the $. The vReplacement could probably be blank, replacing each of the NON matching lines with nothing.

----------------
I always use the same structure for my Regex code. Only have to change 4 simple areas that are bolded.
Let>vNeedle=my search pattern goes here
//Let>vHaystack=my simple test search source goes here
...... OR
ReadFile>C:\temp\temp.txt,vHaystack
Let>vReplacement=my replacement pattern goes here
RegEx>%vNeedle%,%vHaystack%,0,vMatch,vMatchCount,0,%vReplacement%,vNewString
MessageModal>Matching line count is %vMatchCount%

I define what I am looking to match as the Needle
I define the text I am searching through as the Haystack. Usually use a short string for simple strings, OR a temp text file for longer, final sources.
There is a line there for vReplacement that could be commented out, but since the value in the RegEx expression is "0" it does not really matter. I can activate it by simply changing the 0 to a 1.
Then I run the RegEx line, only needing to change the Replacement value as noted above, the other values are all variables and need no change.
Finally, for test purposes I show a count of the matches, and usually have the Watch List open so I can see each of the matching values.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

zerp
Newbie
Posts: 5
Joined: Mon Nov 30, 2009 10:24 pm

Post by zerp » Wed Dec 02, 2009 9:51 pm

Thanks a lot!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts