[futurebasic] Re: [FB] Swapping Arrays in a function.

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

From: Jay Reeve <jktr@...>
Date: Mon, 25 Oct 99 22:52:04 -0500
>Once again, I'm in over my head. I have the function below. Based on the
>ASCII character, I do a lookup from an array to find the substitute
>character. What I want to be able to do is switch out arrays (so for
>example I can substitute a decimal or a hex number). I suspect I can do
>this with XREF but I've never figured out how to make them work. (This is
>for FB^3. I've looked at the manual and the example, but I'm too dense to
>figure it out.)
>
>Again, what I need to do is define and fill a couple of arrays, then pass
>something to the function so it can decide which array to use. I know I can
>just define several global arrays and pass a flag as to which array to use,
>but I'm looking for something a little cleaner and more flexible. Any help
>would be appreciated.

Mark,

I'm not entirely clear on what you want to accomplish, but if you can use 
global arrays you can use XREF@. Have you looked at the XREF FAQ at 
www.futurebasic.org? There are only a couple of small changes for FB^3.

Here is a recipe in 3 easy steps:

1. Create the array format:
  XREF@ myArray$(_anyPositiveNum)'Array size is determined by handle size.
In FB^3, this automatically creates a var called myArray& which is where 
you put the handle to whatever data you want to use.

2. Create the handle:
  myDataH& = NEWHANDLE(256*101)'make big enough for string elements 0-100

3. Slip your handle into the array var:
  myArray& = myDataH&

You're done. You can use myArray$(xx) just like you would any other array:
  myArray$(0)  = "This text is in element 0 of the array"
  myArray$(75) = "This text is in element 75 of the array. "
  myArray$(75) = myArray$(75)+"I hope I made the handle block big enough"
  
Now for the icing. To use a different set of data, just give your array 
the new handle that you created the same way:
  myArray& = anotherDataH&

Want to transfer data from one array to the other? Just use a temporary 
holder while you switch handles:
  myArray& = myDataH&'Use first data set
  tempStr$ = myArray$(75)'get string from first set
  myArray& = anotherDataH&'Switch to other data set
  myArray$(33) = tempStr$

Now the 33rd string of the "anotherDataH&" set is the same as the 75th 
string in myDataH&.

As I understand your code, it appears you are expanding single-character 
tokens into words or phrases. The conversion might yield different 
results depending on language or some other factor, so you would use 
different data sets. It might work something like this:

local fn NormalizeStrContents$(theString$,beginWhere,conversionH&)
dim x,myChar
dim tempStr$

LONG IF conversionH&'check for valid handle
XREF@ MARCtextConvArray$(255)'Create array
MARCtextConvArray& = conversionH&'install conversion table

x=beginWhere
WHILE len(theString$) > x
myChar=peek(@theString$+x)'get token
LONG IF len(MARCtextConvArray$(myChar))=0'no replacement
inc(x)
XELSE
mid$(theString$,x,1) = MARCtextConvArray$(myChar)'replace with conv
x = x + len(MARCtextConvArray$(myChar))'move to next char
END IF
WEND
END IF

end fn=theString$

Your code would probably be a hair faster than this--I changed it in 
hopes it might be clearer.

If you're not sure about how to build the conversion tables into handles, 
ask again.

HTH
 0"0
 =J= a  y
  "