Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 04:23 13 Nov 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 : Is this a trap waiting to happen?

Author Message
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 11:08pm 06 Aug 2019
Copy link to clipboard 
Print this post

G'day All
I'm fiddling with code optimizing and generally trying to improve the 'flow' of my code. Just to push it a little further, I'm trying arrays of GUI controls, with local declarations for the GUI elements...
Here's what I've come up with -

sub GuiSetup
gui setup 1 'Show the main options frame
local OptionsFrame=16
Font 4
gui frame OptionsFrame," Change Time/Date ",1,50,790,200,rgb(Cyan)

gui setup 2 'Show the Time/Date radio buttons
local X=50, Y=100 'Declare the initial X,Y coordinates
Local TimeRadioID(5)=(10,11,12,13,14,15) 'Setup the Array identifiers
Local String TimeRadioStr$(5) Length 6=("Hour","Minute","Second","Day","Month","Year") 'Assign the names to the buttons
font 4
for i = 0 to 5 'Loop through the array
gui radio TimeRadioID(i), TimeRadioStr$(i), X,Y,15,RGB(cyan) 'Add the radio buttons
X=X+180 'Next X position
If i=2 then 'First 3 radios are done
X=50 'Reset the X position
Y=150 'New Y position
end if 'Reset complete
next i 'Do the next item in the array
ctrlval(TimeRadioID(0))=1

gui setup 3'Show the Increase/Decrease arrows
Local IncreaseButton=17, DecreaseButton=18
Font 8 'Change to the ARROW font
gui button IncreaseButton, " ", 700,75,66,66,RGB(green)'Space is the UP arrow
gui button DecreaseButton, "!", 700,160,66,66,RGB(green)'! is the DOWN arrow

end sub

(Note: This is only the GUI SETUP in my coding, so it won't actually do anything if you cut and paste to try it out)

This was much easier and painless than I thought it would be (testament to MM Basic!) but I'm now wondering if putting LOCAL declarations for the GUI elements in the GUI SETUP is somehow going to trip me over further down the track?
So far, I haven't had any problems!

Any thoughts would be appreciated
John
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1116
Posted: 01:43am 07 Aug 2019
Copy link to clipboard 
Print this post

@malabu

The problem with using LOCAL for GUI element names inside the sub is that the declaration is only available inside the sub.

In some GUI cases this would not be a problem however, if you needed to refer to that GUI element using CTRLVAL to assign a different value elsewhere in your program, the GUI name would not be available outside the sub and would throw an error.

INMHO, it is better practice to declare the GUI element names as CONST at the start of your program along with other DIM statements etc. then they are globally available.

panky
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
Malibu
Senior Member

Joined: 07/07/2018
Location: Australia
Posts: 260
Posted: 03:22am 07 Aug 2019
Copy link to clipboard 
Print this post

  Quote  The problem with using LOCAL for GUI element names inside the sub is that the declaration is only available inside the sub.


Thanks Panky... you're exactly right because that's what happened as I found out a couple of hours after my initial post.
I tried to do something to a GUI element (can't remember now, I think a GUI Hide) and I ran into a 'Not Declared' error.
I guess that's why I had the niggling doubt over the merit of what I'd done.
Thanks for your input!
John
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 06:49am 07 Aug 2019
Copy link to clipboard 
Print this post

  panky said  INMHO, it is better practice to declare the GUI element names as CONST at the start of your program along with other DIM statements etc. then they are globally available.

panky


Agreed.
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