Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 16:53 19 May 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 : CONST and Arrays

Author Message
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 03:35am 05 Jun 2017
Copy link to clipboard 
Print this post

Is it possible, or even worthwhile, to make an array using CONST instead of DIM?

For example, instead of:-
CONST Page1LED_Ch1 = 11
CONST Page1LED_Ch2 = 12
CONST Page1LED_Ch3 = 13
CONST Page1LED_Ch4 = 14


It would be nicer to be able to do:-
CONST Page1LED(4) = (11,12,13,14)


Of course this doesn't work, so I've had to resort to:-
DIM Page1LED(4) = (11,12,13,14)


In the code I'm doing, I'm using 4 separate channels for sampling voltage/current, controlling relays and displaying a hell of a lot of information in GUI Pages. (Over 100 Elements at last check) Having 4 Constants in arrays would make coding simpler using FOR...NEXT loops instead of having to type all the individual routines out 4 times and bloating the code. I guess it's no real problem using a DIM instead of CONST in this case, but I like the CONST because there is less chance of me stuffing up the variables.....

Is it maybe worth a look at in future MMBasic releases?

Cheers,

GTG!
...... Don't worry mate, it'll be GoodToGo!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 10:51pm 05 Jun 2017
Copy link to clipboard 
Print this post

I guess if it is not an illegal syntax, you can do exactly as you indicate - this sort of reverts back to personal preference to some extent. I know what you mean about lots of CONST commands. I currently have 21 pages of GUI elements in on system I am working on, and hundreds and hundreds of CONST commands. I don't think it matters one jot at the end of the day, cos MMBASIC just reads those commands at startup, then never refers to them again because they HAVE been defined via the CONST commands, so other then perhaps saving you a few ms at start-up, I don't think it would gain you much. More compact, neater code I guess.

It only takes MMBASIC 157ms to setup all 21 pages of GUI elements and CONST definitions, so one tenth of a second.....not bad.
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 11:25pm 05 Jun 2017
Copy link to clipboard 
Print this post

You could create a function that mimics an array.
[code]
Function Page1Led(index)
Local LEDS(4) = (Page1LED_Ch1,Page1LED_Ch2,Page1LED_Ch3,Page1LED_Ch4)
Page1Led = LEDS(index)
End Function
[/code]

Actually much easier. :)
[code]
DIM Page1LEDS(4) = (Page1LED_Ch1,Page1LED_Ch2,Page1LED_Ch3,Page1LED_Ch4)
[/code]

Edited by MicroBlocks 2017-06-07
Microblocks. Build with logic.
 
Print this page


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

© JAQ Software 2024