[futurebasic] Re: [FB] Loading File speed #2

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

From: GBeckman@...
Date: Sat, 1 May 1999 00:02:56 EDT
Sorry for the wasted band width, but that last one got sent when I was 
editing.  (The one thing I don't like about my G3 Powerbook...static on the 
mouse pad can send the cursor most anywhere, like on the send button when you 
are moving around)

> I tried
>Beckman's suggestion but kept getting type 1 errors (my fault I am sure)
>

Terrald,

	Beckman does not always explain things very well.  I will try to do 
better.  Not trying to insult by over-explanation, just that sometimes things 
escape me for until someone points it out.

	Are you getting the error before or after the read?  It may be that 
your handle is going bad on you.

	Here is the whole thing...almost... and I will put some comments in 
now and then in areas that I had to do some figurin'

LOCAL
DIM Student
DIM Filesize& ,myMen&,StrHndl&
DIM dummy,OsErr%,fileKey

<<I cut a bunch out above...but tried to leave most of what you see you need 
here.  Note that FileSize is & not %.  That escaped me for a while and I 
could never figure out why I got bad numbers on a file of 180+K.>>


LOCAL FN OpenFromWindows
  
  gOpenType$="TEXT"                               'files to open
  
  gFileName$=""

<<make sure nothing is hanging around.  (this is a PG project)>>

  FN pGopenFile
  
  LONG IF LEN(gFileName$)  

<<check to be sure you really have a name>>
    
    CURSOR _watchCursor
    OPEN "I",#3,gFileName$,,gFileVol
    fileSize&=LOF(3,1)

<<Here because I needed a file size for later and because I needed to check 
handle, I decided to use it as my flag... see at the XELSE>>
    
    StrHndl&=FN NEWHANDLE(fileSize&+5)
    
<<try for a handle and then check to see it has something in it.  If not, you 
may not have memory enough for it.  >>

    LONG IF (StrHndl&<>_nil)
      
      osErr%=FN HLOCK(StrHndl&)

<<I am never sure what routines can move memory, so I locked it during the 
read.  Notice I am too lazy to check to see if the lock caused and error>>
      
      READ FILE#3,[StrHndl&],fileSize&
      osErr%=FN HUNLOCK(StrHndl&)   
<<unlock and assume we have a something in the handle>>
    XELSE

<<I could land here because the file name was canceled and blank or because 
of a memory full.  I call a mFulErr here in Beta so I can watch what is going 
on...but sloppy.  I mark my file size 0 so the following routines won't run.

      osErr%=_mFulErr
      FileSize&=0
    END IF
    CLOSE #3  

<<close the file>>
    
    LONG IF FileSize&<>0  

<<If we have anything, we can go on.  I know that I don't really have to do 
the <>0 but I was having trouble here...>>
      
      gOffset&=0

<<This can be a biggie...gotta start at zero>>

      fileKey=FN MainReadNumber%(3,StrHndl&)

I here am just reading the header and making sure I am working with the right 
version>>

      LONG IF FileKey=400                         'got the right file
        

         FOR Student=1 TO _Max 
          gFirstName$(Student)=FN MainReadText$(12,StrHndl&)   
          gLastName$(Student)=FN MainReadText$(20,StrHndl&)   
          gParentName$(Student)=FN MainReadText$(30,StrHndl&)   


<<Start getting the info...Here I happen to know how long each is and you 
said you do also.  You could streamline this a bit as all your strings are 
the same lenght>>

<<and so on, not forgetting to get rid of the handle...
DEF DISPOSEH(StrHndl&)
>>



<<Here is one version of a read I use for the memory block>>

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$

<<In this one I am making sure I don't over run a string if the data flow is 
defective noting that this supposes I don't put 423 or some such nonsense in 
myLength>>

<<The PEEK is always tricky for me.  I think Chris Stazny gave me the actual 
syntax when I could not get all the ( and ] in the right place.>>

Hope this helps,

George