j'ai besoin d'une structure comportant un tableau double
Code : Tout sélectionner
Structure KeyboardParam
KeyboardDim.l[#MaxKeyPerLine][#MaxLine] ;
EndStructure
Voilà si quelqu'un connais la reponse je l'en remerci d'avance
Thy
Code : Tout sélectionner
Structure KeyboardParam
KeyboardDim.l[#MaxKeyPerLine][#MaxLine] ;
EndStructure
Code : Tout sélectionner
Structure machinchouette
maxkeyperline.l[#MaxKeyPerLine]
EndStructure
Structure KeyboardParam
KeyboardDim.machinchouette[#MaxLine]
EndStructure
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Tableau statique 1D-2D-3D-4D-5D
; Fichier : Démonstration
; Version : 1.0.1
; Programmation : OK
; Programmé par : Guimauve
; Date : 09-06-2007
; Mise à jour : 27-10-2007
; Codé avec PureBasic V4.10
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#ARRAY1D_MAX = 5
#ARRAY2D_MAX = 5
#ARRAY3D_MAX = 5
#ARRAY4D_MAX = 5
#ARRAY5D_MAX = 5
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
Structure Array5D
Element5D.Array4D[#ARRAY5D_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
Macro AccessArray5D(ArrayA, i, j, k, l, m)
ArrayA\Element5D[m]\Element4D[l]\Element3D[k]\Element2D[j]\Element1D[i]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
Alpha.Array5D
For Index5D = 0 To #ARRAY5D_MAX - 1
For Index4D = 0 To #ARRAY4D_MAX - 1
For Index3D = 0 To #ARRAY3D_MAX - 1
For Index2D = 0 To #ARRAY2D_MAX - 1
For Index1D = 0 To #ARRAY1D_MAX - 1
AccessArray5D(Alpha, Index1D, Index2D, Index3D, Index4D, Index5D) = (Index1D + Index2D + Index3D + Index4D + Index5D) * #PI
Next
Next
Next
Next
Next
For Index5D = 0 To #ARRAY5D_MAX - 1
For Index4D = 0 To #ARRAY4D_MAX - 1
For Index3D = 0 To #ARRAY3D_MAX - 1
For Index2D = 0 To #ARRAY2D_MAX - 1
For Index1D = 0 To #ARRAY1D_MAX - 1
Debug "(" + Str(Index1D) + ", " + Str(Index2D) + ", " + Str(Index3D) + ", " + Str(Index4D) + ", " + Str(Index5D) + ") = " + StrD(AccessArray5D(Alpha, Index1D, Index2D, Index3D, Index4D, Index5D), 6)
Next
Next
Next
Next
Next
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
A oui pas bête j'avais pas penser a ça. C'est vrai que je pensais que les doubles tableaux étaient suporter dans les structures. mais si ce n'est pas le cas c'est une bonne idée que tu proposes je vais tester çaposhu a écrit :Ok, j'ai jamais vraiment eu besoin d'un tableau à plusieurs dimension dans une structure, mais ta question m'a fait sortir un petit bricolage de la tete (je sais, le bricolage c'est jamais la solution, mais là j'ai pas mieux. Ca viendra peut etre dans la journée)... Je ferais ca, tout betement:
note pour moi meme: faut que je chope le colorer pour ce forum.Code : Tout sélectionner
Structure machinchouette maxkeyperline.l[#MaxKeyPerLine] EndStructure Structure KeyboardParam KeyboardDim.machinchouette[#MaxLine] EndStructure
merci !! désolé j'avais commencé a repondre a poshu et mon gamin est tombé malade ça fait des heures que ma reponse pour poshu était en attente et du coup j'ai pas vu le tient.Guimauve a écrit :À l'heure actuelle dans PB c'est le seul moyen pour avoir un tableau avec 2 dimension ou plus.
Petit exemple jusqu'à 5 dimensions.
A+
Guimauve
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Le nom du projet ici
; Fichier : Source principal
; Version : 0.0.0
; Programmation : À compléter
; Programmé par : Guimauve
; Date : 24-11-2007
; Mise à jour : 24-11-2007
; Codé avec PureBasic V4.10
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#MaxKeyPerLine = 3
#MaxLine = 50
Structure KeyboardParam1D
Element1D.l[#MaxKeyPerLine]
EndStructure
Structure KeyboardParam
Element2D.KeyboardParam1D[#MaxLine]
EndStructure
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Macros d'accès <<<<<
Macro KeyboardParam(KeyboardParamA, Ligne, Colonne)
KeyboardParamA\Element2D[Colonne]\Element1D[Ligne]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<
Macro SetKeyboardParam(KeyboardParamA, Ligne, Colonne, P_Param)
KeyboardParamA\Element2D[Colonne]\Element1D[Ligne] = P_Param
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<
Macro GetKeyboardParam(KeyboardParamA, Ligne, Colonne)
KeyboardParamA\Element2D[Colonne]\Element1D[Ligne]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset <<<<<
Macro ResetKeyboardParam(KeyboardParamA)
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
KeyboardParam(KeyboardParamA, Ligne, Colonne) = 0
; Alternative qui fait la même chose
; SetKeyboardParam(KeyboardParamA, Ligne, Colonne, 0)
Next
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Copy : A = Source : B = Destination <<<<<
Macro CopyKeyboardParam(KeyboardParamA, KeyboardParamB)
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
KeyboardParam(KeyboardParamB, Ligne, Colonne) = KeyboardParam(KeyboardParam4, Ligne, Colonne)
; Alternative qui fait la même chose
; SetKeyboardParam(KeyboardParamB, Ligne, Colonne, GetKeyboardParam(KeyboardParamA, Ligne, Colonne))
Next
Next
; Et pour aller plus vite. Mais attention, cela fonctionne uniquement
; pour les types numériques : .b, .c, .l, .q, .f, .d
; Dès l'instant qu 'il y a un type chaine de caratère ( $ ou .s) c'est le
; code précédenet qui fonctionne.
; CopyMemory(KeyboardParamA, KeyboardParamB, SizeOf(KeyboardParam))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
merci Dobro, c'est vrai que j'avais pas pensé a ça et que ça fonctionne aussi !Dobro a écrit :
attention voici le code qui tue la vie , qui tue la mort
aviez vous pensé a ça ??
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Notes : Matrix33
;
; La matrice se présente sous la forme suivante :
;
; Éléments Matrice --> Index du tableau 1D
; 3x3 éléments --> 9 case de 0 à 8
;
; [e11, e12, e13] --> [0, 1, 2]
; [e21, e22, e23] --> [3, 4, 5]
; [e31, e32, e33] --> [6, 7, 8]
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<
Structure Matrix33L
Element.l[9]
EndStructure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les Macros d'accès <<<<<
Macro Matrix33LElement(MatrixA, Index)
MatrixA\Element[Index]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset <<<<<
Macro ResetMatrix33L(MatrixA)
For Index = 0 To 8
Matrix33LElement(MatrixA, Index) = 0
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Copy : A = Source : B = Destination <<<<<
Macro CopyMatrix33L(MatrixA, MatrixB)
For Index = 0 To 8
Matrix33LElement(MatrixB, Index) = Matrix33LElement(MatrixA, Index)
Next
; CopyMemory(MatrixA, MatrixB, SizeOf(Matrix33L))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Swap <<<<<
Macro SwapMatrix33L(MatrixA, MatrixB)
For Index = 0 To 8
Swap Matrix33LElement(MatrixA, Index), Matrix33LElement(MatrixB, Index)
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Macro de déboguage <<<<<
Macro DebugMatrix33L(MatrixA)
For Index = 0 To 8
Debug Matrix33LElement(MatrixA, Index)
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Prototype de parcours Ligne-Colonne
Procedure DebugMatrix33L_Ex(*MatrixA.Matrix33L)
For Line = 0 To 8 Step 3
Debug "Ligne no. : " + Str(offset + 1)
Debug "Élément : " + Str(Line) + ", " + Str(Line+1) + " et " + Str(Line+2)
For Row = 0 To 2
Debug Matrix33LElement(*MatrixA, Line + Row)
Next
offset + 1
Next
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
Alpha.Matrix33L
For Index = 0 To 8
Matrix33LElement(Alpha, Index) = 2 * Index + 552
Next
Debug "-------------------------------------"
Debug "Parcours comme un tableau 1D"
Debug "-------------------------------------"
DebugMatrix33L(Alpha)
Debug "-------------------------------------"
Debug "Parcours comme un tableau 2D"
Debug "-------------------------------------"
DebugMatrix33L_Ex(Alpha)
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
Code : Tout sélectionner
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Le nom du projet ici
; Fichier : Source principal
; Version : 0.0.0
; Programmation : À compléter
; Programmé par : Guimauve
; Date : 24-11-2007
; Mise à jour : 18-12-2007
; Codé avec PureBasic V4.10
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#MaxKeyPerLine = 3
#MaxLine = 50
Structure KeyboardParam1D
Element1D.l[#MaxKeyPerLine]
EndStructure
Structure KeyboardParam
Element2D.KeyboardParam1D[#MaxLine]
EndStructure
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Macros d'accès <<<<<
Macro KeyboardParam(KeyboardParamA, Ligne, Colonne)
KeyboardParamA\Element2D[Ligne]\Element1D[Colonne]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<
Macro SetKeyboardParam(KeyboardParamA, Ligne, Colonne, P_Param)
KeyboardParamA\Element2D[Ligne]\Element1D[Colonne] = P_Param
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<
Macro GetKeyboardParam(KeyboardParamA, Ligne, Colonne)
KeyboardParamA\Element2D[Ligne]\Element1D[Colonne]
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset <<<<<
Macro ResetKeyboardParam(KeyboardParamA)
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
KeyboardParam(KeyboardParamA, Ligne, Colonne) = 0
; Alternative qui fait la même chose
; SetKeyboardParam(KeyboardParamA, Ligne, Colonne, 0)
Next
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Copy : A = Source : B = Destination <<<<<
Macro CopyKeyboardParam(KeyboardParamA, KeyboardParamB)
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
KeyboardParam(KeyboardParamB, Ligne, Colonne) = KeyboardParam(KeyboardParam4, Ligne, Colonne)
; Alternative qui fait la même chose
; SetKeyboardParam(KeyboardParamB, Ligne, Colonne, GetKeyboardParam(KeyboardParamA, Ligne, Colonne))
Next
Next
; Et pour aller plus vite. Mais attention, cela fonctionne uniquement
; pour les types numériques : .b, .c, .l, .q, .f, .d
; Dès l'instant qu 'il y a un type chaine de caratère ( $ ou .s) c'est le
; code précédenet qui fonctionne.
; CopyMemory(KeyboardParamA, KeyboardParamB, SizeOf(KeyboardParam))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Debug <<<<<
Macro DebugKeyboardParam(KeyboardParamA)
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
Debug "(" + Str(Ligne) + ", " + Str(Colonne) + ") = " + Str(KeyboardParam(KeyboardParamA, Ligne, Colonne))
Next
Next
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
For Ligne = 0 To #MaxLine - 1
For Colonne = 0 To #MaxKeyPerLine - 1
KeyboardParam(Test.KeyboardParam, Ligne, Colonne) = Ligne + Colonne
Next
Next
DebugKeyboardParam(Test)
; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<