Simple, little trick with enumerations
Posted: Wed Nov 28, 2018 6:36 pm
Code: Select all
Enumeration
#Item_1
#Item_2
#Item_3
#Item_4
#Item_5
#Total_Entries ; automatically equals 5
EndEnumeration
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Enumeration
#Item_1
#Item_2
#Item_3
#Item_4
#Item_5
#Total_Entries ; automatically equals 5
EndEnumeration
Code: Select all
Enumeration
#Item_1
#Item_2
#Item_3
#Item_4
#Item_5
EndEnumeration
Total_Entries=#PB_Compiler_EnumerationValue
Code: Select all
Enumeration 10
#Item_1
#Item_2
#Item_3
#Total_Entries ; value will be 13 (will not be 3)
EndEnumeration
Code: Select all
dt = #PB_Compiler_Line
Enumeration 10
#Item_1
#Item_2
#Item_3
#Item_4
#Item_5
EndEnumeration
Debug #PB_Compiler_Line - dt - 3
Code: Select all
Macro enum2pow(_const_)
_const_ = (Bool(#PB_Compiler_EnumerationValue = 0) + Bool(#PB_Compiler_EnumerationValue > 0) * 2 * (#PB_Compiler_EnumerationValue - 1))
EndMacro
Enumeration
enum2pow(#c1)
enum2pow(#c2)
enum2pow(#c3)
enum2pow(#c4)
enum2pow(#c5)
enum2pow(#c6)
enum2pow(#c7)
EndEnumeration
Debug #c1
Debug #c2
Debug #c3
Debug #c4
Debug #c5
Debug #c6
Debug #c7
For this I use EnumerationBinaryNicTheQuick wrote:This is also a nice Enumeration trick to get powers of 2
Code: Select all
EnumerationBinary
#c1
#c2
#c3
#c4
#c5
#c6
#c7
EndEnumeration
Debug #c1
Debug #c2
Debug #c3
Debug #c4
Debug #c5
Debug #c6
Debug #c7
Nice... I totally missed this one in the manualJosh wrote: For this I use EnumerationBinary![]()
This is described in the help under Enumeration.Paul wrote:Nice... I totally missed this one in the manual
Josh wrote:For this I use EnumerationBinaryNicTheQuick wrote:This is also a nice Enumeration trick to get powers of 2![]()