Enumeration Multi constant definition in the same enum level

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Enumeration Multi constant definition in the same enum level

Post by Kurzer »

Hello Fred,
it would be great if you could add a feature to Enumeration to define several constants with the same value in the actual enumeration level. This could be look like this:

Code: Select all

	Enumeration 
		#ImageGadget, #Window, #Image
		#TextStatus
		#TextViewer
	EndEnumeration
In this case #ImageGadget, #Window and #Image would all be defined as 0. Then #TextStatus = 1, #TextViewer = 2

Kind regards
Kurzer
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Enumeration Multi constant definition in the same enum l

Post by davido »

@kurzer,

I don't know if you are aware that the manual states that it can be done thus:

Code: Select all

Enumeration 
  #ImageGadget
  #Window = #ImageGadget
  #Image = #ImageGadget
  #TextStatus
  #TextViewer
EndEnumeration

  Debug #ImageGadget
  Debug #Window
  Debug #Image
  Debug #TextStatus
  Debug #TextViewer
DE AA EB
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Enumeration Multi constant definition in the same enum l

Post by Kurzer »

davido,
thanks for the tip.
I know this kind of definition, this is how I solve it at the moment.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
Micoute
User
User
Posts: 24
Joined: Sat Jun 22, 2013 4:06 pm
Location: La Mézière FRANCE

Re: Enumeration Multi constant definition in the same enum l

Post by Micoute »

Code: Select all

Enumeration Windows
  #Window
EndEnumeration
Enumeration Gadgets
  #ImageGadget
  #TextStatus
  #TextViewer
EndEnumeration
Enumeration Images
  #Image
EndEnumeration

Debug #ImageGadget
Debug #Window
Debug #Image
Debug #TextStatus
Debug #TextViewer
__________________________________________________
Code tags added
23.04.2019
RSBasic
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Enumeration Multi constant definition in the same enum l

Post by Josh »

kurzer wrote:

Code: Select all

	Enumeration 
		#ImageGadget, #Window, #Image
		#TextStatus
		#TextViewer
	EndEnumeration
Writing windows, gadgets, images etc. into one enumeration is complete nonsense. Like Micoute wrote, each of these 'groups' belongs its own named Enumeration, which can be continued in any IncludeFile at any time.

Code: Select all

Enumeration Windows
  #MyWinA
  #MyWinB
EndEnumeration

Enumeration Gadgets
  #MyGadgetA
  #MyGadgetB
  #MyGadgetC
EndEnumeration

Enumeration Images
  #MyImageA
  #MyImageB
EndEnumeration

; In a other includefile

Enumeration Images
  #MyImageC
EndEnumeration
sorry for my bad english
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 666
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Enumeration Multi constant definition in the same enum l

Post by Kurzer »

Yes, I get the point.
My example was unfortunately not so well chosen.
The idea for this request just came to me when I wrote a small code that has only one window and one image, but several gadgets.

I could declare it that way:

Code: Select all

#Window = 0
#Image = 0

Enumeration
  #Gadget1
  #Gadget2
  #Gadget3 
  ;.. and so on
EndEnumeration
In this moemnt I found it "quite nice" if I could write it as shown in my first example.

But this request is not that important either. Possibly there would be use cases, where one can use this exactly in this form, but I'm afraid I can't think of one right now. ;)
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Enumeration Multi constant definition in the same enum l

Post by Michael Vogel »

Not sure if this will make you happy...

Code: Select all

Macro EnumAsAbove
	= #PB_Compiler_EnumerationValue-1 :
EndMacro

Enumeration 
	#A 
	#B EnumAsAbove #C  EnumAsAbove
	#D
EndEnumeration

Debug #A
Debug #B
Debug #C
Debug #D
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Enumeration Multi constant definition in the same enum l

Post by Sicro »

Code: Select all

Macro DefineConstants(_value_, _target1_, _target2_=PB_Ignore, _target3_=PB_Ignore, _target4_=PB_Ignore)
  #_target1_ = _value_
  CompilerIf Not Defined(_target2_, #PB_Constant) : #_target2_ = _value_ : CompilerEndIf
  CompilerIf Not Defined(_target3_, #PB_Constant) : #_target3_ = _value_ : CompilerEndIf
  CompilerIf Not Defined(_target4_, #PB_Constant) : #_target4_ = _value_ : CompilerEndIf
EndMacro

; Examples:

DefineConstants(10, a)
Debug #a

DefineConstants(10, b, c)
Debug #b
Debug #c
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Post Reply