[futurebasic] Re: [FB] Importing lots of text

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: "Michael Evans" <mikonic@...>
Date: Sun, 03 Oct 1999 14:00:39 -0400
This how I would do it in a PG:pro environment...

Code not tested....

CLEAR LOCAL
LOCAL FN fileToSTRarray%(aFileName, aWDrefNum%, theSTRID%)
  DIM fileSize&, fileHandle&, err%, dontCare%,
  DIM chunk255Count%, lastChunkSize&, temp$, count%, offset&
  err% = _noErr

  LONG IF FN fileExists(aFileName,aWDrefNum%)

    ' blank the STR# numbered theSTRID%
    FN newStr(theSTRID%,"")
    FN delElement(1,theSTRID%)

    ' read the file into a handle
    OPEN "I",1,filename$,1,aWDrefNum%
    fileSize& = LOF(1,1)
    LONG IF fileSize& > 0
      fileHandle& = FN NEWHANDLE(fileSize&)
    XELSE
      err% = _ztrue
    END IF
    CLOSE #1

    ' create a new handle for DEF APNDSTR
    resHndl& = FN NEWHANDLE _clear(2)

    LONG IF (fileHandle& <> 0) AND (resHndl& <> 0)
      dontCare% = FN HLOCK(fileHandle&)

      READ FILE #1, [fileHandle&], fileSize&

      chunk255Count% = (fileSize&/255)            'number of chunks
containing 255 chars
      lastChunkSize& = fileSize& MOD 255          'left over chunk
      offset&        = [fileHandle&] -255         'makes the read loop
tidier when

      LONG IF chunk255Count%
        FOR count% = 1 TO chunk255Count%
          temp$ = ""
          offset& = offset& + 255
          POKE @temp$, 255
          BLOCKMOVE offset&, (@temp$ + 1), 255
          DEF APNDSTR(temp$,resHndl&)
        NEXT count%
      END IF

      LONG IF lastChunkSize%
        offset& = offset& + 255
        POKE @temp$, lastChunkSize%
        BLOCKMOVE offset&, (@temp$ + 1), lastChunkSize&'lastChunkSize& MUST
be a Long&
        DEF APNDSTR(temp$,resHndl&)
      END IF



      FN pGreplaceRes(resHndl&,_"STR#",theSTRID%,"")
      'resHndl& no longer valid after pGreplaceRes...
      resHndl& = 0

      dontCare% = FN HUNLOCK(fileHandle&)
      DEF DISPOSEH(fileHandle&)
    XELSE
      err% = _ztrue
    END IF


  XELSE
    err% = _ztrue
  END IF



END FN = err%

call FN fileToSTRarray% like this:

DIM deepDooDoo%, filename$, myWDrefNum%

filename$ = FILES$(_fOpen, "TEXT",,myWDrefNum%)
LONG IF LEN(filename$)
  deepDooDoo% = FN fileToSTRarray%(filename$, myWDrefNum%, 128)
  LONG IF deepDooDoo% = _noErr
    'FN fileToSTRarray% suceeded, your strings are STR# 128
  XELSE
    'FN fileToSTRarray% failed
  END IF

END IF

Cheers,


----------------------------------------------------------
Michael Evans
Manager of Software Development * Photo Systems, Inc.
3301 Wood Valley Road, NW * Atlanta, GA, 30327-1515
Voice: (404) 846-9386
Fax: (404) 240-0878 * Cell: (404) 229-3930
E-mail: evans@... * michael_evans@...
----------------------------------------------------------