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

VBScript Discussion :

Lire deux fichiers en même temps


Sujet :

VBScript

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 10
    Points : 4
    Points
    4
    Par défaut Lire deux fichiers en même temps
    Bonjour
    Je solicite votre aide

    Je dois lire le fichier SYNTHESE.DAT ligne par ligne trouver l'imatriculation du vehicule et pour chaque Imatriculation du véhicule je dois trouver dans le fichier VEHICULE.DAT la ligne qui correspont a mon vehicule

    Je pense que mon problème vient que j'utilise "ReadLine" dans mais 2 boucles mais je ne voi pas comment faire autrement


    Structure du fichier SYNTHESE.DAT
    1083TQ76;Gazole;167.54;1443;11.61;97849;
    1150ZP76;Gazole;45.94;793;5.79;92800;
    12AGR76;Gazole;395.60;4125;9.59;106748;
    130TF76;Gazole;35.70;556;6.42;195188;
    14AJF76;Gazole;71.11;1205;5.90;48771;
    1581YH76;Gazole;168.85;2871;5.88;168150;


    Structure du fichier VEHICULE.DAT
    0000ZZ76;11290;TOURISME;D0 ROUEN;;;
    1083TQ76;11204;SAV OUTILLAGE;D0ROUEN;TECHNICIENS;MASTER;RENAULT
    1150ZP76;11378;SFR;D0 ROUEN;REPRESENTANTS;CLIO;RENAULT
    12AGR76;11386;EXPEDITION;D0 ROUEN;LIVRAISON;TRANSIT;FORD
    130TF76;11373;ATELIERS;D3 ST ETIENNE DU ROUVRAY NVI;ATELIER ELECTRICITÉ / CHRONO;CLIO;RENAULT
    1379TQ76;11106;DIESEL;D0 ROUEN;TECHNICIENS;EXPERT;PEUGEOT
    14AJF76;11420;SFR;D0 ROUEN;REPRESENTANTS;FIESTA;FORD
    1581YH76;11254;COMMERCIAL;D3 ST ETIENNE DU ROUVRAY NVI;REPRESENTANTS;C3;CITROEN
    15AJF76;11389;SFR;D0 ROUEN;REPRESENTANTS;FIESTA;FORD





    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
    Const ForReading = 1, ForWriting = 2
    Dim oFso, S, V
    Dim constente1,constente2
    Dim SFichier,ImatSFichier
    Dim VFichier, ImatVFichier
     
    Set oFso = CreateObject("Scripting.FileSystemObject")
    Set S = oFso.OpenTextFile("c:\CONSO\SYNTHESE.DAT", ForReading)
    Set V = oFso.OpenTextFile("c:\CONSO\VEHICULE.DAT", ForReading)
     
    Set F = oFso.OpenTextFile("c:\CONSO\Fichier.csv", ForWriting,true)
     
    while Not S.AtEndOfStream
    constente1=S.ReadLine
    SFichier = split(constente1,";")
    ImatSFichier=SFichier(0)
     
    	do while V.AtEndOfStream=false 
    		constente2 = V.ReadLine
    		VFichier = split(constente2,";")
    		ImatVFichier=VFichier(0)
     
    		If ImatSFichier=ImatVFichier then
    			Phrase=constente1 & ";" & constente2 & VbCrLf
     
    		End if			
    	Loop
     
    	F.write(Phrase)
     
    Wend
    S.Close
    V.Close
     
    F.Close
    Merci de votre aide

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    Bonjour,

    je te propose d'utiliser un ou 2 dictionnaire pour stocker les valeurs lues dans un fichier ...

    par exemple en utilisant 2 dictionnaires

    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
    Dim oFso
    Set oFso = CreateObject("Scripting.FileSystemObject") 'Objet Fso Global...
    Const ForReading = 1
    Dim oDicS ' Dictionnaire Synthese
    Dim oDicV 'Dictionnaire véhicule
    Set oDicS=CreateObject("Scripting.Dictionary")
    LectFichier "d:\Documents and Settings\philippe\Mes documents\dvp\VBS\Vehicule\Synthese.dat",oDicS
    Set oDicV=CreateObject("Scripting.Dictionary")
    LectFichier "d:\Documents and Settings\philippe\Mes documents\dvp\VBS\Vehicule\Vehicule.dat",oDicV
    AfficheVehicule "14AJF76"
    AfficheVehicule "0000ZZ76"
    AfficheVehicule "XXXXXXX"
    '
    ' Lecture d'un fichier .DAT et le place dans dictionnaire donné en paramétre 
    ' Avec pour clef la 1° colonne du fichier .DAT
    '
    Sub LectFichier ( stFichier, dico )
     Dim f
     Dim stImmat 
     Dim stLigne
     
      Set f = oFso.OpenTextFile(stFichier, ForReading)
      while Not f.AtEndOfStream 
          stLigne = f.ReadLine
    	  stImmat = split(stLigne,";")(0)  'Récupére immatriculation pour clef
          dico.Add stImmat, stLigne
     
     
     
      Wend
      f.Close
     End sub
     
     
    '
    ' Affiche un Véhicule
    '
     Sub AfficheVehicule ( stImmat)
    	Wscript.Echo " ================== " & stImmat & "==================="
    	if oDicS.exists(stImmat) Then
    		wscript.echo "Synthese : " & oDicS.item(stImmat)
    	else
    			wscript.echo "Synthese :        N/A "
    	end if
    	if oDicV.exists(stImmat) Then
    		wscript.echo "Vehicule : " & oDicV.item(stImmat)
    	else
    			wscript.echo "Vehicule :        N/A "
    	end if
     
     
     end sub

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    Merci pour ta reponse

    Mais je pense m'avoir mal exprimer mon fichier SYNTHESE.DAT me donne imatriculation du vehicule que je dois chercher dans le fichier VEHICULE.DAT

    J'attends de mon programme un fichier nommer "FICHIER.CSV"
    Structure du fichier VEHICULE.DAT
    1083TQ76;Gazole;167.54;1443;11.61;97849;1083TQ76;11204;SAV OUTILLAGE;D0ROUEN;TECHNICIENS;MASTER;RENAUL
    1150ZP76;Gazole;45.94;793;5.79;92800;1150ZP76;11378;SFR;D0 ROUEN;REPRESENTANTS;CLIO;RENAULT
    12AGR76;Gazole;395.60;4125;9.59;106748;12AGR76;11386;EXPEDITION;D0 ROUEN;LIVRAISON;TRANSIT;FORD
    130TF76;Gazole;35.70;556;6.42;195188;130TF76;11373;ATELIERS;D3 ST ETIENNE DU ROUVRAY NVI;ATELIER ELECTRICITÉ / CHRONO;CLIO;RENAULT
    ...

    Si tu as une solution

  4. #4
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    Citation Envoyé par forest.y Voir le message
    ...
    J'attends de mon programme un fichier nommer "FICHIER.CSV"
    Structure du fichier VEHICULE.DAT
    1083TQ76;Gazole;167.54;1443;11.61;97849;1083TQ76;11204;SAV OUTILLAGE;D0ROUEN;TECHNICIENS;MASTER;RENAUL
    1150ZP76;Gazole;45.94;793;5.79;92800;1150ZP76;11378;SFR;D0 ROUEN;REPRESENTANTS;CLIO;RENAULT
    ...
    je suppose que tu veux dire "structure du fichier Fichier.csv" ... pour cela je t'ai déjà donné une grosse partie de la solution tu lit ton fichier synthese.dat avec la fonction LectFichier que je t'ai fourni, puis tu lit on fichier vehicule.dat et pour chaque ligne tu récupére les données de synthèses dans le dictionnaire..;

  5. #5
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    Désolé, j'ai modifier ton exemple pour lire ligne par ligne mon fichier SYNTHESE.DAT mais sa ne fonctinne que pour la premiere ligne



    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
    Dim oFso
    Set oFso = CreateObject("Scripting.FileSystemObject") 'Objet Fso Global...
    Const ForReading = 1
    Const ForWriting = 2
    Dim oDicS ' Dictionnaire Synthese
    Dim oDicV 'Dictionnaire véhicule
    Set oDicS=CreateObject("Scripting.Dictionary")
    LectFichier "Synthese.dat",oDicS
    Set oDicV=CreateObject("Scripting.Dictionary")
    LectFichier "Vehicule.dat",oDicV
    Dim S
    Set S = oFso.OpenTextFile("SYNTHESE.DAT", ForReading)
    Dim Imatr
    Set Fichiercsv = oFso.OpenTextFile("Fichier.csv", ForWriting,true)
     
     
    'Lecture ligne par ligne du fichier SYNTHESE.DAT
    do while S.AtEndOfStream=false
     
    	SFichier = split(S.ReadLine,";")
    	Imatr=SFichier(0)
    	AfficheVehicule Imatr
    Loop
     
    '
    ' Lecture d'un fichier .DAT et le place dans dictionnaire donné en paramétre 
    ' Avec pour clef la 1° colonne du fichier .DAT
    '
    Sub LectFichier ( stFichier, dico )
     Dim f
     Dim stImmat 
     Dim stLigne
     
      Set f = oFso.OpenTextFile(stFichier, ForReading)
      while Not f.AtEndOfStream 
          stLigne = f.ReadLine
    	  stImmat = split(stLigne,";")(0)  'Récupére immatriculation pour clef
          dico.Add stImmat, stLigne
     
     
     
      Wend
      f.Close
     End sub
     
     
    '
    ' Affiche un Véhicule
    '
     Sub AfficheVehicule ( stImmat)
    	DIM AY, BY
    	Dim Phrase
     
     
    	if oDicS.exists(stImmat) Then
    		AY=oDicS.item(stImmat)
    	else
    		AY=" N/A "
    	end if
    	if oDicV.exists(stImmat) Then
    		BY=oDicV.item(stImmat)
    	else
    		AY=" N/A "
    	end if
     	Phrase=AY & ";" & BY
     	Fichiercsv.write(Phrase)
     
     end sub

  6. #6
    Candidat au Club
    Profil pro
    Inscrit en
    Juillet 2011
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2011
    Messages : 10
    Points : 4
    Points
    4
    Par défaut
    Merci sa fonctinne j'avais oublé le retour chariot pour chaque ligne,
    parcontre as tu une idée comment je peux vérifier mon fichier avant de le mettre dans un dictionnaire pour ne pas avoir un message erreur si j'ai un index identique sur plusieur ligne

  7. #7
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    tu peu vérifier si l'index existe déjà dans le dictionnaire grâce à la fonction exist...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 31/08/2012, 15h44
  2. Lire deux fichiers en même temps
    Par Carlozi dans le forum Langage
    Réponses: 23
    Dernier message: 31/07/2008, 12h19
  3. Lecture de deux fichiers en même temps
    Par salut93 dans le forum C++
    Réponses: 3
    Dernier message: 26/06/2007, 15h29
  4. [VB6] Lire deux sons en même temps
    Par daladim dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 17/12/2006, 20h29
  5. Voir deux fichier en même temps ?
    Par dr23fr dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 07/09/2006, 11h11

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