Here's the vb code with remarks added to explain how it works. You can paste this into vb as the ' character is interpreted as a remark.
Public Sub trimTS()
' Dimension array variable junk to hold 3 bytes
Dim junk(3) As Byte
' Dim array variable a to hold 187 bytes
DIM a(187) As Byte
' Dim Single Byte Constant as 47Hex
Const sync_byte As Byte = &H47
' note this declares variable fni and fno out as a variant will work but Dim fni as string, fno as string is more efficient
Dim fni, fno
' Explicitely define source file path and name
fni = "H:\" + "Test from Nick.ts"
' Explicitely define destination file path and name
fno = "H:\" + "fixedNick.ts"
' open source file to read byte by byte as file 1
Open fni For Binary Access Read As #1
' open destination file to write byte by byte as file 2
Open fno For Binary Access Write As #2
' read first 3 bytes from source file
Get #1, , junk
' read next 187 bytes from source file
Get #1, , a
' continue until first byte in 187 byte block is not 47Hex
While a(0) = sync_byte
' write 187 byte block to output file
Put #2, , a
' read next 3 bytes from source
Get #1, , junk
' read next 187 bytes from source
Get #1, , a
' loop back to while statement
Wend
' close both source and destination files
Close
End Sub
If you stay in the vb editor with the cursor in the sub () line and press f8 you can single step through the code as it runs. Hovering the cursor over a variable name will reveal it's current value. If you open an immediate window you can execute a vb command eg Print fno
Public Sub trimTS()
' Dimension array variable junk to hold 3 bytes
Dim junk(3) As Byte
' Dim array variable a to hold 187 bytes
DIM a(187) As Byte
' Dim Single Byte Constant as 47Hex
Const sync_byte As Byte = &H47
' note this declares variable fni and fno out as a variant will work but Dim fni as string, fno as string is more efficient
Dim fni, fno
' Explicitely define source file path and name
fni = "H:\" + "Test from Nick.ts"
' Explicitely define destination file path and name
fno = "H:\" + "fixedNick.ts"
' open source file to read byte by byte as file 1
Open fni For Binary Access Read As #1
' open destination file to write byte by byte as file 2
Open fno For Binary Access Write As #2
' read first 3 bytes from source file
Get #1, , junk
' read next 187 bytes from source file
Get #1, , a
' continue until first byte in 187 byte block is not 47Hex
While a(0) = sync_byte
' write 187 byte block to output file
Put #2, , a
' read next 3 bytes from source
Get #1, , junk
' read next 187 bytes from source
Get #1, , a
' loop back to while statement
Wend
' close both source and destination files
Close
End Sub
If you stay in the vb editor with the cursor in the sub () line and press f8 you can single step through the code as it runs. Hovering the cursor over a variable name will reveal it's current value. If you open an immediate window you can execute a vb command eg Print fno






”