Page 1 sur 1

Dim a l'interieur structure, comment faire ?

Publié : jeu. 07/juin/2007 19:50
par Fig
Bonjour,
Je voudrais faire cela:

Code : Tout sélectionner

  Structure xy
    x.l
    y.l
    zone.b
    numero.b
    Dim face.b(3,3,30)
  EndStructure

  NewList CTirage.xy()

addelement(CTirage())
CTirage\face(1,2,3)=12

il y a un moyen ? (ie mettre un tableau dans une structure puis affecter cela a une liste dynamique)

Re: Dim a l'interieur structure, comment faire ?

Publié : jeu. 07/juin/2007 20:18
par Progi1984
Essaie ca :

Code : Tout sélectionner

  Structure xy
    x.l
    y.l
    zone.b
    numero.b
    face.b[3,3,30]
  EndStructure

  NewList CTirage.xy()

addelement(CTirage())
CTirage\face(1,2,3)=12


Publié : jeu. 07/juin/2007 20:49
par Flype
@progi1984

oui mais non, çà marche pas.
ce que tu montres fonctionne pour une tableau à UNE dimension.

pour un tableau multi dimension, je m'y prendrais comme çà à moins de trouver mieux. enfin c'est déjà pas si mal :

Code : Tout sélectionner

;- 
;- initialisation
;- 

#MAX_FACE1 = 3
#MAX_FACE2 = 3
#MAX_FACE3 = 30

Structure xyFACE3
  c.l
EndStructure
Structure xyFACE2
  b.xyFACE3[#MAX_FACE3]
EndStructure
Structure xyFACE1
  a.xyFACE2[#MAX_FACE2]
EndStructure
Structure xy
  x.l
  y.l
  zone.b
  numero.b
  face.xyFACE1[#MAX_FACE1]
EndStructure

Macro face(x, y, z)
  CTirage()\face[x]\a[y]\b[z]\c
EndMacro

;- 
;- example
;- 

NewList CTirage.xy()

If AddElement(CTirage())
  
  ; Set
  
  For a = 0 To #MAX_FACE1 - 1
    For b = 0 To #MAX_FACE2 - 1
      For c = 0 To #MAX_FACE3 - 1
        face(a, b, c) = Random(1000)
      Next c
    Next b
  Next a
  
  face(1, 0, 7) = 777777777
  face(1, 0, 8) = 888888888
  face(1, 0, 9) = 999999999
  
  ; Get
  
  For a = 0 To #MAX_FACE1 - 1
    For b = 0 To #MAX_FACE2 - 1
      For c = 0 To #MAX_FACE3 - 1
        Debug "face(" + Str(a) + "," + Str(b) + "," + Str(c) + ") = " + Str(face(a, b, c))
      Next c
    Next b
  Next a
  
EndIf

Publié : jeu. 07/juin/2007 20:56
par lionel_om
Ou sinon avec :

Code : Tout sélectionner

  Structure xy
    x.l
    y.l
    zone.b
    numero.b
    face.b[3*3*30]
  EndStructure
Et accéder aux éléments avec une petite fonction facile à coder...
Mais c'est moins "classe" !

Lio

Publié : ven. 08/juin/2007 1:02
par minirop
il ne faut pas oublier que :
Dim a.s(5)
est un tableau de 6 chaines de caratères, alors que :
Structure X
a.s[5]
EndStructure
ne contient que 5 chaines de caratères

Publié : sam. 09/juin/2007 0:21
par Guimauve
lionel_om a écrit :Ou sinon avec :

Code : Tout sélectionner

  Structure xy
    x.l
    y.l
    zone.b
    numero.b
    face.b[3*3*30]
  EndStructure
Et accéder aux éléments avec une petite fonction facile à coder...
Mais c'est moins "classe" !

Lio
J'ai programmé un matrice 4X4 avec un tableau à une dimension et parcourir le tableau 1D comme un 2D ça donne quelque chose comme suit :

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Notes : Matrix44
;
; La matrice se présente sous la forme suivante :
;
; Éléments Matrice     -->  Index du tableau 1D
; 4x4 = 16 éléments    -->  16 case de 0 à 15
;  
; [e11, e12, e13, e14] -->  [00, 01, 02, 03] 
; [e21, e22, e23, e24] -->  [04, 05, 06, 07]
; [e31, e32, e33, e34] -->  [08, 09, 10, 11]
; [e41, e42, e43, e44] -->  [12, 13, 14, 15]
; 
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Structure Matrix44
  
  Elements.d[16] ; e11,e12,e13,e14, e21,e22,e23,e24, e31,e32,e33,e34, e41,e42,e43,e44
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Prototype de parcours Ligne-Colonne

For Line = 0 To 15 Step 4
  
   Debug "Coordonnée diagonale :" + Str(Line + offset)
  
   For Row = 0 To 3
    
     Debug Line + Row
    
   Next
  
   Debug "Changement de ligne"
   offset + 1
  
Next
Pour 2 dimensions c'est pas si mal. En 3D, c'est le même principe mais plus complexe. Et en 4D ou plus c'est infernal. Mais c'est possible.

Il a déja été suggéré d'autoriser les tableaux multiples dans les structures. Sans réponse pour l'instant.

A+
Guimauve

Publié : dim. 10/juin/2007 4:52
par Guimauve
La méthode pour avoir un tableau avec dimension multiple est celle dont Flype à fait la démonstration. Et voiçi un autre exemple jusqu'à 4 dimensions.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Tableau statique 1D-2D-3D-4D
; Fichier : Démonstration
; Version : 1.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 09-06-2007
; Mise à jour : 09-06-2007
; Codé avec PureBasic V4.02
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#ARRAY1D_MAX = 4
#ARRAY2D_MAX = 4
#ARRAY3D_MAX = 4
#ARRAY4D_MAX = 4

Structure Array1D
  
  Element1D.d[#ARRAY1D_MAX]
  
EndStructure

Structure Array2D
  
  Element2D.Array1D[#ARRAY2D_MAX]
  
EndStructure

Structure Array3D
  
  Element3D.Array2D[#ARRAY3D_MAX]
  
EndStructure

Structure Array4D
  
  Element4D.Array3D[#ARRAY4D_MAX]
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Macros d'accès <<<<<

Macro AccessArray1D(ArrayA, i)
  
  ArrayA\Element1D[i]
  
EndMacro

Macro AccessArray2D(ArrayA, i, j)
  
  ArrayA\Element2D[j]\Element1D[i]
  
EndMacro

Macro AccessArray3D(ArrayA, i, j, k)
  
  ArrayA\Element3D[k]\Element2D[j]\Element1D[i]
  
EndMacro

Macro AccessArray4D(ArrayA, i, j, k, l)
  
  ArrayA\Element4D[l]\Element3D[k]\Element2D[j]\Element1D[i]
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<

Alpha.Array4D

For Index1D = 0 To #ARRAY1D_MAX - 1
  For Index2D = 0 To #ARRAY2D_MAX - 1
    For Index3D = 0 To #ARRAY3D_MAX - 1
      For Index4D = 0 To #ARRAY4D_MAX - 1
        AccessArray4D(Alpha, Index1D, Index2D, Index3D, Index4D) = (Index1D + Index2D + Index3D + Index4D) * #PI 
      Next
    Next
  Next
Next

For Index1D = 0 To #ARRAY1D_MAX - 1
  For Index2D = 0 To #ARRAY2D_MAX - 1
    For Index3D = 0 To #ARRAY3D_MAX - 1
      For Index4D = 0 To #ARRAY4D_MAX - 1
        Debug "(" + Str(Index1D) + ", " + Str(Index2D) + ", " + Str(Index3D) + ", " + Str(Index4D) + ") = " + StrD(AccessArray4D(Alpha, Index1D, Index2D, Index3D, Index4D), 6)
      Next
    Next 
  Next
Next

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<