![]() |
Forum Index : Microcontroller and PC projects : MMBasic: passing array as argument to Sub
Author | Message | ||||
Janosik Newbie ![]() Joined: 30/10/2015 Location: SlovakiaPosts: 5 |
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 ZealandPosts: 9643 |
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: Smoke makes things work. When the smoke gets out, it stops! |
||||
Janosik Newbie ![]() Joined: 30/10/2015 Location: SlovakiaPosts: 5 |
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: I really can't see what I'm doing wrong here... |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1629 |
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: 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 ... or in other words you are using the wrong MMBASIC version. ![]() causality ≠correlation ≠coincidence |
||||
Janosik Newbie ![]() Joined: 30/10/2015 Location: SlovakiaPosts: 5 |
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: GermanyPosts: 1629 |
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: SlovakiaPosts: 5 |
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: GermanyPosts: 1629 |
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 StatesPosts: 10 |
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 Newbie ![]() Joined: 30/10/2015 Location: SlovakiaPosts: 5 |
I suppopse the guys at CG want to sell their old stuff first... Do you have a link or so to those newer Micromites? 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 ![]() |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1629 |
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). Michael causality ≠correlation ≠coincidence |
||||
CircuitGizmos![]() Guru ![]() Joined: 08/09/2011 Location: United StatesPosts: 1427 |
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. ![]() Micromites and Maximites! - Beginning Maximite |
||||
isochronic Guru ![]() Joined: 21/01/2012 Location: AustraliaPosts: 689 |
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. |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9643 |
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! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |