[futurebasic] Re: [FB] Strings > 255 characters?

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

From: tedd@...
Date: Tue, 27 Oct 1998 15:59:59 -0500
I asked:

>>Anyone have a slick way (or code) to make strings longer than 255
>>characters? I have a need for a 360 charcter string.

jonathan wrote:

>Pascal strings can't be greater than 255, but if you put this
>in a handle, you can pass it to a EF. From a serial buffer,
>as I'm supposing that this is where the chars are,
>this shouldn't be difficult as you probably already have them
>in a handle there, no?

Yes, I solved the problem by using a handle (see below).

---
Osamu Shigematsu wrote:

>How about using handle (or pointer)?
>I always use handle to handle strings (texts) which over 255 characters.
>If the max length was fixed and not so large, you may use pointer.

Correct.

I figured that by grabbing a block of memory equal to the size I needed was
the best way to do this. It reminds me of how C does strings (yuck!).

So, this is how I did it (for anyone interested).

To store the string (actually it's not a string because it's too long). You
have to store characters.

'--- get the memory needed (_size is 2*LEN string)

gNewH& = FN NEWHANDLE _clear(_size)
prt& = [gNewH&]               'get the pointer from the handle
POKE WORD(ptr&), a            'store "a" as the length of the string
FOR i = 2 TO a STEP 2
   POKE WORD(ptr& + i), b     'store "b" as the ASCII value for each
NEXT                          'character of the string

When one wants to read the string, you use:

prt& = [gNewH&]               'get the pointer from the handle
a = PEEK WORD(ptr&)           'get the length of the string
FOR i = 2 to a STEP 2         'move through the memory block
   b = PEEK WORD(prt& + i)    'get the ASCII value
   b$ = CHR$(b)               'convert to character
NEXT

Now, if anyone see's a problem with this, please post it!

---
Pierre A. Zippi wrote:

>A while ago, Mars donated a whole set of "long" string functions to one of the
>FB web sites.  I use a few of them. They're great!
>Check the "Unofficial FB site".

I checked and could not find the "Unofficial FB site", nor Mars' code.
Anyone got a new URL for it? Mars? You got your ears on? You got code?

tedd

___________________________________________________________________
<mailto:tedd@...>	               http://sperling.com/