Can you change the format of the file? Because, as is, it's not very 'friendly' for your needs.
There's no way to determine this data, unless you parse the entire file.
You could load the whole file into a single string with one GET, then split it into an array of string (one array per line in the file.) Then, iterate through the array. This would be significantly faster than reading the whole file over and over. If the source file isn't too large (no more than approximately 10% of memory size) then this may be a viable alternative. If the file is larger than this, you can still use this approach, but, you would read/process the source file in chunks, which would take more code.
ex:
Code:
Dim Lines() as string ' dynamic array of string
Dim N as Long
strInLine = Space(LOF(#intInHandle)) ' Size the input buffer
Get #intInHandle, , strInLine
Lines = Split(strInLine, vbNewLine)
strInLine = ""
Close #intInHandle
For N = 0 to UBound(Lines)
debug.print Lines(N)
' Process the lines of the file, now in the Lines array
Next N
Do you have a list of all the possible coupon types? (how many different coupon codes are there?) Or is there a way to determine (programatically) the lines which contain a coupon type? (Your example file data only has three letter coupon types. Is THIS a distinguishing property of the coupon type line?)
In your code, you would need to add a flag to indicate that you've found a matching coupon type. You would set this flag to TRUE. If the flag is true, you need to process the following line(s) you read, as per your code. If one of the following lines contains a different coupon code, you need to reset the flag (set it to false.)
Let's assume that coupon types will always be 4 characters or less in length. To process this, something along the lines of the code below should come close.
Code:
Dim blFound as Boolean
' Use code per above to load the file data into the Lines array
' within the loop,
For N = 0 to UBound(Lines)
If LenB(Lines(N)) > 4
If blFound then
' Output the TCS Coupons
End If
Else
If Lines(N) = "TCS " then
blFound = True
Else
blFound = False
End If
End If
Next N