[futurebasic] Re: [FB] Still need help with Write File

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

From: GBeckman@...
Date: Sun, 19 Sep 1999 11:29:51 EDT
In a message dated 9/19/99 4:28:36 AM, d8171hn1@... writes:

>> I want to write a number of items to the one file
>>
>> 1. load text file1 to hndl&
>> 2. Array data in memory
>> 3. load text file2 to hndl2&
>>
>> What is the best way to write these 3 items back out to the one file?

Here are some routines I use.

LOCAL
DIM  a,counter
DIM TheString$
LOCAL FN MainReadNumber%(myLength,StrHndl&)
  THESTRING$=""
  FOR counter=1 TO myLength
    a=PEEK([StrHndl&]+goffset&)
    INC(gOffSet&)
    THESTRING$=THESTRING$+CHR$(a)
  NEXT counter
END FN=VAL(theString$)


LOCAL
DIM  a,counter
DIM TheString$
LOCAL FN MainReadText$(myLength,StrHndl&)
  THESTRING$=""
  counter=0
  FOR counter=1 TO myLength
    a=PEEK([StrHndl&]+goffset&)
    INC(gOffSet&)
    THESTRING$=THESTRING$+CHR$(a)
  NEXT counter
  DEF TRUNCATE(theString$)
END FN=TheString$


LOCAL
DIM WhatToWrite$

LOCAL FN MainWriteNumber(TheNumber%,StrHndl&,howFar)
  WhatToWrite$=STR$(theNumber%)+SPACE$(5)  
  BLOCKMOVE @whatToWrite$+2,[StrHndl&]+gOffset&,howFar
  gOffSet&=gOffset&+HowFar
END FN

LOCAL

LOCAL FN MainWriteText(TheString$,StrHndl&,howFar)
  TheString$=TheString$+SPACE$(30)                '+"                         
       "
  BLOCKMOVE @theString$+1,[StrHndl&]+gOffset&,howFar
  gOffSet&=gOffset&+howFar
END FN



so you coud read doing this sort of thing:

Remember, here I am also trying to control the exact length, which you may 
not need to do.  gOffSet& is global, and perhaps a bit sloppy, but...


  gOpenType$="TEXT"                               'files to open
  
  gFileName$=""
  FN pGopenFile
  
  LONG IF LEN(gFileName$)
    
    CURSOR _watchCursor
    OPEN "I",#3,gFileName$,,gFileVol
    fileSize&=LOF(3,1)
    
    StrHndl&=FN NEWHANDLE(fileSize&+5)
    
    LONG IF (StrHndl&<>_nil)
      
      osErr%=FN HLOCK(StrHndl&)
      
      READ FILE#3,[StrHndl&],fileSize&
      osErr%=FN HUNLOCK(StrHndl&)
    XELSE
      osErr%=_mFulErr
      FileSize&=0
    END IF
    CLOSE #3
    
    LONG IF FileSize&<>0

'read some vars      


    
        glatePaperValue%=FN MainReadNumber%(2,StrHndl&)
        gPrintEffort=FN MainReadNumber%(1,StrHndl&)
    
'or and array

        FOR Subject=0 TO _ClassMax 
          gEntriesToDate(Subject)=FN MainReadNumber%(2,StrHndl&)  
          gSubjectGPA(Subject)=FN MainReadNumber%(2,StrHndl&)  
          gSubjectIndex(Subject)=FN MainReadNumber%(2,StrHndl&)  
          gKindOfSubject(Subject)=FN MainReadNumber%(1,StrHndl&)
        NEXT Subject



And write 

    FN pGsaveAs
    LONG IF LEN(gsaveName$)
      
      goffset&=0
      CURSOR _watchCursor
      
      FN MainWriteNumber(fileKey,StrHndl&,3)
      FN MainWriteNumber(gGradeEquivalency,StrHndl&,2)
      FN MainWriteNumber(gNumberOfStudents,StrHndl&,2)  


and

      FOR Subject=0 TO _ClassMax 
        FN MainWriteNumber(gEntriesToDate(Subject),StrHndl&,2)  
        FN MainWriteNumber(gSubjectGPA(Subject),StrHndl&,2)  
        FN MainWriteNumber(gSubjectIndex(Subject),StrHndl&,2)  
        FN MainWriteNumber(gKindOfSubject(Subject),StrHndl&,1)
      NEXT Subject


now write it.

    OPEN "O",#7,gSaveName$,,gSaveVol
    
    WRITE FILE#7,[StrHndl&],gOffSet&
    osErr%=FN HUNLOCK(StrHndl&)
    DEF DISPOSEH(StrHndl&)
    CLOSE #7

I am clipping and snipping fast, as it is time for church, but I hope this 
gives you some clues as to how it can be done.


George