Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:43 28 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 : Passing Reference to Subroutine

Author Message
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 04:25am 30 Nov 2013
Copy link to clipboard 
Print this post

Happy Thanksgiving to all at the Shed..!!

Just a quick question... I have several dimensioned arrays that contain settings data.. I want to create a common subroutine that would use the data from the different arrays.. When called, I need to pass a reference to the wanted array into the subroutine.. I am sure there is a way to do this..! (it's my noobie calling)


dim RPM(12) ' create storage for "RPM" gauge
RPM(0)=0 ' gauge input value
RPM(1)=100 ' gauge MAX scale
RPM(2)=50 ' X-pos of gauge drawing
RPM(3)=50 ' Y-pos of gauge drawing
RPM(4)=yellow ' gauge frame color
RPM(5)=black ' gauge background color
RPM(6)=green ' gauge scale color
RPM(7)=yellow ' gauge numbers color
RPM(8)=red ' gauge needle color
' the last 4 bytes store object state change data

' the sub call
plot_scale (RPM)
' more code...

SUB plot_scale(g_info)
local center_x, center_y
center_x = g_info(2) + 84 ' get passed X-pos
center_y = g_info(3) + 120 ' Y-pos
' more code...
END SUB


I am playing around with the code that Bovist created that draws meter objects and wanted to make it into a common set of routines stored in a LIB file...

Thanks for any help, and Happy Holidays everyone..!!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:39am 30 Nov 2013
Copy link to clipboard 
Print this post

You can not use arrays as an argument for a sub or function.

from the MMBasic manual , page 14
[quote]
Additional Notes
There can be only one END SUB or END FUNCTION for each definition of a subroutine or function. To exit
early from a subroutine (ie, before the END SUB command has been reached) you can use the EXIT SUB
command. This has the same effect as if the program reached the END SUB statement. Similarly you can use
EXIT FUNCTION to exit early from a function.
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.
[/quote]

All is not lost, because what you could do is pass a string.
A string is kind of an array, existing of byte values.
Larger numbers can be a set of bytes, depending how large the values can be.

Edited by TZAdvantage 2013-12-01
Microblocks. Build with logic.
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 08:57am 30 Nov 2013
Copy link to clipboard 
Print this post

We had the same problem with an old system at work. We resolved it by putting all the values into a single array and added another field for, in your case, the gauge type. Pass the gauge type as a string parameter to your routine.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 09:15am 30 Nov 2013
Copy link to clipboard 
Print this post

Thanks Gent's..!!

I am sure I can get around this somehow... just more code...
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 05:25pm 30 Nov 2013
Copy link to clipboard 
Print this post

  James_From_Canb said  
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.
James
Hi james - good to see you back on deck again.

Greg
 
Print this page


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

© JAQ Software 2024