Bonsoir à tous, je travaille sur une programme actuellement, me permettant de créer des fichiers. A partir d'une liste déroulante je choisi la pièce dont je veux créer un nouveau fichier et selon le nom de la pièce que je choisi, la forme n'est pas la même. Pour l'instant, mon programme marche mais que pour une seule pièce (C02), quand je clique sur mon combobox1 et que je clique sur C02 j'ai le format suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Sub EcrireFichier(codePIE As String, codeTYP As String, codeREP As String, codeBN As String)
Dim objFso As Object
Dim objFil As Object
 
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFil = objFso.OpenTextFile("c:\sesame\data_lecteur\" & codePIE & "\CH" & codePIE & codeType & "SERIEREP" & codeREP & "BN" & codeBN & ".dat", 2, True)
 
 
txtCodePIE = Feuil1.ComboBox1.Value
txtCodeTYP = Feuil1.ComboBox2.Value
 
objFil.WriteLine "[]"
objFil.WriteLine "CODE_UP = CH"
objFil.WriteLine "CODE_ATEL = ROBOT FCL"
objFil.WriteLine "CODE_LIGNE = " & codePIE
objFil.WriteLine "CODE_OP = REP " & codeREP
objFil.WriteLine "CODE_SOP = BN " & codeBN
objFil.WriteLine "CODE_MACH = 0"
objFil.WriteLine "CODE_PO = 0"
objFil.WriteLine "CODE_OR = CHFCL"
objFil.WriteLine "CODE_FON = " & codePIE
objFil.WriteLine "CODE_PROD = SERIE"
objFil.WriteLine "CODE_TYP = " & codeTYP
objFil.WriteLine "NOM_GEX = CH" & codePIE & codeTYP & "REP" & codeREP & "BN" & codeBN
objFil.WriteLine "NOM_GAMME = CH" & codePIE & "SERIE"
objFil.WriteLine "DESI_GAM = Culasse " & codePIE & " Serie"
objFil.WriteLine "ROLE_MES = MS"
objFil.WriteLine "TAILLE_ECH = 1"
objFil.WriteLine "NUM_OF ="
 
objFil.WriteLine "CRE_VER = O"
 
objFil.Close
 
Set objFil = Nothing
Set objFso = Nothing
 
End Sub
Le probleme c'est que si je choisi la pièce c04 par exemple : le format sera :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Sub EcrireFichier(codePIE As String, codeTYP As String, codeREP As String, codeBN As String)

Dim objFso As Object
Dim objFil As Object
 
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFil = objFso.OpenTextFile("c:\sesame\data_lecteur\" & codePIE & "\CH" & codePIE & codeType & "SERIEREP" & codeREP & "BN" & codeBN & ".dat", 2, True)
 
 
txtCodePIE = Feuil1.ComboBox1.Value
txtCodeTYP = Feuil1.ComboBox2.Value

objFil.WriteLine "[]"
objFil.WriteLine "CODE_UP = CH FERREUX"
objFil.WriteLine "CODE_ATEL = ROBOT FCX"
objFil.WriteLine "CODE_LIGNE = " & codePIE
objFil.WriteLine "CODE_OP = REP " & codeREP
objFil.WriteLine "CODE_SOP = BN " & codeBN
objFil.WriteLine "CODE_MACH = 0"
objFil.WriteLine "CODE_PO = 0"
objFil.WriteLine "CODE_OR = CHFCL"
objFil.WriteLine "CODE_FON = " & codePIE
objFil.WriteLine "CODE_PROD = SERIE"
objFil.WriteLine "CODE_TYP = " & codeTYP
objFil.WriteLine "NOM_GEX = CH" & codePIE & codeTYP & "REP" & codeREP & "BN" & codeBN
objFil.WriteLine "NOM_GAMME = CH" & codePIE & "SERIE"
objFil.WriteLine "DESI_GAM = Culasse " & codePIE & " Serie"
objFil.WriteLine "ROLE_MES = MS"
objFil.WriteLine "TAILLE_ECH = 1"
objFil.WriteLine "NUM_OF ="

objFil.WriteLine "CRE_VER = O"
 
objFil.Close
 
Set objFil = Nothing
Set objFso = Nothing
 
End Sub
Donc je voulais utiliser la fonction if pour dire que quand je clique sur la liste déroulante et que je choisi telle ou telle pièce, j'ai le format adapté.
J'ai pensé à faire ceci mais ça ne marche pas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
 
Sub EcrireFichier(codePIE As String, codeTYP As String, codeREP As String, codeBN As String)
Dim objFso As Object
Dim objFil As Object
 
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFil = objFso.OpenTextFile("c:\sesame\data_lecteur\" & codePIE & "\CH" & codePIE & codeType & "SERIEREP" & codeREP & "BN" & codeBN & ".dat", 2, True)
 
 
txtCodePIE = Feuil1.ComboBox1.Value
txtCodeTYP = Feuil1.ComboBox2.Value
 
if combobox1.value = "C02" then
objFil.WriteLine "[]"
objFil.WriteLine "CODE_UP = CH"
objFil.WriteLine "CODE_ATEL = ROBOT FCL"
objFil.WriteLine "CODE_LIGNE = " & codePIE
objFil.WriteLine "CODE_OP = REP " & codeREP
objFil.WriteLine "CODE_SOP = BN " & codeBN
objFil.WriteLine "CODE_MACH = 0"
objFil.WriteLine "CODE_PO = 0"
objFil.WriteLine "CODE_OR = CHFCL"
objFil.WriteLine "CODE_FON = " & codePIE
objFil.WriteLine "CODE_PROD = SERIE"
objFil.WriteLine "CODE_TYP = " & codeTYP
objFil.WriteLine "NOM_GEX = CH" & codePIE & codeTYP & "REP" & codeREP & "BN" & codeBN
objFil.WriteLine "NOM_GAMME = CH" & codePIE & "SERIE"
objFil.WriteLine "DESI_GAM = Culasse " & codePIE & " Serie"
objFil.WriteLine "ROLE_MES = MS"
objFil.WriteLine "TAILLE_ECH = 1"
objFil.WriteLine "NUM_OF ="
 
objFil.WriteLine "CRE_VER = O"
 
objFil.Close
 
Set objFil = Nothing
Set objFso = Nothing
 
ElseIf combobox1.value = "C04" then
 
Dim objFso As Object
Dim objFil As Object
 
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFil = objFso.OpenTextFile("c:\sesame\data_lecteur\" & codePIE & "\CH" & codePIE & codeType & "SERIEREP" & codeREP & "BN" & codeBN & ".dat", 2, True)
 
 
txtCodePIE = Feuil1.ComboBox1.Value
txtCodeTYP = Feuil1.ComboBox2.Value
 
objFil.WriteLine "[]"
objFil.WriteLine "CODE_UP = CH FERREUX" '<<<<<< =======
objFil.WriteLine "CODE_ATEL = ROBOT FCX" '<<<<<<==========
objFil.WriteLine "CODE_LIGNE = " & codePIE
objFil.WriteLine "CODE_OP = REP " & codeREP
objFil.WriteLine "CODE_SOP = BN " & codeBN
objFil.WriteLine "CODE_MACH = 0"
objFil.WriteLine "CODE_PO = 0"
objFil.WriteLine "CODE_OR = CHFCL"
objFil.WriteLine "CODE_FON = " & codePIE
objFil.WriteLine "CODE_PROD = SERIE"
objFil.WriteLine "CODE_TYP = " & codeTYP
objFil.WriteLine "NOM_GEX = CH" & codePIE & codeTYP & "REP" & codeREP & "BN" & codeBN
objFil.WriteLine "NOM_GAMME = CH" & codePIE & "SERIE"
objFil.WriteLine "DESI_GAM = Culasse " & codePIE & " Serie"
objFil.WriteLine "ROLE_MES = MS"
objFil.WriteLine "TAILLE_ECH = 1"
objFil.WriteLine "NUM_OF ="
 
objFil.WriteLine "CRE_VER = O"
 
objFil.Close
 
Set objFil = Nothing
Set objFso = Nothing
 
End if 
End Sub

Cordialement