Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / QFiles / QFiles.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'QFILES.INC by Doctor Electron  Copyright 2002 Global Services
'Last Modified: Dec 20, 2002    Comments to: doctorelectron@cwdom.dm

'These routines were written to allow indexed access (fNum) to files.
'Use GetFileNum Function first to get fNum to be used in all other calls.
'If GetFileNum < 0 then you don't have an available fNum "file handle."

     DECLARE SUB fINITIALIZE
     DECLARE FUNCTION GetFileNum() AS LONG
     DECLARE SUB fOPEN(fNum AS LONG, fName$ AS STRING, fHow AS LONG)
     DECLARE SUB fCLOSE(fNum AS LONG)
     DECLARE SUB fPOSITION(fNum AS LONG, fPosition AS LONG)
     DECLARE SUB fWRITELINE(fNum AS LONG, fString AS STRING)
     DECLARE FUNCTION fSIZE(fNum AS LONG) AS LONG
     DECLARE FUNCTION fREADBINSTR(fNum AS LONG, fBytes AS LONG) AS STRING

     CONST MaxQFiles=8

     DIM qf1 AS QFILESTREAM
     DIM qf2 AS QFILESTREAM
     DIM qf3 AS QFILESTREAM
     DIM qf4 AS QFILESTREAM
     DIM qf5 AS QFILESTREAM
     DIM qf6 AS QFILESTREAM
     DIM qf7 AS QFILESTREAM
     DIM qf8 AS QFILESTREAM
     DIM qfn(1 TO MaxQFiles) AS BYTE  'keeps track of which qfiles are open
     DIM qfi AS LONG

     SUB fINITIALIZE  'call this to initialize at program start
      FOR qfi=1 TO MaxQFiles: qfn(qfi)=0: NEXT qfi
     END SUB

     FUNCTION GetFileNum() AS LONG
      Result=-1
      FOR qfi=1 TO MaxQFiles
       IF qfn(qfi)=0 THEN Result=qfi: EXIT FUNCTION
      NEXT qfi
     END FUNCTION

     SUB fOPEN(fNum AS LONG, fName$ AS STRING, fHow AS LONG)
      qfi=fHow
      IF FILEEXISTS(fName$)=0 THEN qfi=fmcreate
      SELECT CASE fNum
      CASE 1: qf1.OPEN(fName$,qfi)
      CASE 2: qf2.OPEN(fName$,qfi)
      CASE 3: qf3.OPEN(fName$,qfi)
      CASE 4: qf4.OPEN(fName$,qfi)
      CASE 5: qf5.OPEN(fName$,qfi)
      CASE 6: qf6.OPEN(fName$,qfi)
      CASE 7: qf7.OPEN(fName$,qfi)
      CASE 8: qf8.OPEN(fName$,qfi)
      END SELECT
      qfn(fNum)=1
     END SUB

     SUB fCLOSE(fNum AS LONG)
      SELECT CASE fNum
      CASE 1: qf1.CLOSE
      CASE 2: qf2.CLOSE
      CASE 3: qf3.CLOSE
      CASE 4: qf4.CLOSE
      CASE 5: qf5.CLOSE
      CASE 6: qf6.CLOSE
      CASE 7: qf7.CLOSE
      CASE 8: qf8.CLOSE
      END SELECT
      qfn(fNum)=0: DOEVENTS
     END SUB

     SUB fPOSITION(fNum AS LONG, fPosition AS LONG)
      SELECT CASE fNum
      CASE 1: qf1.Position=fPosition
      CASE 2: qf2.Position=fPosition
      CASE 3: qf3.Position=fPosition
      CASE 4: qf4.Position=fPosition
      CASE 5: qf5.Position=fPosition
      CASE 6: qf6.Position=fPosition
      CASE 7: qf7.Position=fPosition
      CASE 8: qf8.Position=fPosition
      END SELECT
     END SUB

     FUNCTION fSIZE(fNum AS LONG) AS LONG
      SELECT CASE fNum
      CASE 1: Result=qf1.Size
      CASE 2: Result=qf2.Size
      CASE 3: Result=qf3.Size
      CASE 4: Result=qf4.Size
      CASE 5: Result=qf5.Size
      CASE 6: Result=qf6.Size
      CASE 7: Result=qf7.Size
      CASE 8: Result=qf8.Size
      END SELECT
     END FUNCTION

     FUNCTION fReadBinStr(fNum AS LONG, fBytes AS LONG) AS STRING
      SELECT CASE fNum
      CASE 1: Result=qf1.ReadBinStr(fBytes)
      CASE 2: Result=qf2.ReadBinStr(fBytes)
      CASE 3: Result=qf3.ReadBinStr(fBytes)
      CASE 4: Result=qf4.ReadBinStr(fBytes)
      CASE 5: Result=qf5.ReadBinStr(fBytes)
      CASE 6: Result=qf6.ReadBinStr(fBytes)
      CASE 7: Result=qf7.ReadBinStr(fBytes)
      CASE 8: Result=qf8.ReadBinStr(fBytes)
      END SELECT
      DOEVENTS
     END FUNCTION

     SUB fWriteLine(fNum AS LONG, fString AS STRING)
      SELECT CASE fNum
      CASE 1: qf1.WriteLine(fString)
      CASE 2: qf2.WriteLine(fString)
      CASE 3: qf3.WriteLine(fString)
      CASE 4: qf4.WriteLine(fString)
      CASE 5: qf5.WriteLine(fString)
      CASE 6: qf6.WriteLine(fString)
      CASE 7: qf7.WriteLine(fString)
      CASE 8: qf8.WriteLine(fString)
      END SELECT
      DOEVENTS
     END SUB

'Add other QFileStream properties and methods here as you need them.
'These routines look ugly, but are a workaround to access files by index.
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2024-10-7  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-12-20 10:02:36