Cependant le compteur est en dur dans mon fichier csv si un utilisateur rajoute des lignes dans le fichier csv il devra modifier le compteur cela entrainera des risques d'erreur .
Solution demander : Je voudrais que dans ma boucle for de i jusqu a x le nombre x qui correspond au nombre de ligne a lire du fichier csv s'adapte automatiquement
Je n'arrive pas a joindre mon dossier mais il est tres simple
Code : Tout sélectionner
Colonne 0 | Colonne 1 | Colonne 2
-----------------------------------------------------------------------------------------
Ligne 0 Architecture SE | AjouterCompteurNb Ligne - 1 ( aide a la personne ) |
Ligne 1 32 bit | 2 ( le compteur a saisir |
Ligne 2 64 bit |
Ci dessous : Mon Application , Une fonction pour lire le csv
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>
#include <Array.au3>
_Lecture_Fichier_Csv_Et_Mise_En_Place_Dans_ComboBox()
func _Lecture_Fichier_Csv_Et_Mise_En_Place_Dans_ComboBox()
; Recupere CSV dans un tableau
Global $csvArchitectureSE = _CSV2Array("C:\ArchitectureSE.csv", ",")
; Nom par defaut combox box ligne 0 colonne0 du csv
Global $nameComboBoxArchitecture = $csvArchitectureSE[0][0]
; Compteur Csv
Global $cptArchitectureSE = $csvArchitectureSE[1][1]
; Création Graphique
Global $projet = GUICreate("Form1", 615, 792, 431, 138)
Global $group1 = GUICtrlCreateGroup("", 80, 0, 425, 737)
; Création Combo
Global $architecture = GUICtrlCreateCombo($nameComboBoxArchitecture, 208, 536, 153, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
; Boucle qui lis le dossier CSV architecture SE et le mes dans la liste déroulante
For $i = 1 To $cptArchitectureSE
GUICtrlSetData(-1, $csvArchitectureSE[$i][0])
Next
EndFunc
#FUNCTION# ===================================================================
; Name ..........: _CSV2Array
; Description ...:
; AutoIt Version : V3.3.0.0
; Syntax ........: _CSV2Array($hFile[, $cSeperator = "auto"[, $bFilterString = True[, $iColumnMode = 0]]])
; Parameter(s): .: $hFile - Handle for the CSV file to Read
; $cSeperator - Optional: (Default = "auto") : Tries to find the separator char (; or , or TAB or | or space)
; | Data-seperator-char
; | Empty-string = Opt("GUIDataSeparatorChar")
; $bFilterString - Optional: (Default = True) : Removes leading and trailing " or '
; $iColumnMode - Optional: (Default = 0) :
; | 0: Sets error if lines have different columns and @extended to the csv-line number
; | 1: returns lines with different columns numbers comparing to the first line, too
; | 2: removing all columns > column numbers in the first line
; Return Value ..: Success - 2-dim Array
; Failure - 0
; @ERROR - 1: error file read
; @ERROR - 2: different number of columns / @EXTENDED = CSV-line
; - 3: parameter error
; Author(s) .....: Thorsten Willert
; Date ..........: Mon Dec 07 18:59:46 CET 2009
; ==============================================================================
Func _CSV2Array($hFile, $cSeperator = "auto", $bFilterString = True, $iColumnMode = 0)
Local $s = FileRead($hFile)
If @error Then Return SetError(1)
If $cSeperator = Default Then $cSeperator = "auto"
If Not $cSeperator Then $cSeperator = Opt("GUIDataSeparatorChar")
; searching the line-seperator and splitting the lines into an array
Local $aLines
If StringInStr($s, @CRLF) Then
$aLines = StringSplit($s, @CRLF, 1)
ElseIf StringInStr($s, @CR) Then
$aLines = StringSplit($s, @CR)
Else
$aLines = StringSplit($s, @LF)
EndIf
; searching the delimiter in the first line
Local $aTMP
If $cSeperator = "auto" Then
Local $iMax = 0
Local $iC[5] = [0, 0, 0, 0, 0]
Local $sC[5] = [";", ",", @TAB, "|", " "]
$aTMP = StringRegExp($aLines[1], ";", 3)
If Not @error Then $iC[0] = UBound($aTMP)
$aTMP = StringRegExp($aLines[1], ",", 3)
If Not @error Then $iC[1] = UBound($aTMP)
$aTMP = StringRegExp($aLines[1], "\t", 3)
If Not @error Then $iC[2] = UBound($aTMP)
$aTMP = StringRegExp($aLines[1], "\|", 3)
If Not @error Then $iC[3] = UBound($aTMP)
$aTMP = StringRegExp($aLines[1], "[ ]", 3)
If Not @error Then $iC[4] = UBound($aTMP)
For $i = 0 To UBound($sC) - 1
If $iC[$i] > $iMax Then
$iMax = $iC[$i]
$cSeperator = $sC[$i]
EndIf
Next
EndIf
; creating 2-dim array based on the number of data in the first line
$aTMP = StringSplit($aLines[1], $cSeperator)
Local $iCol = $aTMP[0]
Local $aRet[$aLines[0]][$iCol]
; splitting and filling the lines
For $i = 1 To $aLines[0]
$aTMP = StringSplit($aLines[$i], $cSeperator)
If @error Then ContinueLoop
If $aTMP[0] > $iCol Then
Switch $iColumnMode
Case 0
Return SetError(2, $i)
Case 1
ReDim $aRet[$aLines[0] - 1][$aTMP[0]]
Case 2
$aTMP[0] = $iCol
Case Else
Return SetError(3)
EndSwitch
EndIf
For $j = 1 To $aTMP[0]
$aTMP[$j] = StringStripWS($aTMP[$j], 3)
; removing leading and trailing " or '
If $bFilterString Then $aTMP[$j] = StringRegExpReplace($aTMP[$j], '^("|'')(.*?)\1$', '$2')
$aRet[$i - 1][$j - 1] = $aTMP[$j]
Next ; /cols
Next ; /lines
Return $aRet
EndFunc ;==>_CSV2Array