View Full Version : using file_load?
sandyrepope
17-07-2007, 19:35
I'm trying to use file_load and when my script does it returns 'nothing'. I sure would like to know what I'm doing wrong. Here is what I am using.
uses "file"
dim load_it as string
dim sFile as long
dim fHandle as long
dim Load_Note as string
load_it = Dir_getcurrent + "testing.txt"
msgbox 0, load_it
sFile = file_exists(load_it)
If sFile = %true then
fHandle = file_open( load_it, "input")
Load_Note = file_load(fHandle)
msgbox 0, Load_Note
file_close(fHandle)
end if
I've tried using file_lineinput instead and it works just fine. It's just file_load that doesn't seem to work.
Thanks
Sandy
ErosOlmi
17-07-2007, 20:46
Hi Sandy.
FILE_LOAD (http://www.thinbasic.com/public/products/thinBasic/help/html/file_load.htm) needs a file name as input parameter. All the open, load and close operations are done internally by the function.
So your script can be something like:
uses "file"
dim load_it as string
dim Load_Note as string
load_it = Dir_getcurrent + "testing.txt"
msgbox 0, load_it
If file_exists(load_it) = %true then
Load_Note = file_load(load_it)
msgbox 0, Load_Note
end if
Ciao
Eros
sandyrepope
18-07-2007, 03:06
Thank You for the explanation. I had a strong feeling that I wasn't understanding something but I didn't know what. This makes it very clear to me.
Thanks
Sandy
ErosOlmi
18-07-2007, 07:15
Good, Sandy.
FILE_LOAD has a lot of power. It has the capacity to load from a single byte file to multi megabytes files in one go. Text files or bynary files, whatever. The full file content will be placed into the return string in a snap.
For example the following few lines of code will load a comma separated CSV file in one single line using the power of FILE_LOAD and PARSE functions together regardless the number of lines or columns will be present in CSV file.
USES "FILE"
...
dim FileToLoad as string value app_sourcepath & "CSV_SampleData.csv" '---Indicate your CSV file here
dim MyMatrix() as string
dim nLines as long
dim nCols as long
'---
'---Just one line do the job of loading file data, parsing text lines, dimensioning and filling the matrix.
'------
PARSE(FILE_Load(FileToLoad), MyMatrix(), $crlf , ",")
'--Now get the number of lines and max number of columns parsed
nLines = ubound(MyMatrix(1))
nCols = ubound(MyMatrix(2))
...
Ciao
Eros