Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:52 18 Sep 2025 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: passing array as argument to Sub

Author Message
Janosik
Newbie

Joined: 30/10/2015
Location: Slovakia
Posts: 5
Posted: 04:22am 31 Oct 2015
Copy link to clipboard 
Print this post

Hi all,

Is it possible to pass an array as argument for a Sub or Function in MMBasic?
I have tried everything I could think of, but none of it works...

Thanks and greetings,
Janosik.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 04:29am 31 Oct 2015
Copy link to clipboard 
Print this post

Welcome!


As far as I know, you just use closed brackets to represent the array, and then the entire array is passed:

SUB MYSUB ARRAY$(),A,B,C
...
...
END SUB



See manual, page 43.

EDIT: From manual:

  MicroMite manual, page 43 said  You can also pass one or more complete arrays to a subroutine or function by specifying the array with empty brackets instead of the normal dimensions. For example, a(). In the subroutine or function definition the associated parameter must also be specified with empty brackets. The type (ie, float, integer or string) of the argument supplied and the parameter in the definition must be the same.
Edited by Grogster 2015-11-01
Smoke makes things work. When the smoke gets out, it stops!
 
Janosik
Newbie

Joined: 30/10/2015
Location: Slovakia
Posts: 5
Posted: 06:01am 31 Oct 2015
Copy link to clipboard 
Print this post

Thanks for your answer, Guru!

But... I did try that...

Here's what I wrote:


Main

Sub Main
Dim mnuTekst$(4)
mnuTekst$(1)="aaaaaaaaaaaa"
mnuTekst$(2)="bbbbbbbbb"
mnuTekst$(3)="ccccccccccccccc"
mnuTekst$(4)="dddd"
keuze=KiesUitMenu(4,mnuTekst$(),100,20)
print @(0,0) keuze
End Sub

Function KiesUitMenu(aantal,tekst$(),x,y)
For i=1 to aantal
print @(x,y+i*12) tekst$(i)
Next i
KiesUitMenu=99
End Function


When I run it, I get this this error:
  Quote  
[10] keuze=KiesUitMenu(4,mnuTekst$(),100,20)
Error: Invalid array dimension


I really can't see what I'm doing wrong here...
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 06:50am 31 Oct 2015
Copy link to clipboard 
Print this post

  Janosik said   Hi all,

Is it possible to pass an array as argument for a Sub or Function in MMBasic?
I have tried everything I could think of, but none of it works...

Thanks and greetings,
Janosik.


Hi Janosik (and welcome),

which system (Maximite, Micromite, MM2, MM+, ...), which MMBasic version, please?

Regards
Michael

EDIT:
for example for MAXIMITES (MMBasic 4.5, s. Manual p20) applies this:
  Quote  You cannot use arrays in a subroutine or function's argument list however the caller can use them. For example, this is a valid way of calling the Swap subroutine (discussed above):
Swap dat(i), dat(i + 1)
This type of construct is often used in sorting arrays.

ie you have to use global arrays for this purpose.

'Code example for MAXIMITES MMBasic 4.5
Main

Sub Main
Dim mnuTekst$(4)
mnuTekst$(1)="aaaaaaaaaaaa"
mnuTekst$(2)="bbbbbbbbb"
mnuTekst$(3)="ccccccccccccccc"
mnuTekst$(4)="dddd"
keuze=KiesUitMenu(4,100,20)
Print @(0,0) keuze
End Sub

Function KiesUitMenu(aantal,x,y)
For i=1 To aantal
Print @(x,y+i*12) tekst$(i)
Next i
KiesUitMenu=99
End Function


  Quote  I really can't see what I'm doing wrong here...


... or in other words you are using the wrong MMBASIC version. Edited by twofingers 2015-11-01
causality ≠ correlation ≠ coincidence
 
Janosik
Newbie

Joined: 30/10/2015
Location: Slovakia
Posts: 5
Posted: 07:05am 31 Oct 2015
Copy link to clipboard 
Print this post

Hi twofingers,

I bought an assembled and tested CGCOLORMAX2 from CircuitGizmos.

When entering "Print MM.VER" at the prompt, it shows "4.04".
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 07:20am 31 Oct 2015
Copy link to clipboard 
Print this post

  Janosik said   Hi twofingers,

I bought an assembled and tested CGCOLORMAX2 from CircuitGizmos.

When entering "Print MM.VER" at the prompt, it shows "4.04".

The MaxiMite (and your MMBasic version too) is somehow outdated.
You should try to update your MMBasic (s. Geoffs site ). The 4.5 (4.05) is the latest.

Although that will not solve your problem.
You cannot use arrays in a subroutine or function's argument list


Regards
Michael


PS
Here are many very friendly and competent people to help you if you need help.

PPS
I like the MAXIMITE and his family too!
causality ≠ correlation ≠ coincidence
 
Janosik
Newbie

Joined: 30/10/2015
Location: Slovakia
Posts: 5
Posted: 07:28am 31 Oct 2015
Copy link to clipboard 
Print this post

Okay... this way it works indeed
I'm not really happy with this sollution (it just doesn't "feel" right), but it will just have to do!
Thanks for your help.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 07:36am 31 Oct 2015
Copy link to clipboard 
Print this post

  Janosik said   I'm not really happy with this sollution (it just doesn't "feel" right), ...

I agree with that! That's why Geoff made it better for the newer Micromites.


causality ≠ correlation ≠ coincidence
 
hwholmes
Newbie

Joined: 30/05/2014
Location: United States
Posts: 10
Posted: 08:44am 31 Oct 2015
Copy link to clipboard 
Print this post


I think part of your problem with dimension might also be that arrays are zero "0" based by default. Try:

mnuTekst$(0)="aaaaaaaaaaaa"
mnuTekst$(1)="bbbbbbbbb"
etc.

or use the setting to change the base to 1, I don't have it open but I think it is one of the "OPTION" items.


  Janosik said   ....

Here's what I wrote:


Main

Sub Main
Dim mnuTekst$(4)
mnuTekst$(1)="aaaaaaaaaaaa"
mnuTekst$(2)="bbbbbbbbb"
mnuTekst$(3)="ccccccccccccccc"
mnuTekst$(4)="dddd"
keuze=KiesUitMenu(4,mnuTekst$(),100,20)
print @(0,0) keuze
End Sub

Function KiesUitMenu(aantal,tekst$(),x,y)
For i=1 to aantal
print @(x,y+i*12) tekst$(i)
Next i
KiesUitMenu=99
End Function


When I run it, I get this this error:
  Quote  
[10] keuze=KiesUitMenu(4,mnuTekst$(),100,20)
Error: Invalid array dimension


I really can't see what I'm doing wrong here...
 
Janosik
Newbie

Joined: 30/10/2015
Location: Slovakia
Posts: 5
Posted: 09:10am 31 Oct 2015
Copy link to clipboard 
Print this post

  twofingers said  That's why Geoff made it better for the newer Micromites

I suppopse the guys at CG want to sell their old stuff first...
Do you have a link or so to those newer Micromites?

  hwholmes said  
I think part of your problem with dimension might also be that arrays are zero "0" based by default.

I don't think that is the problem...
I created an array with 5 elements (indexed from 0 up to 4), but I'm just not using the one with index 0 (which is indeed a bit waste of memory ).Edited by Janosik 2015-11-01
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1629
Posted: 09:41am 31 Oct 2015
Copy link to clipboard 
Print this post

  Janosik said   Do you have a link or so to those newer Micromites?

If you own already a programmer (like Pickit3) it is very simple and cheap.
You only need
1x breadboard
1x Pic32MX170
1x Capacitor 47µF (ceramic or tantal)
1x USB to serial adaptor (6Pin USB 2.0 to TTL UART Serial Converter CP2102 or similar)
and some jumper wires.

You can also buy complete boards and/or chips from Grogster or WhiteWizzard or bigmik and many more (AFAIK).

If you want to build your own progranmer then are there many ways (for example).

First of all I would suggest to download Geoffs excellent MM manual.

Note: The Micromite has no VGA output but you can easily connect a 6$ LCD 240x320 (with touchscreen).

MichaelEdited by twofingers 2015-11-01
causality ≠ correlation ≠ coincidence
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 10:59am 31 Oct 2015
Copy link to clipboard 
Print this post

  Janosik said  
  twofingers said  That's why Geoff made it better for the newer Micromites

I suppopse the guys at CG want to sell their old stuff first...
Do you have a link or so to those newer Micromites?


Maximites are different from Micromites.

You can update the CGCOLORMAX with the update software that Geoff has on his site. The CGCOLORMAX you have can be updated to Maximite formware version 4.5.

The CGMICROBOARD ( you can buy one here ) is a Micromite (not a Maximite) and the BASIC in a Micromite is more advanced.



Edited by CircuitGizmos 2015-11-01
Micromites and Maximites! - Beginning Maximite
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 12:27pm 31 Oct 2015
Copy link to clipboard 
Print this post

This is probably not the right place for it, but...

I keep seeing references to the minimal circuit ...(ed) AFAIK Microchip's recommended minimum circuit for pic32x in general has :

A low esr capacitor on Vcap, eg 10 uF, ceramic
Small ceramic bypass capacitors (0.1u) across the main power pins
Small ceramic bypass capacitor (0.1u) across the A/D power pins
and optimally a tank capacitor near the main power pins


(ed)
The higher speeds of the later micros require lower voltages which makes
them more susceptible to noise .. so more decoupling capacitors etc are needed.
I think the '470 has more, and the MZ has additional 0.01 uf bypass caps everywhere as well.
The point is, I don't think the single capacitor is enough.Edited by chronic 2015-11-02
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9643
Posted: 06:05pm 31 Oct 2015
Copy link to clipboard 
Print this post

For the MM+, I use 100n's very close to the power and analog-power pins, and also tank/reservoir cap on the main power in. This tends to be enough, but I do note that the Microchip datasheet for the 470's does mention(on page 27) that extra caps may be needed in parallel with the 100n's in the range 0.01uF to 0.001uF(10n-1n) for high-frequency immunity.

The datasheet goes on to recommend 100n in parallel with a 1n for HF noise.

At this stage, I have not bothered with the 1n's in parallel, but if it proved to be a problem, they could be added by stacking them on top of the existing 100n caps.

Not cosmetically ideal, but it would work until a new PCB revision could be done.
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025