News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Seek, Loc and Lof

Started by jj2007, January 14, 2011, 11:41:32 AM

Previous topic - Next topic

jj2007

The PB site says Use the SEEK function to determine a binary file's current pointer position, and LOF to determine its length, and they discourage Loc as obsolete.

First, I don't get how one should use Seek to get the pointer without moving it; and second, what's wrong with Loc?
The next update of MasmBasic will have Loc (as shown below), but I am curious to know why PB doesn't like it...

Quote   Open "O", #1, "TestShort.txt"      ; open file for output
   Print #1, "This is a pretty long string"
   Close
   Open "U", #1, "TestShort.txt"      ; open file for updating
   Print Str$("The file has %i bytes\n", Lof(#1))
   
Seek #1, 17         ; move file pointer on long
   Print Str$("The file pointer is now at byte %i\n", Loc(#1))
   Print #1, "short string"      ; result: This is a pretty short string
   Print Str$("Now the file has %i bytes\n", Lof(#1))
   Close
   Print
"The result: [", FileRead$("TestShort.txt"), "]"

hutch--

JJ,

I think its just a semantic issue as they perform the same function. With SEEK its the difference between a statement and a function, same is done with MID$, even though I have only ever used the function form. To do it in Windows it probably has to be a wrapper for "SetFilePointer()" so its a matter of what you want to provide at the basic user interface.

I personally use API file handling when I want to work on file data using the file pointer.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php