Oxygen Basic
Programming => Problems & Solutions => Topic started by: Karen Zibowski on February 28, 2018, 08:26:24 AM
-
Hi
I'm trying to convert a PowerBasic program to an Oxygen
but encounter problems such as
1. Equivalent of ISFILE function in Oxygen which checks whether a file exist or not
2. Equivalent of FREEFILE in Oxygen , when you need to open a file channel
3. How to open a file in binary mode
The following is my code which cannot be compiled
' Read_Filestr.o2bas
$ filename "Read_Filestr.exe"
use rtl64
'===================================
FUNCTION readFileStr(gfnam AS STRING) AS STRING
' reads in the entire file as a string
Long ff
string bst
' IF ISFALSE ISFILE(gfnam) THEN
' File not found error -- we return a null string
' FUNCTION = ""
' EXIT FUNCTION
' END IF
ff = 3 'FREEFILE
OPEN gfnam FOR BINARY AS #ff
GET$ #ff, LOF(ff), bst
CLOSE #ff
FUNCTION = bst
END FUNCTION
'===========================================
' Start of main
string filnam , wfilstr
filnam = "co2.exe"
wfilstr = readFileStr(filnam)
print " wanted file string : " + $CRLF + wfilstr
Regards
Karen
-
Channelled File i/o is something we need to develop for PB compatibility. But where the files are not huge, and LAN file transactions are not required, I would recommend using our core GetFile and PutFile. they work directly with strings, binary content or otherwise.
string s=GetFile "MyfileA.bin"
PutFile s,"MyFileB.bin"
If the file does not exist, your string will be empty.
-
Many thanks Charles, I have modified my program to
' Read_Filestr.o2bas
$ filename "Read_Filestr.exe"
use rtl64
'===================================
FUNCTION readFileStr(gfnam AS STRING) AS STRING
' reads in the entire file as a string
Long ff
string bst
' IF ISFALSE ISFILE(gfnam) THEN
' File not found error -- we return a null string
' FUNCTION = ""
' EXIT FUNCTION
' END IF
' ff = 3 'FREEFILE
' OPEN gfnam FOR BINARY AS #ff
' GET$ #ff, LOF(ff), bst
' CLOSE #ff
bst = GetFile gfnam
FUNCTION = bst
END FUNCTION
'===========================================
' Start of main
string filnam
string wfilstr
filnam = "C:\oxygenBasic Compiler\bmt.dll"
wfilstr = readFileStr(filnam)
print " wanted file string : " + wfilstr
print " length of file string : " + str$(len(wfilstr))
Kindly check if I'm doing it right
One more thing what is oxygen equivalent to PowerBasic $CRLF ( carriage feed character)
I was not able to write the code as
print " wanted file string : " + $CRLF + wfilstr
-
Yes, that looks fine Karen, and it worked on my system (with a different file)
to make your own crlf equate:
$ crlf chr(13,10)
'same as:
% crlf chr(13,10)
once defined, it is referred to as crlf, dollars prefixes are not used
-
Thanks Charles