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 StatesPosts: 761 |
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: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
James_From_Canb Senior Member Joined: 19/06/2011 Location: AustraliaPosts: 265 |
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 StatesPosts: 761 |
Thanks Gent's..!! I am sure I can get around this somehow... just more code... |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Hi james - good to see you back on deck again. Greg |
||||
Print this page |