1.bas(10) error 28: Expected pointer, before ',' in 'If Not EOF(FF) Then Get FF, , rByte 'reading'
1.bas(11) error 28: Expected pointer, before ',' in 'If Not EOF(FF) Then Get FF, , Junk 'not used bytes'
Function FindOffset(ByVal wFile As String, ByVal wMarker As String) As Long
Dim As Long FF
Dim As Byte rByte
Dim As Byte Junk
Dim As String CmpStr
FF = FreeFile
Open wFile For Binary As FF
Do Until EOF(FF)
If Not EOF(FF) Then Get FF, , rByte
If Not EOF(FF) Then Get FF, , Junk
If Len(CmpStr) < Len(wMarker) Then
CmpStr = CmpStr + Chr(rByte)
Else
CmpStr = Mid(CmpStr, 2) + Chr(rByte)
End If
If CmpStr = wMarker Then
FindOffset = Loc(FF) + 1
Exit Do
End If
Loop
Close #1
Exit Function
End Function
Function FindOffset(ByVal wFile As String, ByVal wMarker As String) As Long
Dim As Long FF
Dim As Byte rByte
Dim As Byte Junk
Dim As String CmpStr
FF = FreeFile
Open wFile For Binary As FF
Do Until EOF(FF)
If Not EOF(FF) Then Get #FF, , rByte '' <-- Here
If Not EOF(FF) Then Get #FF, , Junk '' <-- and here
If Len(CmpStr) < Len(wMarker) Then
CmpStr = CmpStr + Chr(rByte)
Else
CmpStr = Mid(CmpStr, 2) + Chr(rByte)
End If
If CmpStr = wMarker Then
FindOffset = Loc(FF) + 1
Exit Do
End If
Loop
Close #1
Exit Function
End Function
Function FindOffset(ByVal wFile As String, ByVal wMarker As String) As Long
Dim As Long FF
Dim As Byte rByte
Dim As Byte Junk
Dim As String CmpStr
FF = FreeFile
Open wFile For Binary As FF
Do Until EOF(FF)
If Not EOF(FF) Then Get #FF, , rByte '' <-- Here
If Not EOF(FF) Then Get #FF, , Junk '' <-- and here
If Len(CmpStr) < Len(wMarker) Then
CmpStr = CmpStr + Chr(rByte)
Else
CmpStr = Mid(CmpStr, 2) + Chr(rByte)
End If
If CmpStr = wMarker Then
FindOffset = Loc(FF) + 1
Exit Do
End If
Loop
Close #1
Exit Function
End Function
Unfortunately, FreeBASIC is a bit inconsistent here. The # to mark a file handle is sometimes optional as with the Open and Close statement, but it is not with the Get and Put statement, or the Line Input statement. Worse, EOF does not accept the #.
No probl. A heads up: close #1 should be close #FF. Otherwise you'll have some really hard to track bugs if you intend to use this function elsewhere where files are also handled.
Function FindOffset(ByVal wFile As String, ByVal wMarker As String) As Long
Dim As Long FF
Dim As Byte rByte
Dim As Byte Junk
Dim As String CmpStr
FF = FreeFile
Open wFile For Binary As FF
Do Until EOF(FF)
If Not EOF(FF) Then Get #FF, , rByte '' <-- Here
If Not EOF(FF) Then Get #FF, , Junk '' <-- and here
If Len(CmpStr) < Len(wMarker) Then
CmpStr = CmpStr + Chr(rByte)
Else
CmpStr = Mid(CmpStr, 2) + Chr(rByte)
End If
If CmpStr = wMarker Then
FindOffset = Loc(FF) + 1
Exit Do
End If
Loop
Close #1
Exit Function
End Function
I use it with such a function, but it spoils files, how can I fix it?
Function WriteToFile(ByVal wFile As String, ByVal wValue As String, ByVal wMarker As String) As Boolean
Dim As Long S
Dim As Byte i
Dim As Byte bVal
S = FindOffset(wFile, wMarker)
wValue = wValue + "<END>"
Open wFile For Binary As #1
For i = 1 To Len(wValue)
bVal = Asc(Mid(wValue, i, 1))
Put #1, S + (i - 1) * 2, bVal
Next i
Close #1
Return True
Exit Function
Return False
End Function