Author Topic: PureBasic - Enumerations  (Read 4811 times)

0 Members and 1 Guest are viewing this topic.

Cliff Nichols

  • Guest
PureBasic - Enumerations
« on: October 29, 2013, 10:25:28 PM »
In PowerBasic we can have Enums such as
Code: [Select]
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
Code: [Select]
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
Quote
Only 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 ??

Cliff Nichols

  • Guest
Re: PureBasic - Enumerations
« Reply #1 on: February 17, 2015, 09:29:37 PM »
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?

Offline Bob Houle

  • Newbie
  • *
  • Posts: 41
  • User-Rate: +3/-3
  • "It was too lonely at the top."
Re: PureBasic - Enumerations
« Reply #2 on: February 17, 2015, 11:25:18 PM »
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

Offline Bob Houle

  • Newbie
  • *
  • Posts: 41
  • User-Rate: +3/-3
  • "It was too lonely at the top."
Re: PureBasic - Enumerations
« Reply #3 on: February 17, 2015, 11:41:34 PM »
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

Cliff Nichols

  • Guest
Re: PureBasic - Enumerations
« Reply #4 on: February 19, 2015, 04:35:49 PM »
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



Offline Bob Houle

  • Newbie
  • *
  • Posts: 41
  • User-Rate: +3/-3
  • "It was too lonely at the top."
Re: PureBasic - Enumerations
« Reply #5 on: February 20, 2015, 04:01:26 PM »
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?