Offset beyond Binary EOD Error
Keywords: 3327 Error Offset beyond Binary EOD Error
Question:
ok I am trying to use the binary operations as reccomended on the board which look like an excellent way to do this :) Only problem is, I'm receiving an error when trying it. I haven't used binary operations before so it's quite possible I'm doing something wrong here. Here's the code:iptest = FileOpen("C:\TEMP\mergedlog.txt", "READ") time = FileOpen("C:\TEMP\time.txt", "WRITE") file = FileOpen("C:\TEMP\ipconfig.txt", "WRITE") FileClose(file) mergedlogsize = FileSize("C:\TEMP\mergedlog.txt") binarybuffer = BinaryAlloc(mergedlogsize / 5) BinaryRead(binarybuffer, "C:\temp\ipconfig.txt" ) FileWrite(time, TimeDate()) x= BinaryEodGet(binarybuffer) BinaryEodSet(binarybuffer, x + 1) thefirsttime = @TRUE While @TRUE textline = FileRead(iptest) If textline == "*EOF*" Then Break testip = ItemExtract(3, textline, " ") temp = StrCat(testip, @CRLF) If BinaryStrCnt(binarybuffer, 0, x - 1, temp) == 0 Then BinaryPokeStr(binarybuffer, x, temp) EndWhile FileWrite(time, TimeDate()) FileClose(time) FileClose(iptest) BinaryWrite(binarybuffer, "C:\TEMP\ipconfig.txt") BinaryFree(binarybuffer)testip is retrieved from a file and is just a run of the mill IP address. The error I get is on the If statement saying 3327 Error: Offset beyond binary EOD. This is on the first iteration of this code.One other thing is that it's adding a space to the first piece of data in the output file. Any ideas on how to get rid of this?
Answer:
- I think this line is causing the problem...
x=BinaryEodGet(binarybuffer) BinaryEodSet(binarybuffer, x + 1)delete it. It's bumping the EOD point past the end of valid data. The problem will show up in the first line of added data.- BinaryStrCnt, third parameter, is an offset, not a count. BinaryEODGet returns a count. Subtract 1 to get an offset.
- Leading space? Probably picking it up with a BinaryPeekStr. Add one to offset value. Subtract 1 from count.
- Revised code snippet:
x= BinaryEodGet(binarybuffer) If x > 0 If BinaryStrCnt(binarybuffer, 0, x-1, temp) == 0 Then BinaryPokeStr(binarybuffer, x, temp) Else BinaryPokeStr(binarybuffer, x, temp) EndIf
Article ID: W14826