IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Discussion :

changer forme d'une création de fichier avec if


Sujet :

VBA

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ardennes (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2011
    Messages : 76
    Points : 0
    Points
    0
    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 : 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

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Février 2010
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 38
    Points : 47
    Points
    47
    Par défaut
    Hum, essaye avec ce type de structure (chez moi le elseif ne fonctionne pas)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    If  A = X  then 
      {execution}
    else 
        if A = y then 
            {execution}
        end if
    end if

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ardennes (Champagne Ardenne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2011
    Messages : 76
    Points : 0
    Points
    0
    Par défaut
    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

Discussions similaires

  1. Changer une ligne de fichier avec script
    Par debdarky dans le forum Shell et commandes GNU
    Réponses: 9
    Dernier message: 26/07/2013, 16h35
  2. Réponses: 2
    Dernier message: 20/04/2012, 09h24
  3. probleme de création de fichiers avec une boucle
    Par bobo696 dans le forum Débuter
    Réponses: 3
    Dernier message: 19/01/2009, 14h45
  4. Création de fichier avec Powerbuilder
    Par cradleofpain dans le forum Powerbuilder
    Réponses: 8
    Dernier message: 07/05/2007, 10h37
  5. Réponses: 3
    Dernier message: 19/10/2005, 15h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo