[futurebasic] Re: [FB] [FB2] XREF Array of Records (lengthy)

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

From: Jay Reeve <jktr@...>
Date: Tue, 19 Oct 99 23:36:13 -0500
>I'm not sure that adding the length info into the handle is a good idea - I
>would keep these seperate. My guess is that this is your problem.

I'm sure David is right. Here are a couple of suggestions for your code, 
apart from FN Mung&, intended to be helpful, not critical:

>Now, I want to load these into an array of records. Each student is given 
>one 52-byte record. These contain a two-byte integer for their ID, and a 
>50-byte string for their name:
>DIM RECORD studentInfo
>  DIM studentId%
>  DIM 50 studentName$
>DIM END RECORD.studentInfo
You will find that this creates a 54-byte record. The string will add a 
length byte and a pad byte to the 50 chars you requested. No problem, as 
you use the _studentInfo constant correctly. (I assume you're using FBII, 
because in FB^3 you will have to rename this constant--it can't be the 
same as the record name.)

>XREF@ gFormattedInfo.studentInfo(1000)'Could be any number, no mem 
>  'Dynamic Allocation
>  gFormattedInfo.Top& = FN NEWHANDLE(4)
Does this work? I'm not sure how. The handle var that goes with an XREF@ 
is a simple LONG var. It's usually:
   gFormattedInfo& = FN NEWHANDLE(4)

>  arraySize% = 0            'It will be equal to 4 once the loop starts
... 4? Where do you get 4? When you do this:
>    arraySize% = arraySize% + _studentInfo
it will be 54 (the size of _studentInfo).

>    osErr% = FN SETHANDLESIZE(gFormattedInfo.Top&, arraySize%)
Again, I think it should be:
     osErr% = FN SETHANDLESIZE(gFormattedInfo&, arraySize%)

>    'Find the student ID
>    idPointer& = VARPTR(gFormattedInfo.studentID%(arrayDepth%))
>    'blockmove source, destination, amount
>    BLOCKMOVE (gTextH& + offSet&), idPointer&, 2
 You have been putting more-or-less random values in here. You need to 
dereference the handle to get the address of the text.:
     BLOCKMOVE ([gTextH&] + offSet&), idPointer&, 2

Why are you moving 2 bytes? It looks to me as if the data you are getting 
has a 5-char id. You could use 6 or 7 to be safe. Is what you want really 
     BLOCKMOVE ([gTextH&] + offSet&), @tempStr$ + 1, 6
     POKE @tempStr$,6                 'Create string from first 6 chars
     gFormattedInfo.studentId% = VAL(tempStr$)      'Store as INT value

>    'Find the student name
>    char$ = CHR$(9)
Do you know that the divider is a CHR$(9)? That is a tab char. A space 
would be CHR$(32).

>    'It locks up right here
>    offSet& = FN Mung&(char$,rep$,gTextH&,offSet&,_search)
I don't see a problem here, providing your FN Mung& uses the parameters 
correctly. Here's my stab at one using your parameters:

LOCAL FN Mung&(@findTxt&,@replTxt&,txtH&,offSet&,mode)
  LONG IF txtH&             'Check for non-zero handle
    findLen = PEEK(findTxt&)
    replLen = PEEK(replTxt&)
    found& = FN 
END FN = found&

I'm not sure what you do with the _search param, as the search mode is 
determined by what's in the strings.

>    lineStart& = offSet&
>    INC(offSet&)
>    offSet& = FN Mung&(char$,rep$,gTextH&,offSet&,_search)
Are you looking for the next CHR$(9), or should your code to 'Move 
offSet& to next line' go here? (I suspect it should.)

>    stringStart& = VARPTR(gFormattedInfo.studentName$(arrayDepth%))
>    copySize% = (offSet& - lineStart&)
Do you intend to copy the CR with the name? I'm not positive, but I think 
this will, even if you search for the CR instead of the tab.

>    'Move offSet& to next line
>    char$ = CHR$(13)
>    offSet& = FN Mung&(char$,rep$,gTextH&,offSet&,_search)
>    INC(offSet&)
As I said above, you have already moved into the next line, unless your 
data has a tab at the end of the name field, before the CR.    

Please excuse me if I've belabored the obvious. I'm sure you are clear on 
most of this. But if I have elucidated anything, maybe it will help.

 =J= a  y