I've got this macro which performs 10 different checks on the metadata of an HTML file. The idea is you point the macro at a drive containing thousands of folders each of which contains a separate HTML file and it works it way through them all performing each of these 10 checks to each html file in turn. The whole macro runs between a Repeat and Until command as it works through each folder.
The complete code is too lengthy to post (over 3000 lines) so just posting a section of it as it's really just variations of this throughout.
Each of the different checks is a separate '1st level' subroutine. Depending on the result of the Subroutine there are then three possible other '2nd level' Subroutines that run.
This is one such combination of a 1st level SRT and a single 2nd level SRT
Code: Select all
//1st Level SRT
SRT>nccFiles
Let>nccFC=0
While>strFCPos<>##EOF##
Label>FindFC
Let>nccFC=nccFC+1
ReadLn>%Path%\ncc.html,%nccFC%,strFCPos
Trim>strFCPos,strFCPos
MidStr>strFCPos,13,9,strFCPosTrim
If>{(%strFCPosTrim%="ncc:files") AND (%nccFCLineCount%=0)}
//When it finds the ncc:files line save the line number as nccFCLine1
Let>nccFCLine1=%nccFC%
//Increment nccFCLineCount to indicate that 1 instance of ncc:files has been found so far
Let>nccFCLineCount=1
//Read the line in the ncc file that has the 1st instance of ncc:files
ReadLn>%Path%\ncc.html,%nccFCLine1%,strFCValue1
LTrim>strFCValue1,strFCValue1
Let>FCpattern=ncc:files.+?content="\K[^"]+
RegEx>FCpattern,strFCValue1,0,FCMatches1,nm1,0
//If nothing had been entered into the metadata set FCMatches1_1 to 0 to identify it needs changing
If>nm1=0
Let>FCMatches1_1=0
Endif
Trim>FCMatches1_1,FCMatches1_1
If>FCMatches1_1=
Let>FCMatches1_1=0
Endif
Goto>FindFC
Endif
If>{(%strFCPosTrim%="ncc:files") AND (%nccFCLineCount%=1)}
//If it finds a 2nd line save the line number as nccFCLine2
Let>nccFCLine2=%nccFC%
//Increment nccFCLineCount to indicate that 2 instances of ncc:files have been found
Let>nccFCLineCount=2
//Read the line in the NCC that has the 2nd instance of ncc:files
ReadLn>%Path%\ncc.html,%nccFCLine2%,strFCValue2
LTrim>strFCValue2,strFCValue2
Let>FCpattern=ncc:files.+?content="\K[^"]+
RegEx>FCpattern,strFCValue2,0,FCMatches2,nm1,0
//If nothing had been entered into the metadata set FCMatches2_1 to 0 to identify it needs changing
If>nm1=0
Let>FCMatches2_1=0
Endif
Trim>FCMatches2_1,FCMatches2_1
If>FCMatches2_1=
Let>FCMatches2_1=0
Endif
Endif
EndWhile
END>nccFiles
//Work out which Level 2 SRT to use
//If the ncc:files line is missing entirely from the metadata
If>nccFCLineCount=0
GoSub>MissingNCCFiles
Endif
//If there is only 1 instance of ncc:files in the metadata
If>nccFCLineCount=1
GoSub>SingleNCCFiles
Endif
//If the ncc:files line appears twice in the metadata
If>nccFCLineCount=2
GoSub>MultipleNCCFiles
Endif
//Level 2 SRT
SRT>MissingNCCFiles
SetFocus>Notepad++*
//Open the GoTo command in Notepad++
Wait>1
Press Ctrl
Send>g
Release Ctrl
WaitWindowOpen>Go To...
Wait>0.2
//Line 25 will always be within the metadata area. It doesn't matter where the ncc:files line
Send>25
Wait>0.2
Press Enter
Wait>1
SetFocus>Notepad++*
Wait>0.5
Press Enter
Wait>0.2
//Add the metadata line with the correct file count value
Send><meta name="ncc:files" content="%strNames_Count%"/>
Let>NCCFileReport=Added Missing ncc:files metadata tag
END>MissingNCCFiles
The whole macro consists of 10 sets of Level 1 and Level 2 SRT's like this.
The macro works fine if I just run a single Level 1 SRT. It works fine whether it's adding a missing tag, correcting an existing or removing and correcting a duplicate.
It also works fine if I run all the Level 1 SRT's as long as none of them had to remove a duplicate. If they do, the line number count goes out of sequence and the macro starts adding/deleting the wrong lines.
For example, lets say that in the html file the metadata line <meta name="ncc:files" content="64"/> appears twice on lines 16 and 17 (but has the wrong value on line 16 - should be 70 and not 64). The next level 1 SRT then needs to make a change to another metadata tag on line 20.
What happens here is that the macro will delete line 17 and correct line 16 to have the content of 70 and not 64. However, the line that was originally on line 20 is now on line 19 but the next Level 1 SRT still tries to correct the tag on line 20.
I would completely understand this if all the level 1 SRT's were running at the same time but I thought I had them running one after the other:
Code: Select all
//Level 1 SRT
GoSub>nccFiles
//Level 2 SRTS
//If the ncc:files line is missing entirely from the metadata
If>nccFCLineCount=0
GoSub>MissingNCCFiles
Endif
//If there is only 1 instance of ncc:files in the metadata
If>nccFCLineCount=1
GoSub>SingleNCCFiles
Endif
//If the ncc:files line appears twice in the metadata
If>nccFCLineCount=2
GoSub>MultipleNCCFiles
Endif
//Level 1 SRT
GoSub>ncckByteSize
//Level 2 SRTS
//If the ncc:kByteSize line is missing entirely from the metadata
If>nccKBLineCount=0
GoSub>MissingncckByteSize
Endif
//If there is only 1 instance of ncc:kByteSize in the metadata
If>nccKBLineCount=1
GoSub>SinglencckByteSize
Endif
//If the ncc:kByteSize line appears twice in the metadata
If>nccKBLineCount=2
GoSub>MultiplencckByteSize
endif
I've also found that after it's checked the first html file in the first folder, when it moves to the second html file it just gets things completely wrong and just runs the various Missing level 2 SRT's even though the relevant tags aren't missing. This is despite the fact at the start of each loop I delete the contents of all the variables that are set in the various Level 1 SRT's so that everything starts afresh again.
I don't know if any of that made any sense whatsoever, but does anyone have any idea why this might be happening?