Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:31 26 Nov 2024 Privacy Policy
Jump to

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: Australia
Posts: 1101
Posted: 08:13pm 03 Oct 2012
Copy link to clipboard 
Print this post

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: Australia
Posts: 3194
Posted: 09:00pm 03 Oct 2012
Copy link to clipboard 
Print this post

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: Australia
Posts: 1101
Posted: 07:35pm 04 Oct 2012
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024