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

VB.NET Discussion :

[vb.net] pb d'exécution d'un programme


Sujet :

VB.NET

  1. #1
    Membre éclairé Avatar de lou87
    Profil pro
    Inscrit en
    Février 2006
    Messages
    368
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 368
    Par défaut [vb.net] pb d'exécution d'un programme
    Bonjour !

    J'aimerais copier dans un fichier texte, à un endroit précis, des données que j'aurais récupérer de mon interface graphique.

    Voici mon 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
       Function Rafraichissement_LSI()
     
            Dim fileR As StreamReader
            Dim fileW As StreamWriter
            Dim ts As FileStream
            Dim i, j As Integer
            Dim tbl_string() As String
            Dim cellule As String = listder_cellule.Text
            Dim Date_debut As String = Date_deb.Text
            Dim Date_final As String = Date_fin.Text
            Dim logiciel As String = listder_lib_logi_micro.Text
            Dim type_incident As String = listder_type_incident.Text
            Dim domaine As String = listder_domaine_info.Text
     
            MsgBox(Date_debut)
            MsgBox(Date_final)
            MsgBox(cellule)
            MsgBox(logiciel)
            MsgBox(type_incident)
            MsgBox(domaine)
     
            'modification de la date de traitement dans le fichier de paramètres Parambo.txt pour le prochain rafraichissement des requetes LSI
            Dim file As New System.IO.StreamReader("\\beaqae\HDC_ESPACE_COMMUN\Statistiques\Applications\Developpements\Suivi_TR_NIV2\Parambo.txt")
     
            i = 1
     
            Do
                ReDim Preserve tbl_string(i)
     
                tbl_string(i) = file.ReadToEnd
     
                If tbl_string(i) = "END" Then
                    Exit Do
                End If
                If tbl_string(i) Like "N,Cell = %" = True Then
                    tbl_string(i) = "N,Cell = " & cellule
                End If
                If tbl_string(i) Like "D,Date_deb = %" = True Then
                    tbl_string(i) = "D,Date_deb = " & Date_debut
                End If
                If tbl_string(i) Like "D,Date_fin = %" = True Then
                    tbl_string(i) = "D,Date_fin = " & Date_final
                End If
                If tbl_string(i) Like "N,Logiciel = %" = True Then
                    tbl_string(i) = "N,Logiciel = " & logiciel
                End If
                If tbl_string(i) Like "N,Type = %" = True Then
                    tbl_string(i) = "N,Type = " & type_incident
                End If
                If tbl_string(i) Like "N,Domaine = %" = True Then
                    tbl_string(i) = "N,Domaine = " & domaine
                End If
                i = i + 1
            Loop
     
            file.Close()
            file = Nothing
     
            Dim file1 As New System.IO.StreamWriter("\\beaqae\HDC_ESPACE_COMMUN\Statistiques\Applications\Developpements\Suivi_TR_NIV2\Parambo.txt")
            For j = 1 To i
                file1.WriteLine(tbl_string(j))
            Next
            file1.Close()
            file1 = Nothing
     
        End Function
    Je sais que mon programme n'avance pas car le do loop fait reboucler je ne sais combien de fois le code, et puis quand je décale le débuggueur afin de voir s'il m'écrit ce que je veux à la bonne place, et bien en faite il m'efface mon fichier texte et ne m'écrit rien....

    Faut-il que je prenne autre chose que StreamWriter ou StreamReader ? Ou quelque chose dans ce genre ?

    Merci d'avance.

    P.S : J'ai en faite repris un bout de programme en vba et essayer de la retranscrire en vb.net.

    Si cela peut aider, je met le bout de programme en vba.

    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
    Public Sub Ecriture_Parambo(ByVal DateTraitement As Date, ByVal Chemin As String)
     
            Dim fs As New FileSystemObject
            Dim ts As TextStream
            Dim i As Integer
            Dim tbl_string() As String
     
            'modification de la date de traitement dans le fichier de paramètres Parambo.txt pour le prochain rafraichissement des requetes LSI
            ts = fs.OpenTextFile(Chemin & "\Parambo.txt", ForReading)
            i = 1
            Do
                ReDim Preserve tbl_string(i)
                tbl_string(i) = ts.ReadLine
                If tbl_string(i) = "END" Then
                    Exit Do
                End If
                If tbl_string(i) Like "D,DATE = *" = True Then
                    tbl_string(i) = "D,DATE = " & DateTraitement
                End If
                i = i + 1
            Loop
            ts.Close()
     
            ts = fs.OpenTextFile(Chemin & "\Parambo.txt", ForWriting)
            For j = 1 To i
                ts.WriteLine(tbl_string(j))
            Next
            ts.Close()
            ts = Nothing
            fs = Nothing
     
     
     
        End Sub

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    Demande à ton tuteur si du XML ca leur conviendrait au lieu du TXT !

    change le nom de ton topic !

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Dim fileR As StreamReader
            Dim fileW As StreamWriter
    pk tu en redéclare 2 autres apres ?

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Function Rafraichissement_LSI()
     
    End Function
    PK fonction ?

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    tu dois utiliser un File.AppendText(fichier)

    (edit) ... pas forcement

  7. #7
    Membre éclairé Avatar de lou87
    Profil pro
    Inscrit en
    Février 2006
    Messages
    368
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 368
    Par défaut
    Parce que je l'appelle dans un bouton.

    Plus exactement dans mon bouton "Rechercher".

    File.AppendText(Fichier) c'est pour modifier les données d'un fichier, c'est ça ?

    Merci de ton aide.

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    Citation Envoyé par lou87
    Parce que je l'appelle dans un bouton.

    Plus exactement dans mon bouton "Rechercher".

    File.AppendText(Fichier) c'est pour modifier les données d'un fichier, c'est ça ?

    Merci de ton aide.
    Lou ....

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Sub blabla   'Private ?
           'blabla
    End Sub
     
    blabla()

  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    J'avais un peu de temps ca fonctionne

    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
    Private Sub Rafraichissement_LSI()
     
            Dim lecture As StreamReader
            Dim ecriture As StreamWriter
            Dim ligne As String
            Dim tableau(50) As String
            Dim i As Byte
     
            Dim fichier As String = "C:\Documents and Settings\Administrateur\Bureau\Parambo.txt"
     
            Dim cellule As String = listder_cellule.Text
            Dim Date_debut As String = Date_deb.Text
            Dim Date_final As String = Date_fin.Text
            Dim logiciel As String = listder_lib_logi_micro.Text
            Dim type_incident As String = listder_type_incident.Text
            Dim domaine As String = listder_domaine_info.Text
     
     
            If Not File.Exists(fichier) Then
                MsgBox("le fichier n'existe pas", MsgBoxStyle.Exclamation)
            Else
                Try
     
                Catch ex As Exception
                    MsgBox("erreur en ouverture du fichier", MsgBoxStyle.Critical)
                    End 'sortie du programme
                End Try
                i = 1
                'lecture du fichier
                lecture = New StreamReader(fichier)
                Do While lecture.Peek() <> -1 ' lecture séquentielle du fichier
                    Try
                        ligne = lecture.ReadLine()
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Critical)  ' ex = nom de l'exception
                    End Try
                    tableau(i) = ligne
                    i = i + 1
                Loop
                lecture.Close()
            End If
     
     
            'Mise a jour dans le tableau!!
     
            tableau(22) = "N,Cell = " & cellule
            tableau(23) = "D,Date_deb = " & Date_debut
            tableau(24) = "D,Date_fin = " & Date_final
            tableau(25) = "N,Logiciel = " & logiciel
            tableau(26) = "N,Type = " & type_incident
            tableau(27) = "N,Domaine = " & domaine
     
            'écriture du fichier
            ecriture = New StreamWriter(fichier)
     
            Try
                For i = 1 To 30
                    ecriture.WriteLine(tableau(i))
                Next
                'gestion d'une erreur d'écriture
            Catch
                MsgBox("erreur d'écriture", MsgBoxStyle.Critical)
            End Try
            ecriture.Close()
            MsgBox("fichier mis à jour avec succès", MsgBoxStyle.Information)
     
        End Sub

  10. #10
    Membre éclairé Avatar de lou87
    Profil pro
    Inscrit en
    Février 2006
    Messages
    368
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 368
    Par défaut
    Merci beaucoup 6su7 !!!!


  11. #11
    Membre éclairé Avatar de lou87
    Profil pro
    Inscrit en
    Février 2006
    Messages
    368
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 368
    Par défaut
    Mais j'ai remarqué une petite anomalie dans l'exécution du programme...

    Lorsqu'il recopie le texte, il ne me met pas les caractère spéciaux, tel que 'é' ou encore '£'....

    Docn j'ai dut modifier un peu ce que l'on m'as donné :

    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
      Private Sub Rafraichissement_LSI()
    
            Dim lecture As StringReader
            Dim ecriture As StringWriter
            Dim ligne As String
            Dim tableau(50) As String
            Dim i As Byte
    
            Dim fichier As String = "C:\Document\Parambo.txt""
    
            Dim cellule As String = listder_cellule.Text
            Dim Date_debut As String = Date_deb.Text
            Dim Date_final As String = Date_fin.Text
            Dim logiciel As String = listder_lib_logi_micro.Text
            Dim type_incident As String = listder_type_incident.Text
            Dim domaine As String = listder_domaine_info.Text
    
    
            If Not File.Exists(fichier) Then
                MsgBox("le fichier n'existe pas", MsgBoxStyle.Exclamation)
            Else
                Try
    
                Catch ex As Exception
                    MsgBox("erreur en ouverture du fichier", MsgBoxStyle.Critical)
                    End 'sortie du programme
                End Try
                i = 1
                'lecture du fichier
                lecture = New StringReader(fichier)
                Do While lecture.Peek() <> -1 ' lecture séquentielle du fichier
                    Try
                        ligne = lecture.ReadLine()
                    Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Critical)  ' ex = nom de l'exception
                    End Try
                    tableau(i) = ligne
                    i = i + 1
                Loop
                lecture.Close()
            End If
    
            'Mise a jour dans le tableau!!
    
            tableau(22) = "N,Cell = " & cellule
            tableau(23) = "D,Date_deb = " & Date_debut
            tableau(24) = "D,Date_fin = " & Date_final
            tableau(25) = "N,Logiciel = " & logiciel
            tableau(26) = "N,Type = " & type_incident
            tableau(27) = "N,Domaine = " & domaine
    
            'écriture du fichier
            ecriture = New StringWriter(fichier)
            Try
                For i = 1 To 27
                    ecriture.WriteLine(tableau(i))
                Next
                'gestion d'une erreur d'écriture
            Catch
                MsgBox("erreur d'écriture", MsgBoxStyle.Critical)
            End Try
            ecriture.Close()
            MsgBox("fichier mis à jour avec succès", MsgBoxStyle.Information)
    
        End Sub
    L'inconvénient c'est que le bout de code en violet est souligné et que je n'arrive pas à résoudre le problème....

    Le pop-up d'erreur est :


    Si vous avez une idée, merci.

  12. #12
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    212
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 212
    Par défaut
    l'import du IO c'est bien fait ?

    essais "as System.IO.StringReader"

  13. #13
    Membre éclairé Avatar de lou87
    Profil pro
    Inscrit en
    Février 2006
    Messages
    368
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 368
    Par défaut
    Bonjour !

    Cela n'a pas résolu mon problème de mettre as System.IO.StringWriter au lieu de as StringWriter....

    Merci quand même.

  14. #14
    Membre éprouvé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 115
    Par défaut
    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
    'Pour l'écriture :
            Dim ecriture As IO.StreamWriter
            Dim fichier As String = "C:\Document\Parambo.txt"
            Dim tableau(50) As String
            Dim i As Integer
     
     
            Try
                ecriture = IO.File.CreateText(fichier)
                For i = 1 To 27
                    ecriture.WriteLine(tableau(i))
                Next
                ecriture.Close()
            Catch
                'MsgBox("erreur d'écriture", MsgBoxStyle.Critical)
            End Try
     
     
            MsgBox("fichier mis à jour avec succès", MsgBoxStyle.Information)
    StreamWriter, pas String

Discussions similaires

  1. [SQL Server 2000][DTS][NET 1.1] Exécution d'un package DTS
    Par aldbaran dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 02/02/2006, 11h26
  2. Réponses: 7
    Dernier message: 24/10/2005, 23h10
  3. Problème lors de l'exécution de mes programmes
    Par darkmalak01 dans le forum Langage
    Réponses: 7
    Dernier message: 27/09/2005, 18h35
  4. Réponses: 1
    Dernier message: 05/09/2005, 11h37
  5. Exécution d'un programme hors session
    Par skywaukers dans le forum Langage
    Réponses: 3
    Dernier message: 07/07/2005, 10h31

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