In PowerBasic we can have Enums such as
ENUM ErrorHandling_Color 'Console Colors '<--- Console can only display 16 colors
Black_Dark = 0
Blue_Dark = 1
Green_Dark = 2
Cyan_Dark = 3
Red_Dark = 4
Magenta_Dark = 5
Brown_Dark = 6
White_Dark = 7
Gray_Light = 8
Blue_Light = 9
Green_Light = 10
Cyan_Light = 11
Red_Light = 12
Magenta_Light = 13
Yellow_Light = 14
White_Light = 15
END ENUM
I tried to port this to PureBasic
Enumeration ErrorHandling_Color
#Black_Dark = 0
#Blue_Dark = 1
#Green_Dark = 2
#Cyan_Dark = 3
#Red_Dark = 4
#Magenta_Dark = 5
#Brown_Dark = 6
#White_Dark = 7
#Gray_Light = 8
#Blue_Light = 9
#Green_Light = 10
#Cyan_Light = 11
#Red_Light = 12
#Magenta_Light = 13
#Yellow_Light = 14
#White_Light = 15
EndEnumeration
I tried with both using the # symbol and without but the compile error I get is
QuoteOnly Integer Constant Expressions allowed for an enumeration
Is there something I am doing wrong? or some other keyword that I would recognize as an PB-Enum ??
Almost 2 years later and still no reply?
I just started Purebasic again and whammo I hit the exact same problem again and no idea what I am doing wrong?
If you're going to define each constant why bother using enumerations? :)
Enumeration
#Black_Dark ; the first value is zero (default)
#Blue_Dark
#Green_Dark
#Cyan_Dark
#Red_Dark
#Magenta_Dark
#Brown_Dark
#White_Dark
#Gray_Light
#Blue_Light
#Green_Light
#Cyan_Light
#Red_Light
#Magenta_Light
#Yellow_Light
#White_Light
EndEnumeration
Debug #Green_Light ; answer displays 10... which is correct
Enumeration ErrorHandling_Color
#Black_Dark = 0
#Blue_Dark = 1
#Green_Dark = 2
#Cyan_Dark = 3
#Red_Dark = 4
#Magenta_Dark = 5
#Brown_Dark = 6
#White_Dark = 7
#Gray_Light = 8
#Blue_Light = 9
#Green_Light = 10
#Cyan_Light = 11
#Red_Light = 12
#Magenta_Light = 13
#Yellow_Light = 14
#White_Light = 15
EndEnumeration
Debug #Green_Light ; yields 10 the same as above
Cliff,
I re-tried your example and I don't get an error as you've entered it.
What version of PureBasic are you running? The latest is 5.31
--Bob
Odd, changing my above code to declare #ErrCheck_Color to the below seems to work???? (not sure what will happen when I go to use it though yet???)
#ErrCheck_Color = 1
Enumeration #ErrCheck_Color
#dBlack ;= 0
#dBlue ;= 1
#dGreen ;= 2
#dCyan ;= 3
#dRed ;= 4
#dMagenta ;= 5
#dBrown ;= 6
#dWhite ;= 7
#lGray ;= 8
#lBlue ;= 9
#lGreen ;= 10
#lCyan ;= 11
#lRed ;= 12
#lMagenta ;= 13
#lYellow ;= 14
#lWhite ;= 15
EndEnumeration
I am using an old PureBasic 4.60
No... #dBlack will be 1 not zero
Not sure what you're trying to accomplish??
If you set #ErrCheck_Color = 1 your first Enumeration will START at 1 (#dBlack will = 1)
The default STARTING POINT is zero, and STEP is = 1
so no parameter is required.
Enumeration
#dBlack ;= 0
#dBlue ;= 1
#dGreen ;= 2
#dCyan ;= 3
#dRed ;= 4
#dMagenta ;= 5
#dBrown ;= 6
#dWhite ;= 7
#lGray ;= 8
#lBlue ;= 9
#lGreen ;= 10
#lCyan ;= 11
#lRed ;= 12
#lMagenta ;= 13
#lYellow ;= 14
#lWhite ;= 15
EndEnumeration
You seem to want to name this "structure", but that's only if you want to "add" to it at a later time...
This is all explained in the Help file.
e.g.
Enumeration 3 STEP 2
#dBlack ;= 3
#dBlue ;= 5
#dGreen ;= 7
etc, etc
EndEnumeration
Debug #dBlack
Debug #dBlue
----------------------------------------------
PS - I'd update to 5.31, there's been a ton of improvements in 3 1/2 years.
Your version is from 7th November 2011
Updates are free FOREVER... why wouldn't you?