Get the bigger used enumeration [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Get the bigger used enumeration [Resolved]

Post by Kwai chang caine »

Hello at all

Have you a way for obtain the LAST enumeration PB have given ?
I have try

Code: Select all

Enumeration #PB_Compiler_EnumerationValue
but unfortunately the number is already exist :|
I have try

Code: Select all

Enumeration #PB_Any
without really believing in it, and that's worse :|

And when i use a big number, like

Code: Select all

Enumeration 10000
for be sure this number is not used (An again i'm not really sure :oops:) i have an error, the IDE ask if i'm sure ? :? obviously i'm sure :twisted:

Have a good day
Last edited by Kwai chang caine on Fri Feb 13, 2026 10:02 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 530
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Get the bigger used enumeration

Post by Mindphazer »

Hi KCC
According to the manual, the reserved constant #PB_Compiler_EnumerationValue store the next value which will be used in the enumeration. It can be useful to get the last enumeration value or to chain two enumerations.

Code: Select all

Enumeration
    #GadgetInfo ; égale à 0
    #GadgetText ; égale à 1
    #GadgetOK   ; égale à 2
EndEnumeration
  
Enumeration #PB_Compiler_EnumerationValue
  #Test1
  #Test2
  #Test3
EndEnumeration

Debug "#Test1 = " + Str(#Test1)
Debug "#Test2 = " + Str(#Test2)
Debug "#Test3 = " + Str(#Test3)
Result :

Code: Select all

#Test1 = 3
#Test2 = 4
#Test3 = 5
That's the expected result. #Test1 starts with value 3
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
NicTheQuick
Addict
Addict
Posts: 1575
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Get the bigger used enumeration

Post by NicTheQuick »

Why exactly do you want that? For what purpose do you use these numbers?
If someone asks such questions it mostly means there is a better way to solve the problem.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get the bigger used enumeration

Post by Kwai chang caine »

Hello at you two and thanks for your quick answer 8)

@Mindphazer
Me i believed stupidly that the compiler memorize the last number in all the code and give it with this constant :oops:
Apparently not :|

@NicTheQuick
I try to modify an ENORMOUS code not written by me :oops: but by a TRUE programmer :mrgreen: and that's true watchmaking, all is thinking for be the best :shock:
With hundreds and hundreds constants
And yesterday i believe i have breaken the toy :oops: because when i click on a button or menu, that do other thing :shock:
After 2 hours of search and even sometime delete my modifications i understand several constants have the same values, or worst sometime all menu is deca'ed...
Then i say to me, the best is to give to my own constant a unic number for be sure not have again colisions :wink:
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
spikey
Addict
Addict
Posts: 806
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Get the bigger used enumeration

Post by spikey »

You can achieve what you want with named enumerations, the compiler tracks the sequence separately across different names:

Code: Select all

Enumeration FIRST 1
  #F1st
  #F2nd
  #F3rd
EndEnumeration

Enumeration SECOND 1
  #One
  #Two
  #Three
  #Four
  #Five
EndEnumeration

Enumeration FIRST 
  #F4th
  #F5th
  #F6th
  #F7th
EndEnumeration

Enumeration SECOND
  #Six
  #Seven
  #Eight
  #Nine
  #Ten
EndEnumeration

Debug "First:"
Debug #F1st
Debug #F2nd
Debug #F3rd
Debug #F4th
Debug #F5th
Debug #F6th
Debug #F7th

Debug "Second:"
Debug #One
Debug #Two
Debug #Three
Debug #Four
Debug #Five
Debug #Six
Debug #Seven
Debug #Eight
Debug #Nine
Debug #Ten
User avatar
NicTheQuick
Addict
Addict
Posts: 1575
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Get the bigger used enumeration

Post by NicTheQuick »

First you have to distinguish the different namespaces for IDs in Purebasic. I can not list all of them out of my head but here are some examples:
  • Windows
  • Gadgets
  • Images
  • Sprites
  • ...
Then you can use named enumerations to have lists for each kind of objects in Purebasic like so:

Code: Select all

Enumeration Windows
	#main_window
	#about_window
EndEnumeration

Enumeration Gadgets
	#main_content
	#search_button
EndEnumeration

; a lot of other codes or even includes

Enumeration Windows
	#search_window
EndEnumeration

Enumeration Gadgets
	#search_bar
	#replace_bar
EndEnumeration


Debug "main_window: " + #main_window
Debug "about_window: " + #about_window
Debug "search_window: " + #search_window
This way you can create continuous IDs for each type of objects.

And in case you have an application where you need a dynamic number of gadgets or windows or whatever you should consider using `#PB_Any` instead of static IDs and store the resulting handle in a list, map, array or whatever suits you usecase.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get the bigger used enumeration

Post by Kwai chang caine »

Waouuuhh !!! :shock:
I have perhaps see the NAMESPACE at the begining, but full forgotten and never use it since this time, incredible !!! 8)
Thanks for this tips, i try to never forgot it at new :oops: :?

The problem is i can't modifiy this gigantic code, less i touch it, more he works :mrgreen:
Because my starting goal, was to ask at the debugger his LAST enumeration :wink:
Then i have thinking to that, if there aren't a native way :oops:
In fact it's also like this, that in the code, the MASTER do for "reserve" places :idea:

Code: Select all

Enumeration
 #NiceConstantOfTrueProgrammer1
 #NiceConstantOfTrueProgrammer2
 #NiceConstantOfTrueProgrammer3
 #MaxNiceConstant1
EndEnumeration

Enumeration 2
 #NiceConstantOfTrueProgrammer4
 #NiceConstantOfTrueProgrammer5
 #NiceConstantOfTrueProgrammer6
 #MaxNiceConstant2
EndEnumeration

Debug "Before... when the sunshine and the birds chirp" + #CRLF$
Debug #NiceConstantOfTrueProgrammer1
Debug #NiceConstantOfTrueProgrammer2
Debug #NiceConstantOfTrueProgrammer3
Debug #NiceConstantOfTrueProgrammer4
Debug #NiceConstantOfTrueProgrammer5
Debug #NiceConstantOfTrueProgrammer6

Debug "Now KCC open the nice code of TRUE programmer"
Debug "and put his dirty constants :-(" + #CRLF$ 

Enumeration #MaxNiceConstant1 + #MaxNiceConstant2
 #DirtyConstantOfKcc1
 #DirtyConstantOfKcc2
 #DirtyConstantOfKcc3
EndEnumeration

Debug "After the chaos...KCC twister" + #CRLF$ 
Debug #DirtyConstantOfKcc1
Debug #DirtyConstantOfKcc2
Debug #DirtyConstantOfKcc3

ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Get the bigger used enumeration

Post by mk-soft »

It makes sense to go through the code and use Named Enumerations.

Window or gadget enumeration high numbers to start leads to very large internal array with plenty of empty space
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get the bigger used enumeration

Post by Kwai chang caine »

Thanks a lot for your precious advice MkSoft 8)
I didn't know that too :oops:
It's a pity there not exist a way for see how much value of constants equal 10 (For exampler) :|
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Get the bigger used enumeration [Resolved]

Post by mk-soft »

If I take enumerations or named enumerations, I am not interested in the value and is also not relevant to the code.

Only that I have clean statement strong names in code.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get the bigger used enumeration [Resolved]

Post by Kwai chang caine »

Yes, it's a shame that the source code I'm modifying doesn't use this convention; it's too late to add it now with the hundreds of constants, thousands of lines, and modifying even one of them risks losing a function or create a bug :oops:
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Randy Walker
Addict
Addict
Posts: 1248
Joined: Sun Jul 25, 2004 4:21 pm
Location: USoA
Contact:

Re: Get the bigger used enumeration [Resolved]

Post by Randy Walker »

Wow. I can't say I understand the question or goal. What is it you are trying to do?
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Nothing is faster, more stable, or easier to maintain than code that doesn’t exist. :mrgreen:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5658
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get the bigger used enumeration [Resolved]

Post by Kwai chang caine »

Hello Randy :D

In fact it's very simple, i hou have a very very very big code with numerous thousand of lines, several hundred of constants etc ...
That the NAMESPACE have not be used in the old code, and you not want or can perturbate it when you adding new constants
When you manage an event or call something, the constant must be unique, for be sure when you say to the compiler you want to eat something, it don't put the spoon in your eye, but preferably in your mouth :lol: . i thinking it's a pity that not exist something like #PB_Compiler_ConstantMaxValue where inside you have the MAXIMUM value that the compiler attribute :idea:
Stupidly i believe #PB_Compiler_EnumerationValue play this role, but no :oops:

Like this you can do :

Code: Select all

 ; Old good code
Enumeration
 #ConstantOfVeryVeryVeryBigCode1
 #ConstantOfVeryVeryVeryBigCode2
 etc ..
EndEnumeration
 
; New code
Enumeration #PB_Compiler_ConstantMaxValue
 #ConstantKccNew1
 #ConstantKccNew2
 etc...
EndEnumeration
Like this impossible to have collisions, and avoid the risk of too big numbers , like MkSoft explain to me :wink:
And also not get yelled at by the compiler because the number is too big :?

Code: Select all

Enumeration 10000 ; For be sure this number is not used
 #ConstantKccNew1
 #ConstantKccNew2
 etc...
 EndEnumeration
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2163
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Get the bigger used enumeration [Resolved]

Post by Andre »

Maybe the sense of named enumerations (to be used with window, gadget,... IDs) can be better described in the related topic: https://www.purebasic.com/documentation ... tions.html

And the OpenWindow(), xxxGadget() and similar command descriptions should link to this topic in their "#ID" description.

What do you mean :?:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Axolotl
Addict
Addict
Posts: 935
Joined: Wed Dec 31, 2008 3:36 pm

Re: Get the bigger used enumeration [Resolved]

Post by Axolotl »

Regarding some of the statements, I would say:
It's a question of personal programming style.
However, I believe that, in addition to functionality, “clean” implementation is also a decisive quality criterion.
To be honest, though, I stopped imposing my coding style on others a long time ago.
Long story short:
I always use named enumerations. Advantage: You can also continue the enumerations (e.g., in include files).

A little tip on the side:
Sometimes I use macros to get all enums.
Not a complete example, just meant to show the idea behind it.

Code: Select all

EnableExplicit ; <= my favorite command!! 
; ..... in the main source File .....  

Enumeration EWindow 1 ; begins with 1 and ZERO is the invalid or error 
  #WND_Main           ; <= my application window "Name" is important not the value !! 
  #WND_Details 
  #WND_Trace  
EndEnumeration 
Macro Lo_Window : 1 : EndMacro 
Macro Hi_Window : (#PB_Compiler_EnumerationValue - 1) : EndMacro

; ..... in a different source File .....  

Enumeration EWindow ; continued 
  #WND_DescriptionEditor  ; 
EndEnumeration 
UndefineMacro Hi_Window : Macro Hi_Window : (#PB_Compiler_EnumerationValue - 1) : EndMacro 

; ..... in a different source File .....  

; ; work on all available windows .... 
; For wndNumber = Lo_Window To Hi_Window 
;   HideWindow(wndNumber, #False) ; show all windows !! 
; Next 
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