May 06, 2024, 01:40:19 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Defining CONST values

Started by LarryMc, April 04, 2008, 11:27:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

When I define a bunch of CONST variables I usually group them by some criteria.

I almost always have to go back and insert one or more before I finish an application.

  CONST A_BUTTON = 1
  CONST C_BUTTON = 2
  CONST E_BUTTON = 3
  CONST G_BUTTON = 4
  CONST I_BUTTON = 5

If I decide that i want to add a B-Button I wind up having to renumber from C_Button down thusly:

  CONST A_BUTTON = 1
  CONST B_BUTTON = 2
  CONST C_BUTTON = 3
  CONST E_BUTTON = 4
  CONST G_BUTTON = 5
  CONST I_BUTTON = 6

Keeping the numbers in order helps me insure I don't duplicate a number and keeping the variable names in order helps to keep the variable names unique and consistent.

What I'd like to do is something like this:

base_number = 100
  CONST A_BUTTON = base_number : base_number++
  CONST B_BUTTON = base_number : base_number++
  CONST C_BUTTON = base_number : base_number++
  CONST E_BUTTON = base_number : base_number++
  CONST G_BUTTON = base_number : base_number++
  CONST I_BUTTON = base_number : base_number++

Problems is:
   Everything about CONST are compile time so they can't contain any variables.


I then tried using a SETID since it is evaluated at runtime:
  uint base_number
  base_number = 100
  SETID "A_BUTTON",base_number

Problem there is a SETID won't compile with a variable either (like base_number).

Is there some magic workaround that I can use to accomplish what I'm wanting to do?

If not, is it something that could be added to the language?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Yes.

const value1 = 100
const value2 = value1 + 1
const value3 = value2 + 1
const value4 = value3 + 1

And so on.

Which is the same method that's been used in other languages for decades ;)  Adding a value between two others only requires two changes.

Which reminds me...to add enumerations for the next version ;)

Paul.
Ionic Wind Support Team

LarryMc

Thanks,

That's what I was looking for.

Don't ask me why I had never seen that in 30+ years of fooling around with computers.


Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Used in C everywhere.  Of course they don't use the same keyword.  And if you look in the official Windows include files (from MS) you'll see lots of:
...
#define WM_USER 0x400
#define WM_GETIT WM_USER+1
#define WM_SETIT WM_GETIT+1
...

For just about every control.

Paul.
Ionic Wind Support Team

LarryMc

Never used C.
Before getting into IB/EB never had any use for MS include files.

Seen a lot of:
#define WM_USER 0x400
#define WM_GETIT WM_USER+1
#define WM_SETIT WM_USER+2

Which is what I'm use to seeing in the API viewer.

but I guess I just never noticed where they used the preceeding + 1

Anyway,

Thanks

Larry




LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library