This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modification.frm
360 lines (332 loc) · 11.3 KB
/
Modification.frm
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Modification
Caption = "Modification des fichiers"
ClientHeight = 9600.001
ClientLeft = 108
ClientTop = 456
ClientWidth = 5892
OleObjectBlob = "Modification.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "Modification"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim numEtudiant, num, nom, prenom, natio As String
Dim TP, DS As String
Dim CP, Adresse As String
Dim etudiantExist As Boolean
Dim Result() As String
Dim Tablo(10000) As String
Private Sub CheckBox1_Click()
'Si la case 1 est cochee, on coche les 2 autres
If (CheckBox1.Value = True) Then
If (CheckBox2.Enabled = True) Then
CheckBox2.Value = True
End If
If (CheckBox3.Enabled = True) Then
CheckBox3.Value = True
End If
End If
End Sub
Private Sub CommandButton1_Click()
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
numEtudiant = TextBox1.Value
etudiantExist = False
AlreadyAdd = False
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Etatcivil.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigneEC
Result = Split(ContenuLigneEC, ",")
If (Result(0) = numEtudiant) Then
'Si le numero etudiant existe, on debloque les champs de l'etat civil et la case a cocher pour la suppression
etudiantExist = True
num = Result(0)
TextBox2.Value = num
nom = Result(1)
TextBox9.Enabled = True
TextBox9.Value = nom
prenom = Result(2)
TextBox3.Enabled = True
TextBox3.Value = prenom
natio = Result(3)
TextBox4.Enabled = True
TextBox4.Value = natio
CheckBox1.Enabled = True
End If
Wend
Close #1
If (etudiantExist = True) Then
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Notes.txt" For Input As #2
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Adresses.txt" For Input As #3
While Not EOF(2)
Line Input #2, ContenuLigneN
Result = Split(ContenuLigneN, ",")
If (Result(0) = numEtudiant) Then
'Si des notes existent, on debloque les champs et la case
TP = Result(1)
TextBox6.Enabled = True
TextBox6.Value = TP
DS = Result(2)
TextBox5.Enabled = True
TextBox5.Value = DS
AlreadyAdd = True
CheckBox2.Enabled = True
Else
If (AlreadyAdd = False) Then
TextBox6.Enabled = False
TextBox6.Value = ""
TextBox5.Enabled = False
TextBox5.Value = ""
End If
End If
Wend
Close #2
AlreadyAdd = False
While Not EOF(3)
Line Input #3, ContenuLigneA
Result = Split(ContenuLigneA, ",")
If (Result(0) = numEtudiant) Then
'On debloque les champs d'adresse
CP = Result(1)
TextBox8.Enabled = True
TextBox8.Value = CP
Adresse = Result(2)
TextBox7.Enabled = True
TextBox7.Value = Adresse
AlreadyAdd = True
CheckBox3.Enabled = True
Else
If (AlreadyAdd = False) Then
TextBox8.Enabled = False
TextBox8.Value = ""
TextBox7.Enabled = False
TextBox7.Value = ""
End If
End If
Wend
Close #3
Else
'Si l'etudiant n'existe pas, on bloque tout et on remet les champs nuls
MsgBox "Cet étudiant n'existe pas"
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox6.Enabled = False
TextBox7.Enabled = False
TextBox8.Enabled = False
TextBox9.Enabled = False
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
CheckBox1.Enabled = False
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
End If
End Sub
Private Sub CommandButton2_Click()
'Valeurs des champs
numEtudiant = TextBox1.Value
num = TextBox2.Value
nom = TextBox9.Value
prenom = TextBox3.Value
natio = TextBox4.Value
'Si les notes ne sont pas numeriques, erreur
If (IsNumeric(TextBox6.Value)) Then
TP = TextBox6.Value
Else
MsgBox "La note de TP est invalide"
End If
If (IsNumeric(TextBox5.Value)) Then
DS = TextBox5.Value
Else
MsgBox "La note de DS est invalide"
End If
CP = TextBox8.Value
Adresse = TextBox7.Value
'Recup etatcivil.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Etatcivil.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On change les valeurs de Result en fonction des valeurs des champs
Result(1) = nom
Result(2) = prenom
Result(3) = natio
End If
'On ajoute a Tablo la ligne formatee, prete a etre print dans le fichier
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2) & "," & Result(3)
i = i + 1
Wend
Close #1
'On ouvre de nouveau Etatcivil, il sera vierge
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Etatcivil.txt" For Output As #1
j = 0
While j < i
'On ajoute toutes les lignes de Tablo
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
'Recup notes.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Notes.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On change les valeurs de Result en fonction des valeurs des champs
Result(1) = TP
Result(2) = DS
End If
'On ajoute a Tablo la ligne formatee, prete a etre print dans le fichier
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2)
i = i + 1
Wend
Close #1
'On ouvre de nouveau Notes, il sera vierge
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Notes.txt" For Output As #1
j = 0
While j < i
'On ajoute toutes les lignes de Tablo
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
'Recup adresses.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Adresses.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On change les valeurs de Result en fonction des valeurs des champs
Result(1) = CP
Result(2) = Adresse
End If
'On ajoute a Tablo la ligne formatee, prete a etre print dans le fichier
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2)
i = i + 1
Wend
Close #1
'On ouvre de nouveau Adresses, il sera vierge
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Adresses.txt" For Output As #1
j = 0
While j < i
'On ajoute toutes les lignes de Tablo
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
MsgBox "Etudiant modifié"
End Sub
Private Sub CommandButton3_Click()
'Si aucune case n'est cochee, rien a faire
If (CheckBox1.Value = False And CheckBox2.Value = False And CheckBox3.Value = False) Then
MsgBox "Aucune case n'est cochée"
End If
'On supprime l'etat civil
If (CheckBox1.Value = True) Then
'Recup etatcivil.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Etatcivil.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On n'ajoute pas cette ligne dans Tablo, afin de le supprimer
MsgBox "Etat civil supprimé"
TextBox1.Value = ""
TextBox2.Value = ""
TextBox9.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
Else
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2) & "," & Result(3)
i = i + 1
End If
Wend
Close #1
'On ecrase Etatcivil
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Etatcivil.txt" For Output As #1
j = 0
While j < i
'On ajoute toutes les lignes de Tablo
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
End If
'On supprime les notes
If (CheckBox2.Value = True) Then
'Recup notes.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Notes.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On n'ajoute pas cette ligne dans Tablo, afin de le supprimer
MsgBox "Notes supprimées"
TextBox6.Value = ""
TextBox5.Value = ""
Else
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2)
i = i + 1
End If
Wend
Close #1
'On ecrase Notes
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Notes.txt" For Output As #1
j = 0
While j < i
'On ajoute les lignes de Tablo dans le fichier
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
End If
'On supprime l'adresse
If (CheckBox3.Value = True) Then
'Recup adresses.txt
i = 0
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Adresses.txt" For Input As #1
While Not EOF(1)
Line Input #1, ContenuLigne
Result = Split(ContenuLigne, ",")
If Result(0) = numEtudiant Then
'On n'ajoute pas cette ligne dans Tablo, afin de le supprimer
MsgBox "Adresse supprimée"
TextBox8.Value = ""
TextBox7.Value = ""
Else
Tablo(i) = Result(0) & "," & Result(1) & "," & Result(2)
i = i + 1
End If
Wend
Close #1
'On ecrase Adresses
Open "C:\Users\Aymeric\Documents\GitHub\TP_VBA" & "\Adresses.txt" For Output As #1
j = 0
While j < i
'On ajoute les lignes de Tablo dans Adresses
Print #1, Tablo(j)
j = j + 1
Wend
Close #1
End If
End Sub