[futurebasic] Re: [FB] containers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2007 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Thu, 15 Feb 2007 18:39:27 +0100
Bernie a écrit :
> 
> Ted asked:
> 
>> Is there a cute way of stepping through a container byte by byte, akin 
>> to the string$[i] thing?
> 
> 
> Alain and Jay are the container experts but these are the cute-ist I can 
> come up with:
> 
> 
> // Option (1)
> '----------
> local mode
> local fn Cntr( @cPtr as pointer, chrPos as long )
> '~'1
> dim as pointer  p
> p = [cPtr.nil&] + chrPos
> end fn = p.0``
> 
> dim as container gC
> dim as long c, length
> 
> gC = "Alpha Bravo Charlie Delta Echo FutureBasic"
> 
> length = len(gC)
> for c = 0 to length - 1
> print fn Cntr( gC, c ),chr$(fn Cntr( gC, c ))
> next c
> '----------
> 
> 
> // Option (2)
> '----------
> dim as container gC
> dim as pointer p, pEnd
> 
> gC = "Alpha Bravo Charlie Delta Echo FutureBasic"
> 
> p = [gC.nil&]
> pEnd = p + fn GetHandleSize( gC.nil& ) - 1
> while ( p <= pEnd )
> print p.0``,chr$(p.0``)
> p++
> wend
> '----------
> 
> 

XRef arrays might also be used for that purpose:

'~'A
'                             Runtime : RNTM Lite.INCL
'~'B

begin globals
dim as container gC
end globals

local fn SteppingThroughContainerByteByByteUsingXRef
dim as long maxIndex,i
xref@ aryPlotter( _maxInt ) as byte

aryPlotter = [@gC]
maxIndex = fn GetHandleSize( aryPlotter ) - 1
for i = 0 to maxIndex
print chr$( aryPlotter(i) );
next
end fn


// main
gC = "Alpha Bravo Charlie Delta Echo FutureBasic"

fn SteppingThroughContainerByteByByteUsingXRef

Alain