Gambas-it

Gambas3 => Domande tecniche => Topic aperto da: vuott - 15 Settembre 2013, 18:01:13

Titolo: Enum: esempio di suo utilizzo
Inserito da: vuott - 15 Settembre 2013, 18:01:13
Riporto questa discussione apparsa nella Mailing List ufficiale relativamente alla parola chiave Enum, che, come riporta la guida in linea, dichiara un'enumerazione (o lista numerata, conteggio):


" Is there a selfexplaining, simpleand clear examplecode available using ENUM ?
The docs example are not sufficient for my weak head.

wally
"


" Really? You use Enum as a more convenient way to declare integer constants:

---

Codice: gambas [Seleziona]
' The file permission numerical constants
Private Const PERM_EXEC  As Integer = 1
Private Const PERM_WRITE As Integer = 2
Private Const PERM_READ     As Integer = 4


---

simply becomes

---

Codice: gambas [Seleziona]
Private Enum PERM_EXEC = 1, PERM_WRITE = 2, PERM_READ = 4


---

with the additional ability to have implicit sequences:

---

Codice: gambas [Seleziona]
' Counting
Private Const Zero As Integer = 0
Private Const One  As Integer = 1
Private Const Two  As Integer = 2


---

will be

---

Codice: gambas [Seleziona]
Private Enum Zero, One, Two


---

The first value, if not explicitely given, defaults to 0. The n+1-st value
becomes the n-th value plus 1.

Please, make your own example code of it if you want...

Regards,
Tobi