Page 1 of 1

File commands extended

Posted: Wed Jun 08, 2005 9:11 pm
by TerryHough
I would like to suggest that the File commands be extended to use a
#File parameter, such as

Code: Select all

WriteData(#File, *MemoryBuffer, LengthToWrite)
which would replace

Code: Select all

UseFile(#File)
WriteData(*MemoryBuffer, LengthToWrite)
This is a lot more intuitive, I believe. Now it is too easy to forget that the
"current file" has changed and that leads to bugs. Spent most of the
morning tracking down that exact situation.

I realize this change would break existing code, but perhaps this could
be included in the upcoming Vs 4.0.

Many of the File commands need this change. This change would
  • make them consistent with the ones that already require the #File parameter
    deprecate the need for the UseFile(#File) command
I find that

Code: Select all

; psuedo code
OpenFile(10,"Example.txt")
OpenFile(20,"Insert.txt")
OpenFile(30,"Rewrite.txt")
While Eof(10) = 0
  Text$ = ReadString(10)
  ; manipulate the data to your heart's content
  WriteStringN(30,Text$)
  Text$ = ReadString(20)
  ; manipulate the data to your heart's content
  WriteStringN(30,Text$)
Wend 
CloseFile(10)
CloseFile(20)
CloseFile(30)
is more consistent and easier for me to understand than

Code: Select all

; psuedo code
OpenFile(10,"Example.txt")
OpenFile(20,"Insert.txt")
OpenFile(30,"Rewrite.txt")
While Eof(10) = 0
  UseFile(10)
  Text$ = ReadString()
  ; manipulate the data to your heart's content
  UseFile(30)
  WriteStringN(Text$)
  UseFile(20)
  Text$ = ReadString()
  ; manipulate the data to your heart's content
  UseFile(30)
  WriteStringN(Text$)
Wend 
CloseFile(10)
CloseFile(20)
CloseFile(30)
especially when the manipulation portions of the code are many lines
and/or procedures separated.

Thanks,
Terry

Posted: Wed Jun 08, 2005 9:13 pm
by Polo
I agree.

Posted: Wed Jun 08, 2005 11:21 pm
by dell_jockey
so do I.

Posted: Wed Jun 08, 2005 11:56 pm
by Dare2
Would be nice. And needn't break old code.
  • WriteData( [#file,] *MemoryBuffer, LengthToWrite)

Code: Select all

WriteData(*MemoryBuffer, LengthToWrite)   ; -- use last active file ID.
WriteData(#File, *MemoryBuffer, LengthToWrite)
works for all file operations (except usefile(#File)). :)

Posted: Thu Jun 09, 2005 7:07 am
by Bonne_den_kule
I agree. Then it will be thread safe

Posted: Mon Jun 13, 2005 2:00 pm
by Dummy
Dare2 wrote:WriteData(*MemoryBuffer, LengthToWrite) ; -- use last active file ID.
Better:

use last ID set by UseFile(#File)