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

Windows Forms Discussion :

Ecriture et lecture d'un fichier config


Sujet :

Windows Forms

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2006
    Messages : 16
    Points : 8
    Points
    8
    Par défaut Ecriture et lecture d'un fichier config
    : roll: Bonjour à tous et à toutes ...

    Voila ma question, je développe une petite application ou il est possible de changer le nom de boutons selon le choix de l'utilisateur

    Pour cela j'ai créé des TextBox pour que l'utilisater puisse saisir le nom de son choix. Ce nom est également stoqué dans une variable.

    Chaque TextBox Comporté Label pour indiquer à quel bouton elle se refere, Et si la TextBox est vide le Nom, la TextBox et la variable Prenent Comme valeur le label.text
    Voila 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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    Private Sub PanelMnemo_Paint (ByVal sender As System.Object ByVal e, Comme System.Windows.Forms.PaintEventArgs) Poignées PanelMnemo.Paint
    If TextBox_Bex.Text = "" Then
    TextBox_Bex.Text = Label_Bex.Text
    End If
    If TextBox_BalBlanc1.Text = "" Then
    TextBox_BalBlanc1.Text = Label_BalBlanc1.Text
    End If
    If TextBox_BalBlanc2.Text = "" Then
    TextBox_BalBlanc2.Text = Label_BalBlanc2.Text
    End If
    If TextBox_BalNoir.Text = "" Then
    TextBox_BalNoir.Text = Label_BalNoir.Text
    End If
    If TextBox_BalMire.Text = "" Then
    TextBox_BalMire.Text = Label_MireBarre.Text
    End If
    If TextBox_EntGr1.Text = "" Then
    TextBox_EntGr1.Text = Label_Entree1.Text
    End If
    If TextBox_EntGr2.Text = "" Then
    TextBox_EntGr2.Text = Label_Entree2.Text
    End If
    If TextBox_EntGr3.Text = "" Then
    TextBox_EntGr3.Text = Label_Entree3.Text
    End If
    If TextBox_EntGr4.Text = "" Then
    TextBox_EntGr4.Text = Label_Entree4.Text
    End If
    If TextBox_EntGr5.Text = "" Then
    TextBox_EntGr5.Text = Label_Entree5.Text
    End If
    if TextBox_EntGr6.Text = "" Then
    TextBox_EntGr6.Text = Label_Entree6.Text
    End If
    Si TextBox_EntGr7.Text = "" Then
    TextBox_EntGr7.Text = Label_Entree7.Text
    End If
    if TextBox_EntGr8.Text = "" Then
    TextBox_EntGr8.Text = Label_Entree8.Text
    End If
    if TextBox_Mem1.Text = "" Then
    TextBox_Mem1.Text = Label_Mem1.Text
    End If
    if TextBox_Mem2.Text = "" Then
    TextBox_Mem2.Text = Label_Mem2.Text
    End If
    Si TextBox_Mem3.Text = "" Then
    TextBox_Mem3.Text = Label_Mem3.Text
    End If
    If TextBox_Mem4.Text = "" Then
    TextBox_Mem4.Text = Label_Mem4.Text
    End If
    If TextBox_Mem5.Text = "" Then
    TextBox_Mem5.Text = Label_Mem5.Text
    End If
    Si TextBox_Mem6.Text = "" Then
    TextBox_Mem6.Text = Label_Mem6.Text
    End If
    If TextBox_Mem7.Text = "" Then
    TextBox_Mem7.Text = Label_Mem7.Text
    End If
    Si TextBox_Mem8.Text = "" Then
    TextBox_Mem8.Text = Label_Mem8.Text
    End If
    If TextBox_Sortie1.Text = "" Then
    TextBox_Sortie1.Text = Label_Sortie1.Text
    End If
    If TextBox_Sortie2.Text = "" Then
    TextBox_Sortie2.Text = Label_Sortie2.Text
    End If
    If TextBox_Sortie3.Text = "" Then
    TextBox_Sortie3.Text = Label_Sortie3.Text
    End If
    If TextBox_Sortie4.Text = "" Then
    TextBox_Sortie4.Text = Label_Sortie4.Text
    End If
    If TextBox_Sortie5.Text = "" Then
    TextBox_Sortie5.Text = Label_Sortie5.Text
    End If
    If TextBox_Sortie6.Text = "" Then
    TextBox_Sortie6.Text = Label_Sortie6.Text
    End If
    If TextBox_Sortie7.Text = "" Then
    TextBox_Sortie7.Text = Label_Sortie7.Text
    End If
    If TextBox_Sortie8.Text = "" Then
    TextBox_Sortie8.Text = Label_Sortie8.Text
    End If
    End Sub
    J'aurais du le faire avec un ableau et Une boucle mais je n'y suis pas parvenu. Je m'y repencherais plus tard. Se qui est sur c'est qu'il existe une méthode plus simple et une boucle pourait se charger du coté repétitif de ce code. Mais bon.

    Pour ne pas à avoir à retapper le nom de chque bouton A chaque lancement (pas tres cool) J'ai trouvé sur un forum Une méthode pour écrire des valeurs dans un fichier texte.Puis Une Autre méthode pour lire le contenu de ce fichier texte.


    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
    «Module permetant de creer un fichier de configuration
    Module RecConfig
     
    'Sous Permetant Dans d'ecrire un fichier
    Public Sub Enregistrer ()
    Dim configname (0 à 11) As String
    configname (1) = Form1.TextBox_Bex.Text
    My.Computer.FileSystem.WriteAllText ( "C: \ testfile.txt", "," & configname (1), True)
    End Sub
     
    'Sous permetant de lire le contenu d'un fichier
    Public Sub Read ()
    Utilisation myReader As New Microsoft.VisualBasic.FileIO.TextFieldParser ( "C: \ testfile.txt")
    MyReader.TextFieldType = FileIO.FieldType.Delimited
    MyReader.SetDelimiters (",")
    CurrentRow As String ()
    While Not MyReader.EndOfData
    Essayer
    currentRow MyReader.ReadFields = ()
    CurrentField As String
    For Each currentField En currentRow
    MsgBox (currentField)
    Suivant
    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
    MsgBox ( "Line" & ex.Message & _
    "Texte non valide, Il est ignoré.")
    End Try
    End While
    End Using
    End Sub
     
    End Module

    Tout cela fonctionne tres bien mais actuellement Comme Vous pouvez le voir la sortie de Mon tableau affiche un MsgBox voiture Je n'ai pas réussi à le diriger vers mon fichier Texte.


    Donc

    Question 1 Comment ecrire mes variables dans un tableau et écrire ce tableau dans mon fichier Texte
    Question 2 Comment relire ce tableau et ecrire ces valeur Dans un autre tableau. car j'en ai besoin pour autre chose ?
    Qiestion 3 Comment faire pour effacer le contenu de mon Fichier Texte Chaque écriture d'avant pour le reinitaliser. pour éviter comme cela se passe en se moment que mon texte s'écrive à la suite ?


    Merci de vos reponses.


    Yves

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2006
    Messages : 16
    Points : 8
    Points
    8
    Par défaut
    Desolé mais l'editeur emplace les If par Si

    Mais vous comprendrez

    Desolé

    @+ Yves

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2006
    Messages : 16
    Points : 8
    Points
    8
    Par défaut
    Bonsoir,
    J'ai trouvé la solution A la une des questions Posée.

    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
    Public Sub Enregistrer () 
    Dim configname (0 à 29) As String 
    configname (1) = Form1.TextBox_Bex.Text 
    configname (2) = Form1.TextBox_BalBlanc1.Text 
    configname (3) = Form1.TextBox_BalBlanc2.Text 
    configname (4) = Form1.TextBox_BalNoir.Text 
    configname (5) = Form1.TextBox_BalMire.Text 
    configname (6) = Form1.TextBox_Sortie1.Text 
    configname (7) = Form1.TextBox_Sortie2.Text 
    configname (8) = Form1.TextBox_Sortie3.Text 
    configname (9) = Form1.TextBox_Sortie4.Text 
    configname (10) = Form1.TextBox_Sortie5.Text 
    configname (11) = Form1.TextBox_Sortie6.Text 
    configname (12) = Form1.TextBox_Sortie7.Text 
    configname (13) = Form1.TextBox_Sortie8.Text 
    configname (14) = Form1.TextBox_EntGr1.Text 
    configname (15) = Form1.TextBox_EntGr2.Text 
    configname (16) = Form1.TextBox_EntGr3.Text 
    configname (17) = Form1.TextBox_EntGr4.Text 
    configname (18) = Form1.TextBox_EntGr5.Text 
    configname (19) = Form1.TextBox_EntGr6.Text 
    configname (20) = Form1.TextBox_EntGr7.Text 
    configname (21) = Form1.TextBox_EntGr8.Text 
    configname (22) = Form1.TextBox_Mem1.Text 
    configname (23) = Form1.TextBox_Mem2.Text 
    configname (24) = Form1.TextBox_Mem3.Text 
    configname (25) = Form1.TextBox_Mem4.Text 
    configname (26) = Form1.TextBox_Mem5.Text 
    configname (27) = Form1.TextBox_Mem6.Text 
    configname (28) = Form1.TextBox_Mem7.Text 
    configname (29) = Form1.TextBox_Mem8.Text 
    Dim i As Integer = 0 
    My.Computer.FileSystem.WriteAllText ( "D: \ Projets_de_Yves \ essais Projets \ AlexTest \ Config.yjp", "", False) 
    For i = 0 To 29 
    My.Computer.FileSystem.WriteAllText ( "D: \ Projets_de_Yves \ essais Projets \ AlexTest \ Config.yjp", configname (i) & ",", True) 
    Suivant 
     
     
    End Sub
    Je mets une fausse La Bolène de fin d'instruction avant ma boucle et j'efface le contenu du fichier.
    Puis je passe cette Bolène Un moment d'écrire au True ma boucle Dans le fichier.


    Tout ne marche pas encore parfaitement mais cela avance ...


    Les autres questions bien sur retent d'actualité.

    @ + Yves

Discussions similaires

  1. [Débutant] ecriture et lecture d'un fichier PHP qui génère du XML
    Par leoAlB dans le forum C#
    Réponses: 7
    Dernier message: 18/06/2014, 16h00
  2. Ecriture et lecture d'un fichier
    Par malus56 dans le forum Débuter
    Réponses: 11
    Dernier message: 07/07/2011, 14h27
  3. Ecriture et lecture dans un fichier
    Par laetous dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 23/08/2006, 17h59

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