j'utilise souvent des tableaux et je trouve très embêtant de créer toutes les lignes à chaque fois, donc j'ai fait un petit script pour me simplifier la vie :
► Afficher le texte
Code : Tout sélectionner
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;~ #include <Timers.au3>
Global $progName = "New Array", $FichierTableau = ""
Global $valeur1D = 1, $valeur2D = 1, $nMsg
#region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate($progName, 235, 102, 199, 129)
GUICtrlCreateLabel("Nom du tableau :", 10, 10, 85, 17, $SS_CENTERIMAGE)
Global $NomTableau = GUICtrlCreateInput("", 100, 10, 120, 21)
GUICtrlCreateLabel("Taille 1D :", 10, 40, 50, 17, $SS_CENTERIMAGE)
Global $taille1D = GUICtrlCreateInput($valeur1D, 70, 40, 40, 21, BitOR($ES_NUMBER, $SS_CENTERIMAGE, $ES_CENTER))
GUICtrlSetLimit(-1, 3)
GUICtrlCreateLabel("Taille 2D :", 120, 40, 50, 17, $SS_CENTERIMAGE)
Global $taille2D = GUICtrlCreateInput($valeur2D, 180, 40, 40, 21, BitOR($ES_NUMBER, $SS_CENTERIMAGE, $ES_CENTER))
GUICtrlSetLimit(-1, 3)
Global $NewArray = GUICtrlCreateButton("Nouveau tableau", 65, 70, 100, 20)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $NewArray
            $FichierTableau = GUICtrlRead($NomTableau)
            $valeur1D = GUICtrlRead($taille1D)
            $valeur2D = GUICtrlRead($taille2D)
            If $valeur1D = "" Or $valeur1D = 0 Then
                $valeur1D = 1
                GUICtrlSetData($taille1D, $valeur1D)
            EndIf
            If $valeur2D = "" Or $valeur2D = 0 Then
                $valeur2D = 1
                GUICtrlSetData($taille2D, $valeur2D)
            EndIf
            If $FichierTableau = "" Then
                MsgBox(48, $progName, "Le nom du tableau ne peut être vide.")
                ContinueCase
            Else
                CreationTableau($FichierTableau, $valeur1D, $valeur2D)
                GUICtrlSetData($NomTableau, "")
                GUICtrlSetData($taille1D, 1)
                GUICtrlSetData($taille2D, 1)
            EndIf
    EndSwitch
WEnd
Func CreationTableau($Fichier, $taille, $2D)
    Local $CheminFichier = FileSelectFolder("Veuillez choisir un dossier :", "")
    If $CheminFichier = "" Then $CheminFichier = @ScriptDir
    $CheminFichier &= "\" & $Fichier & ".au3"
    Local $line = ""
;~  Local $starttime = _Timer_Init()
    WriteFile($CheminFichier, $line, 1)
    If $2D = 1 Then
        $line = "Global $" & $Fichier & "[" & $taille & "]" & @CRLF
        $line &= "$" & $Fichier & "[0] = " & $taille - 1
        For $i = 1 To $taille - 1
            $line &= @CRLF
            $line &= "$" & $Fichier & "[" & $i & '] = ""'
        Next
        WriteFile($CheminFichier, $line, 0)
    Else
        $line = "Global $" & $Fichier & "[" & $taille & "][" & $2D & "]" & @CRLF
        $line &= "$" & $Fichier & "[0][0] = " & $taille - 1 & @CRLF
        $line &= "$" & $Fichier & "[0][1] = " & $2D - 1
        If $2D > 2 Then
            For $i = 2 To $2D - 1
                $line &= @CRLF
                $line &= "$" & $Fichier & "[0][" & $i & '] = ""'
            Next
            WriteFile($CheminFichier, $line, 0)
        EndIf
        For $i = 1 To $taille - 1
            For $j = 0 To $2D - 1
                $line &= @CRLF
                $line &= "$" & $Fichier & "[" & $i & "][" & $j & '] = ""'
            Next
            WriteFile($CheminFichier, $line, 0)
        Next
    EndIf
;~  ConsoleWrite(@CRLF & "[" & $taille & "][" & $2D & "] = " & Round(_Timer_Diff($starttime) / 1000, 2) & "s")
EndFunc   ;==>CreationTableau
Func WriteFile($CheminFichier, ByRef $data, $start = 1)
    Local $open = 2, $temp, $file
    If $start = 0 Then $open = 1
    $file = FileOpen($CheminFichier, $open)
    ; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(16, $progName, "Unable to open file.")
        Exit
    EndIf
    If $open = 1 Then
        $temp = FileWrite($file, $data)
        If $temp = 0 Then
            MsgBox(16, $progName, "Unable to write in the file.")
        Else
            $data = ""
        EndIf
    EndIf
    FileClose($file)
EndFunc   ;==>WriteFileVoici un petit exemple de ce que ça donne :
► Afficher le texte
Code : Tout sélectionner
Global $test[3][3]
$test[0][0] = 2
$test[0][1] = 2
$test[0][2] = ""
$test[1][0] = ""
$test[1][1] = "" 
$test[1][2] = "" 
$test[2][0] = "" 
$test[2][1] = "" 
$test[2][2] = ""J'espère que mon partage vous sera utile.



