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

Langage Delphi Discussion :

Comment ignorer un saut de ligne ?


Sujet :

Langage Delphi

  1. #1
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut Comment ignorer un saut de ligne ?
    salut,

    j'ai du texte dans un mémo;et je souhaiterais écrire son contenu dans un fichier texte.pour cela j'ai parcouru l'ensemble du mémo.

    moi je souhaiterais donc avoir dans mon fichier texte ,une écriture compacte sans saut de ligne.

    exemple contenu du mémo

    Duration 3293898 3169524 215285 1185310 54067
    Cost 8146382.00 11887233.00 824826.00 6716994.00 222421.00

    Operator ALL
    Duration 140749
    Cost 18387.00

    je souhaiterais pouvoir ignorer le saut de ligne entre les deux blocs.

    merci
    La patience est un Chemin d'or

  2. #2
    Expert éminent sénior
    Avatar de Cl@udius
    Homme Profil pro
    Développeur Web
    Inscrit en
    Février 2006
    Messages
    4 878
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2006
    Messages : 4 878
    Points : 10 008
    Points
    10 008
    Par défaut
    Salut

    Tu peux procéder ainsi: Tu stockes le contenu du mémo dans un StringList, tu y fais le ménage, et tu l'enregistres.

    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
     
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
      SL: TStringList;
    begin
      SL := TStringList.Create;
      try
        SL.Assign(Memo1.Lines);
        for I := SL.Count - 1 downto 0 do
          if Trim(SL[I]) = '' then SL.Delete(I);
        SL.SaveToFile('C:\TonDossier\TonFichier.txt');
      finally
        SL.Free;
      end;
    end;
    @+ Claudius

  3. #3
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut je m'en sort pas...
    salut
    j'ai essayé ton code adapté à mon problème, mais je m'en sors pas vraiment.


    voila tout le contenu de mon mémo

    ORIGINATING VOICE
    Operator Moov Togocel Togotelecom Internatnl Others
    Duration 3293898 3169524 215285 1185310 54067
    Cost 8146382.00 11887233.00 824826.00 6716994.00 222421.00

    FORWARDING VOICE
    Operator ALL
    Duration 140749
    Cost 18387.00

    SMS
    Operator Moov Togocel Togotelecom Internatnl Others
    Count 18612 13633 407 10566 1037
    Cost 587125.00 643482.00 20200.00 562805.00 54850.00



    Le problème réside dans le fait qu'il faut que j'écrive dans un fichier texte l'ensemble des nombres rencontrésdans le mémo sur une seule ligne.

    NB:chaque nombre écrit devra etre séparé par un séparateur.


    s'il vous plait un coup de main pour me sortir du bourbier.
    La patience est un Chemin d'or

  4. #4
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Salut,

    Tu veux que les données se présentent ainsi :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    3293898;3169524;215285;1185310;54067
    8146382.00;11887233.00;824826.00;6716994.00;222421.00
    140749
    18387.00
    18612;13633;407;10566;1037
    587125.00;643482.00;20200.00;562805.00;54850.00
    ?

    [EDIT]

    Si c'est le cas, voici ce que tu peux faire:

    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
    procedure TForm1.Button1Click(Sender: TObject);
    var
    ResteChaine:string;
    MaChaine:string;
    i:integer;
    SL:TStringList;
    begin
      SL:=TStringList.Create;
      MaChaine:='';
      for i:=0 to Memo1.Lines.Count-1 do
      begin
        ResteChaine:=RightStr(Memo1.Lines.Strings[i],Length(Memo1.Lines.Strings[i])-pos(' ',Memo1.Lines.Strings[i]));
        while (pos(' ',ResteChaine)>0) do
        begin
          MaChaine:=MaChaine+copy(ResteChaine,1,pos(' ',ResteChaine)-1)+';';
          ResteChaine:=RightStr(ResteChaine,length(ResteChaine)-pos(' ',ResteChaine));
        end;
          MaChaine:=MaChaine+ResteChaine;
          if Trim(MaChaine)<>'' then
          SL.Add(MaChaine);
          MaChaine:='';
          ResteChaine:='';
      end;
      SL.SaveToFile('C:\TonDossier\TonFichier.txt');
      SL.Free;
    end;
    A+

  5. #5
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut tous les nombres sur une seule ligne
    salut
    je voudrais avoirtous les nombres sur une seule ligne

    3293898;3169524;215285;1185310;54067;8146382.00;11887233.00;824826.00;6716994.00;222421.00;140749;18387.00;18612;13633;407;10566;1037;587125.00;643482.00;20200.00;562805.00;54850.00
    La patience est un Chemin d'or

  6. #6
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut ca marche ,sauf une coquille...
    salut

    voila ton code que j'ai adapté a mes besoins
    mais j'ai une erreur du débogeur.
    voici les images des notifications du débogeur
    [IMG][IMG]C:\Documents and Settings\jtchamdja\Bureau\souhait\sans titre2[/IMG][/IMG]

    là je suis k.o

    code:

    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
    if savedialog1.execute then
    begin
       begin
       assignfile(F,savedialog1.filename+'.txt');
       rewrite(F);
       end;
          if fileexists(savedialog1.filename) then      
      SL:=TStringList.Create;
      MaChaine:='';
      for i:=0 to Memo1.Lines.Count-1 do
      begin
        ResteChaine:=Trim(RightStr(Memo1.Lines.Strings[i],Length(Memo1.Lines.Strings[i])-pos(' ',Memo1.Lines.Strings[i])));
        while (pos(' ',ResteChaine)>0) do
        begin
          MaChaine:=MaChaine+copy(ResteChaine,1,pos(' ',ResteChaine)-1)+';';
          ResteChaine:=RightStr(ResteChaine,length(ResteChaine)-pos(' ',ResteChaine));
        end;
          MaChaine:=MaChaine+ResteChaine+';';
      end;
      // Suppression du dernier ';'
      MaChaine:=copy(MaChaine,1,Length(Machaine)-1);
      SL.Add(MaChaine);
     
      // pour écrire la première ligne
     
      SL[i-1]:=('DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
     
      SL.Strings[i] := datefic+'|' + SL.Strings[i];
      SL.SaveToFile(savedialog1.filename+'.txt');
      SL.Free;
     
    end;
    end;
     
    end;
    end;
    La patience est un Chemin d'or

  7. #7
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Re,

    Excuses moi, j'avais supprimé mon post précédent car je me suis rendu compte qu'il ne collait pas entièrement à tes attentes.

    Voici le nouveaux code :

    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
    procedure TForm1.Button1Click(Sender: TObject);
    var
    ligne:string;
    MaChaine:string;
    Nb:String;
    i:integer;
    SL:TStringList;
    entier:double;
    begin
      SL:=TStringList.Create;
      MaChaine:='';
      for i:=0 to Memo1.Lines.Count-1 do
      begin
        ligne:=StringReplace(Memo1.Lines[i],'.',',',[rfReplaceAll]);
        ShowMessage(ligne);
        while (pos(' ',ligne)>0) do
        begin
          Nb:=copy(ligne,1,pos(' ',ligne)-1);
          if (TryStrToFloat(Nb,entier)) then
          begin
            ShowMessage(MaChaine);
            MaChaine:=MaChaine+Nb+';';
          end;
          ligne:=RightStr(ligne,length(ligne)-pos(' ',ligne));
        end;
     
        if (TryStrToFloat(ligne,entier)) then
        begin
          MaChaine:=MaChaine+ligne+';';
        end;
     
      end;
      SL.Add(MaChaine);
      //ShowMessage(SL.Text);
      SL.SaveToFile('C:\toto.txt');
      SL.Free;
    end;
    J'ai testé vite fait et ça à l'aire de fonctionner

    PS: Lorsque tu mets du code, penses aux balises CODE (le # dans la barre de menu) stp! Ca serait super

  8. #8
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut toujours le bug
    salut,
    merci bien mais,
    j'ai toujours le message du débogeur avec,une modification de l'adresse de violation d'accès qui est maintenant de 00472FB2 dans le module de mon exe.


    la ligne SL.Add(MaChaine); est souligné en bleu
    La patience est un Chemin d'or

  9. #9
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Peut tu nous poster le code intégral de la procédure qui te permet de sauvegarder le fichier STP ? (car là, sans code on ne sera pas)

    Merci

  10. #10
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut voila le code
    salut
    voila le code.

    désolé j'ai pas eu le temps de le commenter.ca ira j'espère
    merci



    code
    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
    procedure TFrm.Butt_statClick(Sender: TObject);
     var i:integer;
    ligne:string;
    MaChaine:string;
    Nb:String;
    SL:TStringList;
    entier:double;
    F:TextFile;
     
     
    begin
    if savedialog1.execute then
    begin
       begin
       assignfile(F,savedialog1.filename+'.txt');
       rewrite(F);
       end;
          if fileexists(savedialog1.filename) then
     SL:=TStringList.Create;
      MaChaine:='';
      for i:=0 to Memo1.Lines.Count-1 do
      begin
        ligne:=StringReplace(Memo1.Lines[i],'.',',',[rfReplaceAll]);
        //ShowMessage(ligne);
        while (pos(' ',ligne)>0) do
        begin
          Nb:=copy(ligne,1,pos(' ',ligne)-1);
          if (TryStrToFloat(Nb,entier)) then
          begin
            //ShowMessage(MaChaine);
            MaChaine:=MaChaine+Nb+';';
          end;
          ligne:=RightStr(ligne,length(ligne)-pos(' ',ligne));
        end;
     
        if (TryStrToFloat(ligne,entier)) then
        begin
          MaChaine:=MaChaine+ligne+';';
        end;
      end;
      SL.Add(MaChaine);
      SL[i-1]:=('DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
      SL.Strings[i] := (copy(datefic,1,8 ))+ '|' + SL.Strings[i];
      SL.SaveToFile(savedialog1.filename+'.txt');
      SL.Free;
     
    ShowMessage('Le fichier  '+ExtPart+'  a été formaté avec succès');
    extension:='';
    end
      else
    begin
       if MessageDlg('Souhaitez-vous interrompre le reformatage du fichier?',mtWarning,[mbYes,mbNo],0)=mryes then
        begin
        showmessage('Processus de reformatage interrompu par l'' utilisateur');
       exit;
     
    end
    else
    begin
    MessageDlg('L''opération est incorrecte.Vous n''avez pas chargé ce type de fichier',mtWarning,[mbOk],0);
    end;
     memo1.Clear;
        end;
    end;
    La patience est un Chemin d'or

  11. #11
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    SAlut
    Il serait bien comme dis plus haut qu'une fois ton code coller dans le corps du message, tu le selectionne et que tu appui sur le bouton # de l'editeur, ca inserera ton code das des balise Code et ca sera bien plus difeste
    Par ce que la c'est pas evident de s'y retrouver dans tout se b***** ( a ben non Bazard ca va c pas grossier... on s'y perd)
    A++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  12. #12
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Comme le dit Qwazerty, pas simple de s'y retrouver ... j'ai indenté le tout et j'essaie de comprendre ton code ....

    Après formatage et épuration, voilà le code :

    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
    procedure TForm1.Butt_statClick(Sender: TObject);
    var i:integer;
    ligne:string;
    MaChaine:string;
    Nb:String;
    SL:TStringList;
    entier:double;
    F:TextFile;
    begin
      if savedialog1.execute then
      begin
        assignfile(F,savedialog1.filename+'.txt');
        rewrite(F);
     
        SL:=TStringList.Create;
        MaChaine:='';
     
        for i:=0 to Memo1.Lines.Count-1 do
        begin
          ligne:=StringReplace(Memo1.Lines[i],'.',',',[rfReplaceAll]);
          while (pos(' ',ligne)>0) do
          begin
            Nb:=copy(ligne,1,pos(' ',ligne)-1);
            if (TryStrToFloat(Nb,entier)) then
            begin
              //ShowMessage(MaChaine);
              MaChaine:=MaChaine+Nb+';';
            end;
            ligne:=RightStr(ligne,length(ligne)-pos(' ',ligne));
          end;
     
          if (TryStrToFloat(ligne,entier)) then
          begin
            MaChaine:=MaChaine+ligne+';';
          end;
        end;
     
        SL.Add(MaChaine);
        SL[i-1]:=('DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
        SL.Strings[i] := (copy(datefic,1,8 ))+ '|' + SL.Strings[i];
        SL.SaveToFile(savedialog1.filename+'.txt');
        SL.Free;
     
        ShowMessage('Le fichier '+ExtPart+' a été formaté avec succès');
        extension:='';
      end
      else
      begin
        if MessageDlg('Souhaitez-vous interrompre le reformatage du fichier?',mtWarning,[mbYes,mbNo],0)=mryes then
        begin
          showmessage('Processus de reformatage interrompu par l'' utilisateur');
          exit;
        end
        else
        begin
          MessageDlg('L''opération est incorrecte.Vous n''avez pas chargé ce type de fichier',mtWarning,[mbOk],0);
        end;
      memo1.Clear;
      end;
    end;
    Bien entendu, je ne sais te dire si il fonctionne ...
    Peux tu m'éclairer sur un point :

    Qu'est ce tu veux faire avec ce bout de code ci dessous :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    SL[i-1]:=('DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
        SL.Strings[i] := (copy(datefic,1,8 ))+ '|' + SL.Strings[i];
    Je ne comprends pas trop

  13. #13
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    SAlut
    Je crois que tu devrais chercher sur le forum et dans l'aide delphi la fonction Val, il me semble avoir lu sur le forum qu'elle permet de sortir les valeur numeric d'une chaine ce qui je pense arrangerais grandement tes affaire et simplifierai d'autant ton code
    A++
    Qwaz

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  14. #14
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut
    salut

    1. la première ligne code doit me permettre d'écrire un en-tete dans le fichier
    2. ensuite la 2e ligne me permet d'ajouter au début de chaque ligne une date de création du fichier.


    [Avertissement] Unit1.pas(281): La variable de boucle FOR 'i' est peut-être indéfinie après la boucle

    Mais je bug toujours avec cet avertissemnt

    Avertissement] Unit1.pas(281): La variable de boucle FOR 'i' est peut-être indéfinie après la boucle

    cette fois cette fois les messages d'erreurs sont les suivant:

    [IMG]C:\Documents and Settings\jtchamdja\Bureau\souhait\error[/IMG]

    [IMG]C:\Documents and Settings\jtchamdja\Bureau\souhait\error2[/IMG]
    La patience est un Chemin d'or

  15. #15
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    Re
    Pour les partie numeric tu as ca

    Je regarder le reste

    [Edit]
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if savedialog1.execute then
    begin
       begin
    J'avais cru a un copier coller malheureux mais je vois que tu persiste et signe
    Tu veux faire quoi exactement avec ces 2 begin qui se suive ?

    [/Edit]
    a+

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  16. #16
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Donc, si je reprends depuis le début, tu veux enregistrer tes données dans un fichier. Apparemment, tu veux sélectionner le fichier dans lequel on va créer les enregistrement.

    Si il existe, on l'ouvre en ajout et on rajoute les statistisques, sinon, on le crée c'est bien ça ?

    EDIT:

    La date de création de la ligne doit être celle lors de la génération de la ligne ou c'est stocké quelque part ? On peut prendre la date système non ?

  17. #17
    Expert éminent
    Avatar de Qwazerty
    Homme Profil pro
    La très haute tension :D
    Inscrit en
    Avril 2002
    Messages
    3 898
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : La très haute tension :D
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2002
    Messages : 3 898
    Points : 8 529
    Points
    8 529
    Par défaut
    Alors pour les message d'erreur, celui

    [Avertissement] Unit1.pas(281): La variable de boucle FOR 'i' est peut-être indéfinie après la boucle
    Normale tu utilise i a l'exterieur de ta boucle

    en gros tu as

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    For I := 0 to 10
    begin
    [...]
    End;
     SL[i-1]:=('DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
    Ca n'est qu'un avertissement, dans ce cas I prendrait la valeur 11 (10+1)

    Si tu veux joindre des images utilise plutot la gestion des piece jointe, c'est un bouton qui se trouve en dessous de la partie ou tu tapes tes messages

    MagicQwaz := Harry Potter la baguette en moins
    Le monde dans lequel on vit
    Ma page perso DVP
    Dernier et Seul Tutoriel : VBA & Internet Explorer
    Dernière contribution : Lien Tableau Structuré et UserForm
    L'utilisation de l’éditeur de message

  18. #18
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Re,

    Je viens de faire vite fait "ma" version qui colle à la tienne mais j'ai simplifié un peu les tests ...

    Voici le code :

    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
    procedure TForm1.butt_statClick(Sender: TObject);
    var i:integer;
    ligne:string;
    MaChaine:string;
    Nb:String;
    entier:double;
    F:TextFile;
    NomFichier:string;
    begin
      if savedialog1.execute then
      begin
        NomFichier:=savedialog1.filename;
        AssignFile(F,NomFichier);
        if (FileExists(NomFichier)) then
          Append(F)
        else
        begin
          rewrite(F);
          Writeln(F,'DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
        end;
     
        MaChaine:='';
        for i:=0 to Memo1.Lines.Count-1 do
        begin
          ligne:=StringReplace(Memo1.Lines[i],'.',',',[rfReplaceAll]);
          while (pos(' ',ligne)>0) do
          begin
            Nb:=copy(ligne,1,pos(' ',ligne)-1);
            if (TryStrToFloat(Nb,entier)) then
            begin
              //ShowMessage(MaChaine);
              MaChaine:=MaChaine+Nb+';';
            end;
            ligne:=RightStr(ligne,length(ligne)-pos(' ',ligne));
          end;
     
          if (TryStrToFloat(ligne,entier)) then
          begin
            if (i= Memo1.Lines.Count-1) then
            MaChaine:=MaChaine+ligne
            else
            MaChaine:=MaChaine+ligne+';';
          end;
        end;
        MaChaine:=DateToStr(Now)+';'+MaChaine;
        Writeln(F,MaChaine);
     
        ShowMessage('Le fichier a été formaté avec succès');
        CloseFile(F);
      end
      else
      begin
        MessageDlg('L''opération est incorrecte.Vous n''avez pas chargé ce type de fichier',mtWarning,[mbOk],0);
      end;
      memo1.Clear;
    end;
    Il doit avoir certaines quelques erreurs lors de la sélection du fichier (test sur l'extension par exemple) mais là ce soir, j'ai pas le temps d'approfondir. Néanmoins, le code fonctionne en toute logique.

    A+

    PS: Désolé pour la mise en forme, ma souris a glissé chef

  19. #19
    Membre du Club Avatar de bigey3
    Profil pro
    Inscrit en
    Décembre 2007
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Décembre 2007
    Messages : 124
    Points : 50
    Points
    50
    Par défaut j'y suis presque...
    salut,
    j'ai travailler toute la nuit sur un code que voici.j'y suis arrivé presque sauf que les sauts de ligne son aussi pris en compte.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost|TgcelSmsCost|TgtelSmsCost|InterSmsCost|OtherSmsCost|
     
    20071001|3293898|3169524|215285|1185310|54067|8146382.00|11887233.00|824826.00|6716994.00|222421.00|||140749|18387.00|||18612|13633|407|10566|1037|587125.00|643482.00|20200.00|562805.00|54850.00||

    le seul problème est que je souhaite avoir un unique séparateur entre tous les nombres.



    j'ai constaté que l'endroit où on a plusieurs séparateurs en meme temps coincident avec les sauts de ligne entre les blocs de texte de mon mémo.


    ORIGINATING VOICE
    Operator Moov Togocel Togotelecom Internatnl Others
    Duration 3293898 3169524 215285 1185310 54067
    Cost 8146382.00 11887233.00 824826.00 6716994.00 222421.00

    FORWARDING VOICE
    Operator ALL
    Duration 140749
    Cost 18387.00

    SMS
    Operator Moov Togocel Togotelecom Internatnl Others
    Count 18612 13633 407 10566 1037
    Cost 587125.00 643482.00 20200.00 562805.00 54850.00




    code:
    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
    80
    81
     
    procedure TFrm.Butt_statClick(Sender: TObject);
     var i,j,k:integer;
    Nbre,MonTexte:string;
    Tab:array of string;
    F:TextFile;
     
    begin
    if savedialog1.execute then
    begin
       begin
       assignfile(F,savedialog1.filename+'.txt');
       rewrite(F);
       end;
          if fileexists(savedialog1.filename) then
          append(F)else
          rewrite(F);
          writeln(F,'DateeStat|','MoovOrigDur|','TgcelOrigDur|','TgtelOrigDur|','InterOrigDur|','OtherOrigDur|','MoovOrigCost|','TgcelOrigCost|','TgtelOrigCost|','InterOrigCost|','OtherOrigCost|','ForwVoiceDur|','ForwVoiceCost|','MoovSmsCount|','TgcelSmsCount|','TgtelSmsCount|','InterSmsCount|','OtherSmsCount|','MoovSmsCost|','TgcelSmsCost|','TgtelSmsCost|','InterSmsCost|','OtherSmsCost|');
          write(F,'  ');
          writeln(F,'');
          write(F,copy(datefic,1,8 )+'|');
       j:=0;
      cpt:=0;
      SetLength(Tab,j);
     Nbre:='';
    lig:='';
    SetLength(Tab,j);
    for k := 2 to memo1.Lines.Count do
    begin
      MonTexte:=Memo1.lines[k];
      for i:=1 to Length(MonTexte) do
      begin
        if MonTexte[i] in ['0'..'9'] then
          Nbre:=Nbre+MonTexte[i]
             else if MonTexte[i] = '.' then
              Nbre:=Nbre+MonTexte[i]
             //  else if ((MonTexte[i] = ' ') and (MonTexte[i+10] = ' '))  then
               //Nbre:=Nbre+''
        else
     
        begin
          if ((Nbre<>'') or ((i=length(MonTexte)) and (Nbre='')))  then
          begin
            SetLength(Tab,j+1);
            Tab[j]:=Nbre;
            j:=j+1;
            lig:=lig+Nbre;
     
             if  (Nbre=' ') then
            begin
              lig:=lig+'|';
            end;
            begin
              //ShowMessage(lig);
              Write(F,trim(lig+'|'));
              lig:='';
            end;
            end;
            Nbre:='';
          end;
        end
      end;
    CloseFile(F);
    ShowMessage('Le fichier  '+ExtPart+'  a été formaté avec succès');
    extension:='';
    end
      else
    begin
       if MessageDlg('Souhaitez-vous interrompre le reformatage du fichier?',mtWarning,[mbYes,mbNo],0)=mryes then
        begin
        showmessage('Processus de reformatage interrompu par l'' utilisateur');
       exit;
       end;
    end
    else
    begin
    MessageDlg('L''opération est incorrecte.Vous n''avez pas chargé ce type de fichier',mtWarning,[mbOk],0);
    Butt_charg.SetFocus;
    end;
     memo1.Clear;
    end;
    La patience est un Chemin d'or

  20. #20
    Rédacteur/Modérateur
    Avatar de ero-sennin
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2005
    Messages
    2 965
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 2 965
    Points : 4 935
    Points
    4 935
    Par défaut
    Salut,

    Attention, hier j'ai édité mon code car j'avais une condition qui merdait! Je l'ai corrigé, donc si tu ne l'a pas pris en compte, en effet, il manque des lignes.

    Je te remet le code fonctionnel :


    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
    procedure TForm1.butt_statClick(Sender: TObject);
    var i:integer;
    ligne:string;
    MaChaine:string;
    Nb:String;
    entier:double;
    F:TextFile;
    NomFichier:string;
    begin
      if savedialog1.execute then
      begin
        NomFichier:=savedialog1.filename;
        AssignFile(F,NomFichier);
        if (FileExists(NomFichier)) then
          Append(F)
        else
        begin
          rewrite(F);
          Writeln(F,'DateeStat|MoovOrigDur|TgcelOrigDur|TgtelOrigDur|InterOrigDur|OtherOrigDur|MoovOrigCost|TgcelOrigCost|TgtelOrigCost|InterOrigCost|OtherOrigCost|ForwVoiceDur|ForwVoiceCost|MoovSmsCount|TgcelSmsCount|TgtelSmsCount|InterSmsCount|OtherSmsCount|MoovSmsCost');
        end;
     
        MaChaine:='';
        for i:=0 to Memo1.Lines.Count-1 do
        begin
          ligne:=StringReplace(Memo1.Lines[i],'.',',',[rfReplaceAll]);
          while (pos(' ',ligne)>0) do
          begin
            Nb:=copy(ligne,1,pos(' ',ligne)-1);
            if (TryStrToFloat(Nb,entier)) then
            begin
              //ShowMessage(MaChaine);
              MaChaine:=MaChaine+Nb+'|';
            end;
            ligne:=RightStr(ligne,length(ligne)-pos(' ',ligne));
          end;
     
          if (TryStrToFloat(ligne,entier)) then
          begin
            if (i= Memo1.Lines.Count-1) then
            MaChaine:=MaChaine+ligne
            else
            MaChaine:=MaChaine+ligne+'|';
          end;
        end;
        MaChaine:=DateToStr(Now)+'|'+MaChaine;
        Writeln(F,MaChaine);
     
        ShowMessage('Le fichier a été formaté avec succès');
        CloseFile(F);
      end
      else
      begin
        MessageDlg('L''opération est incorrecte.Vous n''avez pas chargé ce type de fichier',mtWarning,[mbOk],0);
      end;
      memo1.Clear;
    end;
    A toi de voir pour l'adapter car j'ai simplifié la chose ...

    A+

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [JavaDoc] Comment faire un saut de ligne?
    Par petozak dans le forum Langage
    Réponses: 2
    Dernier message: 31/08/2006, 17h26
  2. ETAT - Ignorer les sauts de ligne dans un champ mémo
    Par superseba888 dans le forum Access
    Réponses: 4
    Dernier message: 14/08/2006, 02h27
  3. [C# 1.1] Comment supprimer un saut de ligne
    Par foolsky dans le forum Windows Mobile
    Réponses: 2
    Dernier message: 26/04/2006, 17h28
  4. [DOS] Comment insérer un saut de ligne ?
    Par Filippo dans le forum Autres Logiciels
    Réponses: 9
    Dernier message: 01/12/2005, 16h12
  5. Comment faire un saut de ligne dans un IMG - Title ?
    Par jlbinfo dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 19/10/2005, 18h28

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