Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Général VBA
Général VBA Forum général VBA . Pour les logiciels spécifiques (Access, Excel, Word, ...), postez dans les bons sous forums.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/06/2011, 00h05   #1
 
Homme Maxime Alexandre
Étudiant
Inscription : mai 2011
Messages : 76
Détails du profil
Informations personnelles :
Nom : Homme Maxime Alexandre
Localisation : France, Ardennes (Champagne Ardenne)

Informations professionnelles :
Activité : Étudiant
Secteur : Enseignement

Informations forums :
Inscription : mai 2011
Messages : 76
Points : -16
Points : -16
Par défaut changer forme d'une création de fichier avec if

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 :
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 :
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 :
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
Maxime082 est déconnecté   Envoyer un message privé Réponse avec citation 03
Vieux 13/06/2011, 15h37   #2
Membre à l'essai
 
cyril courbis
Inscription : février 2010
Messages : 32
Détails du profil
Informations personnelles :
Nom : cyril courbis

Informations forums :
Inscription : février 2010
Messages : 32
Points : 22
Points : 22
Hum, essaye avec ce type de structure (chez moi le elseif ne fonctionne pas)

Code :
1
2
3
4
5
6
7
If  A = X  then 
  {execution}
else 
    if A = y then 
        {execution}
    end if
end if
trash_07 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/06/2011, 17h28   #3
 
Homme Maxime Alexandre
Étudiant
Inscription : mai 2011
Messages : 76
Détails du profil
Informations personnelles :
Nom : Homme Maxime Alexandre
Localisation : France, Ardennes (Champagne Ardenne)

Informations professionnelles :
Activité : Étudiant
Secteur : Enseignement

Informations forums :
Inscription : mai 2011
Messages : 76
Points : -16
Points : -16
j'ai essayé votre méthode, elle à l'air de marcher mais je ne sais pas pourquoi il me dit que le chemin d'accès n'existe pas! alors qu'il existe

Je mets le fichier en PJ;

Cordialement
Maxime082 est déconnecté   Envoyer un message privé Réponse avec citation 01
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h48.


 
 
 
 
Partenaires

Hébergement Web