: 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