' Rapid-Q by William Yu (c)1999-2000 . ' ================================================================================ ' Upload_il_tuo_script_su_Rapidq.it ' file_read_write Preface All examples file are writen without include file ,,Rapidq.inc " !!! in this fact we will use internal numeric constants How can i Read data from *.txt file ? How can i Save data to *.txt file ? =========================================================================================== Read_data First simple step which we must to do is ,, dimension " of file data type : Dim file as Qfilestream i think it is easy . Second step is open file ,we should first check if file exist . File.Open("Test.txt", 0) 'open file for reading number ,, 0 '' destiny that file is open for reading or temp=FileExists("Test.txt") ' check if file exist if temp=0 then ' return 0 if file not found , non zero if print " file not found " sleep 3 'wait 3 seconds end if File.Open("Test.txt", 0) 'open file =========================================================================================== And now whe can load a content of file in one string ,it is good when you want to read character by character or in little section . File.ReadStr(num) read n bytes from file a if we use File.Size this give what we want. a$ = File.ReadStr(File.Size) ' Third step is closing file file.close Our program : temp=FileExists("Test.txt") if temp=0 then print " file not found " sleep 3 end if File.Open("Test.txt", 0) a$ = File.ReadStr(File.Size) print a$ file.close And what about if we want read line by line ? Example : Dim file as Qfilestream file.open("test.txt", 0) do getline$=file.readline print getline$ loop until file.eof file.close =========================================================================================== Save_data First step is checking if file exist ,this we must to do ,because we need know in which ,,file mode " (create,write) we will write into file . If file doesnt exist this cause error <> Ways ________________________________________________________________________ |Example_1.|file_exist_______|,,write_mode_"_____________________________| |Example_2.|file_doesnt_exist|we_create_file_and_write_in_,,create_mode_"| |Example_3.|file_doesnt_exist|first_we_create_file_,and_then_write_______| =========================================================================================== example 1 Dim file as Qfilestream a$="hello" file.open(result$,1 ) ' ,,1" = write mode file.writeline("hellllllllllo") file.Write(a$) file.close example 2 Dim file as Qfilestream temp=FileExists("Test.txt") ' check if file exist if temp=0 then ' return 0 if file not found , non zero if file.open(result$,65535 ) ' ,,65535" = create mode file.close end if file.writeline("hellllllllllo") file.close example 3 Dim file as Qfilestream temp=FileExists("Test.txt") ' check if file exist if temp=0 then ' return 0 if file not found , non zero if file.open(result$,65535 ) ' ,,65535" = create mode file.close end if File.Open("Test.txt", 1) ',,1" = write mode file.writeline("hellllllllllo") file.close =========================================================================================== kumbayah ....... Problems Rapid Q IDE create temporary files in his directory (etc. $noname.bas ) ,and run programs from there therefor may be path different . You should use complete path or create program in text editor and then run Rapiq IDE . ' =============================================================================== ' 2003 Holyguard.net - 2007_Abruzzoweb