There is no need to send the starting position of
PT to the routine. The whole point was to make the code generic. The code found
PT in the data file you posted at offset 64 in all the records that contained it.
The
:getLoc routine processes records that have
GOTO in the first four bytes. By starting at offset 0 (record position 1), it increases the record position by 1, reading 2 byte chunks of the record until
PT is found or offset 67 is reached, whichever comes first. The 67 was arbitrary. Once the offset of
PT is found (stored in the %%i token), the code uses truncation to eliminate the high order bytes. The logic is fairly simple, it was the batch notation that was challenging.
The
FOR /L %variable IN (start,step,end) DO statement uses the "end" parameter as the indicator when to stop the loop. In this case it represents the highest offset to check before quitting the loop. You can exceed the record length without the code throwing an error. Ensure the "end" parameter is large enough to include the entire record without being so large as to needlessly waste CPU cycles.
The code can probably be tweaked for more efficiency. For instance, the search for
PT could start at offset 4; we already know offsets 0-3 contains
GOTOHope this helps.