Author Topic: File IO  (Read 5050 times)

0 Members and 2 Guests are viewing this topic.

Patrice Terrier

  • Guest
Re: File IO
« Reply #15 on: March 14, 2018, 02:14:13 PM »
FOpen the basic version keyword was first introduced by Ethan Winer (Crescent Software) in 1991.
It was modeled closely onto C, and since that time i have always used it, even in PB and now in C++
same for FPut, FGet, FClose, etc.
I found this syntax much easier than the verbose PB's 
OPEN "text.txt" FOR INPUT As FP1

;)


Charles Pegge

  • Guest
Re: File IO
« Reply #16 on: March 15, 2018, 05:28:33 AM »

One of the flaws in Basic has been to conflate verbosity with user-friendliness. If we can trim off these embellishments and,  instead use regular syntax, Basic will be a fitter language :)

JRS

  • Guest
Re: File IO
« Reply #17 on: March 15, 2018, 08:00:05 PM »
Great to see you back on the OxygenBasic forum again Patrice!

Quote
I found this syntax much easier than the verbose PB's
OPEN "text.txt" FOR INPUT As FP1

It doesn't get much simpler than this.

Code: Script BASIC
  1. filestr = LoadString("text.txt")
  2.  
« Last Edit: March 15, 2018, 08:08:24 PM by John »

Patrice Terrier

  • Guest
Re: File IO
« Reply #18 on: March 15, 2018, 11:22:15 PM »
My point is, as long as there is an existing API, why not using the same name than the original, there is no need to re-invent the wheel or using a convoluted syntax to encapsulate the core function.

FOpen has been there for me, since the PDS time...

Mike Lobanovsky

  • Guest
Re: File IO
« Reply #19 on: March 16, 2018, 12:46:40 AM »
Patrice,

LoadString() is an existing API. It comes OOTB right from Windows SDK rather than C/C++ RTL. :)

Patrice Terrier

  • Guest
Re: File IO
« Reply #20 on: March 16, 2018, 05:00:39 AM »
LoadString and FOpen are two distincts animals that do not serve the same purpose.

JRS

  • Guest
Re: File IO
« Reply #21 on: March 16, 2018, 05:06:20 AM »
True but we were discussing verbose.

Charles Pegge

  • Guest
Re: File IO
« Reply #22 on: March 16, 2018, 06:32:01 AM »
Loading and saving whole files are essentially 3-step processes, but I think it's still useful to have them as one-liners, since this will meet the majority of file i/o needs.

Code: [Select]
uses corewin

function LoadFile(string name, any*data, int e)
===============================================
sys f
f=fopen name,"r"    'open for reading
e=fread @data,1,e,f 'load data
fclose f            'close file
return e
end function


function SaveFile(string name, any*data, int e)
===============================================
sys f
f=fopen name,"w"      'open for writing
e=fwrite @data,1,e,f  'save data
fclose f              'close file
return e
end function

'TEST
=====
float v[100],w[100]
for i=1 to 100 : v[i]=i*1.5 : next
SaveFile "t.bin",v,bytesof v
LoadFile "t.bin",w,bytesof v
print w[51] '76.5