The MASM Forum Archive 2004 to 2012

Project Support Forums => PowerBASIC Low Level Code => Topic started by: jj2007 on January 14, 2011, 11:41:32 AM

Title: Seek, Loc and Lof
Post by: jj2007 on January 14, 2011, 11:41:32 AM
The PB site (http://www.powerbasic.com/support/help/pbcc/seek_statement.htm) 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 (http://www.powerbasic.com/support/help/pbcc/loc_function.htm).

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"), "]"
Title: Re: Seek, Loc and Lof
Post by: hutch-- on January 14, 2011, 12:08:03 PM
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.