Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MMBasic - Arrays in subroutines
Author | Message | ||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1101 |
Hi Folks, New guy here but with reasonable experience with Basic and hardware. Using a Duinomite Mega running v4 MMBasic to a PC running TerraTerm. I am trying to code some routines to manipulate arrays but find I can't seem to pass an array variable to a subroutine. I understand that variables passed to subs should be by reference? Code example - > new > 1 dim TstArray(5) > 2 arraypushdown TstArray,6,99 > 3 print TstArray(0) > > 10 Sub ArrayPushDown (ArrayName, ArrayElements, NewData) > 20 Local Ax > 30 For Ax = ArrayElements-1 to 1 Step -1 > 40 ArrayName(Ax) = ArrayName(Ax-1) > 50 Next Ax > 60 ArrayName(0) = NewData > 70 End Sub > > run [7] 40 ArrayName(Ax) = ArrayName(Ax-1) Error: Array must be dimensioned first > If I change the array name in lines 1 and 2 to the same as that in the subroutine, it all works OK but this limits the generality of the subroutine. Am I missing something here? Any help appreciated. Thanks, Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
At this time you cannot pass an array to a sub, only a single element of an array (ie, the argument must resolve into a number or string). I must admit that passing an array (by reference) does not sound that hard to implement - something to look into. Geoff Geoff Graham - http://geoffg.net |
||||
panky Guru Joined: 02/10/2012 Location: AustraliaPosts: 1101 |
Thanks Geoff, appreciate your quick reply. Cheers, Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Print this page |