' Rapid-Q by William Yu (c)1999-2000 . ' ================================================================================ ' Upload_il_tuo_script_su_Rapidq.it ' Qfilestream ****** QFILESTREAM Component ****** QFilestream is Rapid-Q's way of handling files. It's more elegant than the GET, and PUT method of traditional BASIC. QFilestream Properties Field Type R/W Default Support =============== =============== =============== =============== =============== EOF INTEGER R WXG EOF specifies whether the file pointer has reached the end of file. Handle INTEGER R W LineCount INTEGER R WXG LineCount determines how many lines there are in the file. Note that LineCount ignores the CR character, and will only detect LF, so it treats CRLF as one line, but LFLF as 2 lines. Position INTEGER RW WXG Position specifies the current position of the file pointer, any read/write operations will begin from here. Size INTEGER R WXG Size determines the size of the file in bytes. QFilestream Methods Method Type Description Params Support ============== ================= ============== =============== =============== Close SUB Close the 0 WXG stream CopyFrom SUB (Stream, Copy from 2 W Bytes%) another stream Either QFileStream or QMemoryStream If Bytes%=0 then the whole stream is copied Use CopyFrom to copy a QFILESTREAM or a QMEMORYSTREAM to the current filestream. Details: If Bytes% = 0 then the Stream is reset to position 0 and the whole stream is then copied. Example: $INCLUDE "RAPIDQ.INC" DIM File1 AS QFILESTREAM DIM File2 AS QFILESTREAM File1.Open("test.txt", fmCreate) File2.Open("oldtest.txt", fmOpenRead) File1.CopyFrom(File2, 123) '-- Copy 123 bytes from File2 ExtractRes SUB (Resource AS Extract 1 WXG LONG) resource to filestream Extracts a resource from your program to the filestream. Details: The parameter Resource is not the resource handle, but the absolute position of the resource within your file. This requires that you use the keyword Resource(n) to specify the resource number. Example_(dumping_all_resources): $INCLUDE "RAPIDQ.INC" $RESOURCE res_1 as "res.1" $RESOURCE res_2 as "res.2" DIM File1 AS QFILESTREAM File1.Open("test.txt", fmCreate) FOR I = 0 TO ResourceCount-1 File1.ExtractRes(Resource(I)) NEXT LoadArray SUB (Array(), Load data into 2 WXG NumElements&) array Open SUB (FileName$, Open a file, 2 WXG Method%) Method% see RAPIDQ.INC Read SUB (variable) Generic Read, 1 WXG determines the storage space and saves data in variable Datasize is automatically determined, and the value is stored into the variable. Example: $INCLUDE "RAPIDQ.INC" DIM File1 AS QFILESTREAM DIM B AS BYTE, I AS INTEGER File1.Open("test.txt", fmOpenRead) File1.Read(B) '-- Read a byte File1.Read(I) '-- Read an integer ReadLine FUNCTION () AS Reads an 0 WXG STRING entire line, supports UNIX files ReadNum FUNCTION (n) AS Read n bytes, 1 WXG DOUBLE returns number ReadBinStr FUNCTION (n) AS Read n bytes, 1 WXG STRING returns the binary string ReadStr FUNCTION (n) AS Read n bytes, 1 WXG STRING returns the text string ReadUDT SUB (MyType) Read and store 1 WXG data in a MyType structure SaveArray SUB (Array(), Save array 2 WXG NumElements&) Seek SUB (Position%, Seek to 2 WXG From%) Position%, From% see RAPIDQ.INC Write SUB (variable) Generic Write, 1 WXG determines the storage space and saves data to file WriteLine SUB (S AS STRING) Writes string 1 WXG with CR+LF WriteNum SUB (number, Writes a 2 WXG bytes%) number to file WriteBinStr SUB (string, Writes a 2 WXG bytes%) binary string to file WriteStr SUB (string, Writes a text 2 WXG bytes%) string to file (fast) WriteUDT SUB (MyType) Write data 1 WXG stored in a MyType structure QFileStream Examples $INCLUDE "RAPIDQ.INC" DIM File AS QFileStream File.Open("test.bas", fmOpenRead) S$ = File.ReadStr(File.Size) '' Read entire file PRINT S$ '' print it File.Close '------------------------------------------------------ $INCLUDE "RAPIDQ.INC" TYPE MyType Name AS STRING*30 Phone AS STRING*8 Age AS INTEGER END TYPE DIM Person AS MyType Person.Name = "Joe" Person.Phone = "555-5555" DIM File AS QFileStream File.Open("test", fmCreate) File.WriteUDT(Person) ' =============================================================================== ' 2003 Holyguard.net - 2007_Abruzzoweb