[futurebasic] Re: [FB] Newbie questions

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2002 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Thu, 5 Dec 2002 00:50:54 -0600
>I am new to FutureBASIC.

Welcome! I think you're in for some fun.

>2) How can I pass simple variables back via the LOCAL FN's parameter 
>list?  The
>manual indicates that in order to do this, I need to pass the varaible's
>address, but after receiving the address, how I can modify the 
>content?  I need to use PEEK/POKE/BLOCK MOVE?

That's one way. I prefer to put the address into a pointer, then use 
the ptr.fieldoffset syntax:


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

LOCAL FN changePassedVar( @myPtr AS PTR)
myPtr.0& = 1234567 'The & makes it a long
END FN

LOCAL FN test
DIM @ longVar AS LONG 'can't be register var, so use @
longVar = 42
PRINT longVar
FN changePassedVar( longVar)
PRINT longVar
END FN

FN test

//Another option is to use a global true record type, and create a pointer
//to the record:

BEGIN GLOBALS
BEGIN RECORD myRec
DIM var1&
DIM var2%
DIM var3#
DIM var4``
END RECORD
END GLOBALS

LOCAL FN changePassedRecord( @myPtr AS PTR TO myRec)
myPtr.var1 = 50000
myPtr.var2 = 23456
myPtr.var3 = 9.876
myPtr.var4 = 123
end fn

LOCAL FN test2
DIM @ recVar AS myRec 'can't be register var, so use @
FN changePassedRecord( recVar)
PRINT recVar.var1, recVar.var2, recVar.var3, recVar.var4
END FN

FN test2

FWIW, for reasons I can't explain, the .fieldoffset syntax is 
signicantly faster than the old PEEKs and POKEs.

HTH
  e-e
  =J= a  y
   "