Re: iterate enumeration
Posted: Sat Mar 23, 2019 12:01 pm
mk-soft wrote:Everything's too expensive. Is a question of declaration...


http://www.purebasic.com
https://www.purebasic.fr/english/
mk-soft wrote:Everything's too expensive. Is a question of declaration...
Code: Select all
;- Always on top of enumeration
Enumeration Gadgets -1
#_BeginOfGadget
EndEnumeration
#BeginOfGadgets = #_BeginOfGadget + 1
Enumeration Gadgets
#Gadget0
#Gadget1
#Gadget2
#Gadget3
EndEnumeration
Enumeration Gadgets
#Gadget4
#Gadget5
#Gadget6
#Gadget7
EndEnumeration
;- Always bottom of enumeration
Enumeration Gadgets
#_EndOfGadget
EndEnumeration
#EndOfGadgets = #_EndOfGadget - 1
For i = #BeginOfGadgets To #EndOfGadgets
Debug i
Next
Bisonte wrote:I like the code of Cyllceaux, but it's useless if you need several enumerations. Therefore the whole thing with maps :
Code: Select all
Macro DoubleQuote " EndMacro Macro iEnum(EnumerationName, Constant, Value=) Enumeration EnumerationName#Enum Constant Value EndEnumeration CompilerIf Not Defined(LastEnum, #PB_Map) Global NewMap LastEnum() CompilerEndIf LastEnum(Trim(DoubleQuote#EnumerationName#DoubleQuote)) = #PB_Compiler_EnumerationValue - 1 EndMacro iEnum(Gadget, #a, = 1) iEnum(Gadget, #b) iEnum(Gadget, #c) iEnum(Gadget, #d) iEnum(Window, #wa) iEnum(Window, #wb) Debug LastEnum("Gadget") Debug LastEnum("Window")
I mean, you add on every enum call an element... who knows the index what element is what enum ?Cyllceaux wrote: Why useless? It workes with several enums… Or I don't understand what you mean…
The first Parameter of the macro defines the name of the enum.
Bisonte wrote:I mean, you add on every enum call an element... who knows the index what element is what enum ?Cyllceaux wrote: Why useless? It workes with several enums… Or I don't understand what you mean…
The first Parameter of the macro defines the name of the enum.
See at my (your)code, and you see it's nearly the same, exept that you use a List and I use a Map...
so you can find the right enum fast to get the last enumerationvalue.