Page 1 of 2
Get the bigger used enumeration [Resolved]
Posted: Fri Feb 13, 2026 1:47 pm
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
without really believing in it, and that's worse
And when i use a big number, like
for be sure this number is not used (An again i'm not really sure

) i have an error, the IDE ask if i'm sure ?

obviously i'm sure
Have a good day
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 2:05 pm
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 :
That's the expected result. #Test1 starts with value 3
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 2:09 pm
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.
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 2:51 pm
by Kwai chang caine
Hello at you two and thanks for your quick answer
@Mindphazer
Me i believed stupidly that the compiler memorize the last number in all the code and give it with this constant

Apparently not
@NicTheQuick
I try to modify an ENORMOUS code not written by me

but by a TRUE programmer

and that's true watchmaking, all is thinking for be the best
With hundreds and hundreds constants
And yesterday i believe i have breaken the toy

because when i click on a button or menu, that do other thing

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

Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 3:33 pm
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
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 3:49 pm
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.
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 5:02 pm
by Kwai chang caine
Waouuuhh !!!
I have perhaps see the NAMESPACE at the begining, but full forgotten and never use it since this time, incredible !!!

Thanks for this tips, i try to never forgot it at new
The problem is i can't modifiy this gigantic code, less i touch it, more he works
Because my starting goal, was to ask at the debugger his LAST enumeration
Then i have thinking to that, if there aren't a native way
In fact it's also like this, that in the code, the MASTER do for "reserve" places
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
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 5:40 pm
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
Re: Get the bigger used enumeration
Posted: Fri Feb 13, 2026 6:32 pm
by Kwai chang caine
Thanks a lot for your precious advice MkSoft
I didn't know that too
It's a pity there not exist a way for see how much value of constants equal 10 (For exampler)

Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 12:30 am
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.
Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 8:43 am
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

Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 9:22 am
by Randy Walker
Wow. I can't say I understand the question or goal. What is it you are trying to do?
Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 10:57 am
by Kwai chang caine
Hello Randy
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

. 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
Stupidly i believe
#PB_Compiler_EnumerationValue play this role, but no
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

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
Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 11:32 am
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

Re: Get the bigger used enumeration [Resolved]
Posted: Sat Feb 14, 2026 12:43 pm
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