[futurebasic] Re: [FB] String <=> Handle

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

From: Sean -G3- <mclaugh@...>
Date: Fri, 10 Sep 99 21:19:31 -0500
>Hi gang:
>
>Does anyone have a cool way of going from a string$ to a handle& -- and
>back again? Something like: Given a string, how does one make a handle for
>it? And, given a handle, how does one create a string of its contents?
>
>I know that I can find the length of a string; create a block of memory the
>same size; and then POKE the string's values into memory. I also aware that
>if I know the handle of a block of memory then I can PEEK the contents of
>the block into a string. But, I'm looking for something a bit
>shorter/cooler to do those things -- if there is such a critter.
>
>Many thanks in advance for any replies.
>
>tedd

You can lock down and deref the handle. Lets call it myPointer&. Then, do:

myString$ = PSTR$(myPointer&)
PSTR$(myPointer&) = "this is text!"

or use blockmove:

dim theString$, theStringPointer&, stringLength%
theStringPointer& = @theString$

'Lets move myPointer& into the string
stringLenth& = peek long(myPointer&)
long if stringLength& <= 255
   poke stringLength&, theStringPointer&
   blockmove myPointer& + 4, theStringPointer& + 1, stringLength&
end if

'Lets move the string into the myPointer&
theString$ = "this is a string"
stringLength% = len(theString$)
POKE WORD myPointer, stringLength%
blockmove theStringPointer&+1, myPointer& + 2, stringLength%

I haven't tested this, but I hope it at least lead you in the right 
direction. Its alot easier to blockmove the chunk of data than to PEEK 
and POKE each byte.