Win X64 - PB6.11/6.12 - Named Enumeration with Step

Just starting out? Need help? Post your questions and find answers here.
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by pjay »

This could belong in Coding Questions, as it might be a misunderstanding, but the following 3 snippets produce different errors:

Code: Select all

Enumeration Gadgets Step 3
  #MyGad_0
  #MyGad_3
EndEnumeration

; [08:09:51] [COMPILER] Line 1: Only integer constant expressions allowed for an Enumeration.

Code: Select all

EnableExplicit
Enumeration Gadgets Step 3
  #MyGad_0
  #MyGad_3
EndEnumeration

; [08:10:28] [COMPILER] Line 2: With 'EnableExplicit', variables have to be declared: p.

Code: Select all

Enumeration Gadgets
  #MyGad_0
  #MyGad_1
EndEnumeration

Enumeration Gadgets Step 3 ; Text / TrackBar / Value
  #MyGad_3
  #MyGad_6
  #MyGad_9
EndEnumeration

; [08:11:06] [COMPILER] Line 6: Enumeration 'Gadgets' already declared: initial attributes can't be modified.
PeDe
Enthusiast
Enthusiast
Posts: 305
Joined: Sun Nov 26, 2017 3:13 pm

Re: Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by PeDe »

You have forgotten a parameter that is not optional:

Code: Select all

Enumeration Gadgets _0_ Step 3

Peter
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

Re: Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by pjay »

But the enumeration name 'Gadgets' should be treated as the start value parameter, should it not?

Otherwise there's no way to benefit from the Named enumeration whilst also using the Step operator.
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by Demivec »

pjay wrote: Sun Sep 15, 2024 8:47 am But the enumeration name 'Gadgets' should be treated as the start value parameter, should it not?

Otherwise there's no way to benefit from the Named enumeration whilst also using the Step operator.
No it should not.

An enumeration has several qualities:
  • A starting value
  • A step value (this may be a binary multiplication step option instead of an addition)
  • While enumeration is being done the constant #PB_Compiler_EnumerationValue holds the next value to be assigned
A named enumeration records each of these values. The values will be used in future enumeration blocks by simply specifying the enumeration name (and only the name).

If you use the Step operator with a named enumeration it can only be used on the initial enumeration block. Subsequent ones only reference the step and current enumeration value already in progress.

You can obtain the same functionality of changing the Step with just a little more work, like so:

Code: Select all

Enumeration Gadgets
  #MyGad_0
  #MyGad_1
EndEnumeration

Enumeration Gadgets ; Text / TrackBar / Value
  ;Step 3
  #MyGad_4 = #PB_Compiler_EnumerationValue + 2
  #MyGad_7 = #PB_Compiler_EnumerationValue + 2
  #MyGad_10 = #PB_Compiler_EnumerationValue + 2
EndEnumeration

Debug #MyGad_0  ;0
Debug #MyGad_1  ;1
Debug #MyGad_4  ;4
Debug #MyGad_7  ;7
Debug #MyGad_10 ;10
I would also point out that for object IDs there is a disadvantage for skipping IDs because memory space is allocated according to the highest object ID used for a given object type even when the lower IDs are not all in use.
pjay
Enthusiast
Enthusiast
Posts: 277
Joined: Thu Mar 30, 2006 11:14 am

Re: Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by pjay »

Thanks for the detail. I understand the basics but I'd never tried using these two together before.

So you can benefit from Named enumerations and Step in the first instantiation only & they're mutually exclusive after this point - I wonder why this limitation exists.
I would also point out that for object IDs there is a disadvantage for skipping IDs because memory space is allocated according to the highest object ID used for a given object type even when the lower IDs are not all in use.
I wasn't skipping them, they were bases for multiple gadgets.
Axolotl
Addict
Addict
Posts: 872
Joined: Wed Dec 31, 2008 3:36 pm

Re: Win X64 - PB6.11/6.12 - Named Enumeration with Step

Post by Axolotl »

I would stick to the syntax given in the help. As PeDe already wrote:

This is how it should be used:

Code: Select all

; Enumeration [name] [<constant> [Step <constant>]] 
With this in mind, why not doing this. (See the ERROR Info if you do it wrong!)
Here is what I get out of it:

Code: Select all

Enumeration EGadget 1 Step 2 
  #GADGET_1
  #GADGET_2
  #GADGET_3
EndEnumeration 

Debug " 1  : " + #GADGET_1
Debug " 2  : " + #GADGET_2
Debug " 3  : " + #GADGET_3
Debug "Last: " + #PB_Compiler_EnumerationValue 


;ERROR: Enumeration EGadget #PB_Compiler_EnumerationValue Step 2 
; Line 18: Enumeration 'EGadget' already declared: initial attributes can't be modified.

Enumeration EGadget ; <-- this works with initial attributes from above ???? 
  #GADGET_4
  #GADGET_5
  #GADGET_6
EndEnumeration 

Debug " 4  : " + #GADGET_4
Debug " 5  : " + #GADGET_5
Debug " 6  : " + #GADGET_6
Debug "Last: " + #PB_Compiler_EnumerationValue 

; ---------------------------
; Debug Output    
; ---------------------------
; 
;  1  : 1
;  2  : 3
;  3  : 5
; Last: 7
;  4  : 7
;  5  : 9
;  6  : 11
; Last: 13 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply