How do you pass parameters to methods by using arrays?
ElectricAye
Posts: 4,561
Hey everyone,
Let's say I declare an array of 6 elements made up of longs,
(Please note I used parentheses instead of brackets because my browser freaked out.)
Later in the Main program, I write values into my array, as follows:
Later in my Main program, I want to pass this array to a method via the method's parameter list and I use the technique lovingly known as "pass by reference," so I (think I) write the following:
Next, down inside the code of MyBrilliantMethod, I want to extract the values that are stored in the addresses of the TemperatureArray. And here's where my ignorance begins to really balloon...
Would it - or could it - look like this???
If this is a correct approach, then my next question is... What would be the correct value for the AddressOffsets? I presume AddressOffset0 would be zero. But what of the other offsets? How does an offset relate to the memory address?
many thanks for your help,
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Post Edited (ElectricAye) : 5/20/2009 3:46:58 PM GMT
Let's say I declare an array of 6 elements made up of longs,
(Please note I used parentheses instead of brackets because my browser freaked out.)
LONG TemperatureArray(6)
Later in the Main program, I write values into my array, as follows:
TemperatureArray(0) := 0 TemperatureArray(1) := 10 TemperatureArray(2) := 20 TemperatureArray(3) := 30 TemperatureArray(4) := 40 TemperatureArray(5) := 50
Later in my Main program, I want to pass this array to a method via the method's parameter list and I use the technique lovingly known as "pass by reference," so I (think I) write the following:
MyBrilliantMethod (@TemperatureArray)
Next, down inside the code of MyBrilliantMethod, I want to extract the values that are stored in the addresses of the TemperatureArray. And here's where my ignorance begins to really balloon...
Would it - or could it - look like this???
PUB MyBrilliantMethod (HubMemoryAddressOfTempArray) | Temperature0, Temperature1, TemperatureEtc.... Temperature0 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset0] Temperature1 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset1] Temperature2 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset2] Temperature3 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset3] Temperature4 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset4] Temperature5 := LONG[noparse][[/noparse]HubMemoryAddressOfTempArray + AddressOffset5]
If this is a correct approach, then my next question is... What would be the correct value for the AddressOffsets? I presume AddressOffset0 would be zero. But what of the other offsets? How does an offset relate to the memory address?
many thanks for your help,
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Watching the world pass me by, one photon at a time.
Post Edited (ElectricAye) : 5/20/2009 3:46:58 PM GMT
Comments
In this case, Index can increment by 1.
-Phil
that is GREAT! It's almost like I'm starting to really understand what all you gurus have been teaching me all these months. Thanks, too, for the tip on using the Index notation.
bless you, Oh Pilgrim, bless you,
Mark