You can use regexpr. It's pretty powerful and quite fast.
FUNCTION PBMAIN () AS LONG
GetSerials("Cons1.TXT")
End Function
Sub Getserials(FileSpec as string)
Local Str As String
Local SerNo As String
Local iPos, iLen As Long
Open FileSpec For Binary As 1 'Open in binary mode
Get$ #1, Lof(1),Str 'Read it all
Close 1
Do
RegExpr "[0-9A-F]* TO" In Str At iPos + iLen To iPos , iLen 'Note: Your example showed each SerNo in duplicate because the
SerNo += Mid$(Str, iPos, iLen - 3) & $CrLf ' form had SerNo TO SerNo and in each case they were the same.
Loop Until iLen = 0 ' I'm only grabing the one before the TO but still not checking
' for duplicates
MsgBox SerNo 'List them
End Sub
By the way, the regular expression in my example looks for any contiguous characters (of any size) containing digits (0-9) or upper-case letters (A-F) followed by ' TO'. Your sample file works with this regular expression, but you may find situations that it would need to modified. It would match 'B TO' in 'TAB TO COL 10' for instance.
David