Gambas France BETA


Pas de compte ? Incription

comment simplifier ce code

Ce sujet est résolu.

1
AuteurMessages
spheris#1 Posté le 11/2/2024 à 08:56:27
Bonjour,
commen simplifier ce code ci ?

J'ai 18 Label sur mon interface nommé respectivement lbl1 à lbl19 et je souhaite les insérer dans un tableau d'object comme ceci :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TableauPion[19] AS NEW OBJECT
TableauPion[0] = lbl1
TableauPion[1] = lbl2
TableauPion[2] = lbl3
TableauPion[3] = lbl4
TableauPion[4] = lbl5
TableauPion[5] = lbl6
TableauPion[6] = lbl7
TableauPion[7] = lbl8
TableauPion[8] = lbl9
TableauPion[9] = lbl10
TableauPion[10] = lbl11
TableauPion[11] = lbl12
TableauPion[12] = lbl13
TableauPion[13] = lbl14
TableauPion[14] = lbl15
TableauPion[15] = lbl16
TableauPion[16] = lbl17
TableauPion[17] = lbl18
TableauPion[18] = lbl19


On voit tout de suite l'utilité d'une boucle for earch ou for next mais ce code ci ne fonctionne pas:

1
2
3
4
DIM a AS INTEGER
FOR a = 0 TO 18
TableauPion[a] = "lbl" & (a + 1)
NEXT


Une idée?
Merci pour vos réponses.
valaquarus#2 Posté le 11/2/2024 à 18:41:22
-- Unus Ex Altera --Bonsoir Sphéris,

1
2
3
4
5
6
DIM labelText AS Variant[] = [l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13]


FOR i = 0 TO 13
labelText[i].Text = Format(iText[i], "#,###.##")
NEXT


Issue de howmuch4 de la forge.
Je n'ai pas été jusqu'à 18.
En espérant t'aider.
Système d'exploitation : KDE neon 6.0.2 ~ Version Gambas : 3.19.90
vuott#3 Posté le 11/2/2024 à 19:28:46
Ne cedere ineluctabili possimusLa variable tableau de type "Object" doit recevoir une variable de type "Label", et non le nom de l'identifiant.
En supposant que le "Label" soit placé directement sur le "Form" principal, je propose: :|
1
2
3
4
5
6
7
8
9
PUBLIC SUB Form_Open()

DIM llbb AS NEW Label[]

FOR EACH ob AS OBJECT IN ME.Children
IF Object.Type(ob) = "Label" THEN llbb.Push(ob)
NEXT

END
spheris#4 Posté le 12/2/2024 à 09:44:12
super!
1