[futurebasic] Re: [FB] STR# question

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

From: Jay Reeve <jktr@...>
Date: Sat, 15 May 99 10:50:23 -0500
>I know....your suggestions to kiss my STR# stuff is right but it is taking
>several minutes to load the 800k file over the network to put into STRING$()
>stuff.  I would like to try the STR# stuff one time only at the initial
>load.  I can do an initial loop to convert but it takes about 30 seconds on
>my G3.  I tried to modify the suggestion (which works great) that Jay gave
>for converting the read file# to the string$() stuff but trying to go from
>the STR# to string$() is another one of my flaws.
>
>Obviously, I am not a good programmer.  This is giving me a bad offset.
>
>itemnumber=FN countStr(_diagnosislistSTR)
>LONG IF itemnumber>0
>    StrHndl& = FN GETRESOURCE(_"STR#",_diagnosislistSTR)
>    OSErr  = FN HNOPURGE(StrHndl&):gOffSet&=0
>    FOR Myloop=1 TO itemnumber
>      POKE @DIAGNOSIS$(Myloop),48           'Set length byte
>      BLOCKMOVE [StrHndl&]+gOffSet&,@DIAGNOSIS$(Myloop)+1,48'move string
>      gOffSet& = gOffSet& + 48              'get offset of next string
>    NEXT
>    OSErr  = FN HPURGE(StrHndl&)
>END IF
>
>Corrections?

Hi Terrald,

My understanding of STR# resources is that their strings already have 
length bytes--so there's no need to add them. You do need to initialize 
your offset to 2 to skip the word that tells how many strings are in the 
STR#. If the strings are 48 chars long, then you have to add the length 
byte and a pad byte to your offset number, making it 50. However, if ALL 
the strings are the same length (48), there are much easier solutions:

DIM 48 DIAGNOSIS$(_numberOfStrings)      'FB will add length & pad
'Copy entire array in 1 fell swoop
StrHndl& = FN GETRESOURCE(_"STR#",_diagnosislistSTR)
LONG IF StrHndl&
  BLOCKMOVE [StrHndl&]+2,@DIAGNOSIS$(0),FN GETHANDLESIZE(StrHndl&)-2
END IF

Or, my favorite, which uses the data exactly as received, with no 
additional processing or copying needed:

DIM     DIAGNOSIS&       'Tells where to start array
XREF 48 DIAGNOSIS$(1)    "Indicate size of element (50 in this case)
'
StrHndl& = FN GETRESOURCE(_"STR#",_diagnosislistSTR)
LONG IF StrHndl&
  OSErr  = FN HNOPURGE(StrHndl&)
  OSErr  = FN HLOCK(StrHndl&)
  DIAGNOSIS& = [StrHndl&]+2   'Set array address, skipping count word
END IF

...and you're done! This requires that the handle remain locked until 
you're completely finished with it (so it doesn't move, invalidating the 
address in DIAGNOSIS&), but that's no different than having a DIMmed 
array. Your DIAGNOSIS$() array is ready to use!

BTW, I don't actually know whether or not you need to set HNOPURGE if 
you're locking the handle. Also, I've not addressed the question of 
writing back any changes in DIAGNOSIS$(), but that should simply be a 
matter of marking the resource as changed.

As for your not being a good programmer, none of us are when we don't yet 
understand what we're doing. You'll soon understand it, and then you'll 
be the expert!

Let me know if you still run into problems.
 0"0
 =J= a  y
  "