iterate enumeration

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: iterate enumeration

Post by Bisonte »

mk-soft wrote:Everything's too expensive. Is a question of declaration...
:mrgreen: I know... But if you are work in a team, you can't see everytime the code from the other... ;)
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
mk-soft
Always Here
Always Here
Posts: 6208
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: iterate enumeration

Post by mk-soft »

There must be an agreement... 8)
Perhaps optimise it

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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Cyllceaux
Enthusiast
Enthusiast
Posts: 510
Joined: Mon Jun 23, 2014 1:18 pm

Re: iterate enumeration

Post by Cyllceaux »

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")

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.
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: iterate enumeration

Post by Bisonte »

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.
I mean, you add on every enum call an element... who knows the index what element is what 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.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
Cyllceaux
Enthusiast
Enthusiast
Posts: 510
Joined: Mon Jun 23, 2014 1:18 pm

Re: iterate enumeration

Post by Cyllceaux »

Bisonte wrote:
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.
I mean, you add on every enum call an element... who knows the index what element is what 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.

Oh.... Now I know what you mean… Sorry ;-)
Post Reply