Bonjour, voici une partie de mon programme:
Dans un premier temps, je veux faire le calcul pour les valeurs ValeurS1, ValeurP1, etc,que je rentre dans un premier DataGridView jusque là il n'y a pas de problème ca fonctionne. Ensuite, je voudrais appliquer la formule avec les valeurs ValeurS2, ValeurP2, etc puis ValeurS3, S4, etc, que je rentre également dans DataGridView1 puis les afficher le résultat dans un DataGridView2 après avoir appuyer sur un bouton. Le problème est que ca ne fonctionne pas car à chaque fois, le programme reprend les valeurs S1, P1.
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 Function CalculCaquot(ByVal i) As Double Dim a2 As Double = Convert.ToDouble(Me.Labela2.Text) Dim b2 As Double = Convert.ToDouble(Me.Labelb2.Text) Dim LabelQmaxi As Double Dim ValeurSi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("Surfacetotale").Value) Dim ValeurLi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("longueur").Value) Dim ValeurCi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("Coefficientimpermeabilisation").Value) Dim ValeurPi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("pente").Value) i = 1 While i < 100 LabelQmaxi = ((((a2 / 60) / 6.6) * (0.28 * (ValeurLi / 100) ^ 0.84 * (ValeurSi / 10000) ^ -0.42) ^ -b2) ^ (1 / (1 - 0.287 * b2))) * (ValeurCi ^ (1 / (1 - 0.287 * b2))) * ((ValeurPi / 100) ^ (0.41 * b2 / (1 - 0.287 * b2))) * ((ValeurSi / 10000) ^ ((0.95 - 0.507 * b2) / (1 - 0.287 * b2))) * 1000 i += 1 End While Return LabelQmaxi
Je voudrais donc savoir comment incrémenter dans ce cas précis, et quand je dis "incrémenteré, ca veut dire reprendre les valeurs de la deuxième ligne, 3ème ligne etc
Pour plus de précisions, voici le programme complet:
Je précise que je construis un logiciel de dimensionnement d'ouvrages hydrauliques en se basant sur la formule de Caquot.
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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 Public Class Form3 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ComboBoxRegion2.Items.Add("Alsace") ComboBoxRegion2.Items.Add("Aquitaine") ComboBoxRegion2.Items.Add("Auvergne") ComboBoxRegion2.Items.Add("Bourgogne") ComboBoxRegion2.Items.Add("Bretagne") ComboBoxRegion2.Items.Add("Champagne") ComboBoxRegion2.Items.Add("Centre") ComboBoxRegion2.Items.Add("Franche-Comté") ComboBoxRegion2.Items.Add("Limousin") ComboBoxRegion2.Items.Add("Languedoc") ComboBoxRegion2.Items.Add("Lorraine") ComboBoxRegion2.Items.Add("Midi-Pyrénées") ComboBoxRegion2.Items.Add("Nord") ComboBoxRegion2.Items.Add("Normandie") ComboBoxRegion2.Items.Add("Pays-de-Loire") ComboBoxRegion2.Items.Add("Picardie") ComboBoxRegion2.Items.Add("Poitou-Charente") ComboBoxRegion2.Items.Add("Provence-Côte d'Azur") ComboBoxRegion2.Items.Add("Région parisienne") ComboBoxRegion2.Items.Add("Rhône-Alpes") End Sub Private Sub ComboBoxRegion2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxRegion2.SelectedIndexChanged ComboBoxVille2.Items.Clear() If ComboBoxRegion2.Text = "Alsace" Then ComboBoxVille2.Items.Add("Mulhouse") ComboBoxVille2.Items.Add("Strasbourg") End If If ComboBoxRegion2.Text = "Aquitaine" Then ComboBoxVille2.Items.Add("Agen") ComboBoxVille2.Items.Add("Biarritz") ComboBoxVille2.Items.Add("Bordeaux") ComboBoxVille2.Items.Add("Cazaux") ComboBoxVille2.Items.Add("Dax") ComboBoxVille2.Items.Add("Mont-de-Marsan") ComboBoxVille2.Items.Add("Pau") End If If ComboBoxRegion2.Text = "Auvergne" Then ComboBoxVille2.Items.Add("Clermont-Ferrand") End If If ComboBoxRegion2.Text = "Bourgogne" Then ComboBoxVille2.Items.Add("Auxerre") ComboBoxVille2.Items.Add("Château-Chinon") ComboBoxVille2.Items.Add("Dijon") ComboBoxVille2.Items.Add("Mont-St-Vincent") End If If ComboBoxRegion2.Text = "Bretagne" Then ComboBoxVille2.Items.Add("Rostrenen") End If If ComboBoxRegion2.Text = "Champagne" Then ComboBoxVille2.Items.Add("Reims") End If If ComboBoxRegion2.Text = "Centre" Then ComboBoxVille2.Items.Add("Chartres") ComboBoxVille2.Items.Add("Orléans") End If If ComboBoxRegion2.Text = "Franche-Comté" Then ComboBoxVille2.Items.Add("Belfort") End If If ComboBoxRegion2.Text = "Limousin" Then ComboBoxVille2.Items.Add("Limoges") End If If ComboBoxRegion2.Text = "Languedoc" Then ComboBoxVille2.Items.Add("Carcassonne") ComboBoxVille2.Items.Add("Montpellier") ComboBoxVille2.Items.Add("Nîmes") ComboBoxVille2.Items.Add("Perpignan") End If If ComboBoxRegion2.Text = "Lorraine" Then ComboBoxVille2.Items.Add("Metz") End If If ComboBoxRegion2.Text = "Midi-Pyrénées" Then ComboBoxVille2.Items.Add("Gourdon") ComboBoxVille2.Items.Add("Millau") ComboBoxVille2.Items.Add("Ossun") ComboBoxVille2.Items.Add("Toulouse") End If If ComboBoxRegion2.Text = "Nord" Then ComboBoxVille2.Items.Add("Lille") End If If ComboBoxRegion2.Text = "Normandie" Then ComboBoxVille2.Items.Add("Alençon") ComboBoxVille2.Items.Add("Caen") ComboBoxVille2.Items.Add("Rouen") End If If ComboBoxRegion2.Text = "Pays-de-Loire" Then ComboBoxVille2.Items.Add("Angers") ComboBoxVille2.Items.Add("Le Mans") ComboBoxVille2.Items.Add("Nantes") End If If ComboBoxRegion2.Text = "Picardie" Then ComboBoxVille2.Items.Add("Abbeville") ComboBoxVille2.Items.Add("St-Quentin") End If If ComboBoxRegion2.Text = "Poitou-Charente" Then ComboBoxVille2.Items.Add("Angoulême") ComboBoxVille2.Items.Add("Cognac") ComboBoxVille2.Items.Add("Poitiers") End If If ComboBoxRegion2.Text = "Provence-Côte d'Azur" Then ComboBoxVille2.Items.Add("Ajaccio") ComboBoxVille2.Items.Add("Bastia") ComboBoxVille2.Items.Add("Marignane") ComboBoxVille2.Items.Add("Nice") ComboBoxVille2.Items.Add("Salon") End If If ComboBoxRegion2.Text = "Région parisienne" Then ComboBoxVille2.Items.Add("Brétigny") ComboBoxVille2.Items.Add("Paris-Montsouris") End If If ComboBoxRegion2.Text = "Rhône-Alpes" Then ComboBoxVille2.Items.Add("Challes-les-Eaux") ComboBoxVille2.Items.Add("Grenoble") ComboBoxVille2.Items.Add("Lyon") ComboBoxVille2.Items.Add("Montélimar") End If End Sub Private Sub ComboBoxVille2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxVille2.SelectedIndexChanged If ComboBoxVille2.Text = "Mulhouse" Then Labela2.Text = 310 Labelb2.Text = 0.689 End If If ComboBoxVille2.Text = "Strasbourg" Then Labela2.Text = 255 Labelb2.Text = 0.481 End If If ComboBoxVille2.Text = "Agen" Then Labela2.Text = 285 Labelb2.Text = 0.411 End If If ComboBoxVille2.Text = "Biarritz" Then Labela2.Text = 241 Labelb2.Text = 0.34 End If If ComboBoxVille2.Text = "Bordeaux" Then Labela2.Text = 392 Labelb2.Text = 0.51 End If If ComboBoxVille2.Text = "Cazaux" Then Labela2.Text = 379 Labelb2.Text = 0.635 End If If ComboBoxVille2.Text = "Dax" Then Labela2.Text = 273 Labelb2.Text = 0.53 End If If ComboBoxVille2.Text = "Mont-de-Marsan" Then Labela2.Text = 301 Labelb2.Text = 0.411 End If If ComboBoxVille2.Text = "Pau" Then Labela2.Text = 297 Labelb2.Text = 0.511 End If If ComboBoxVille2.Text = "Clermont-Ferrand" Then Labela2.Text = 246 Labelb2.Text = 0.451 End If If ComboBoxVille2.Text = "Auxerre" Then Labela2.Text = 205 Labelb2.Text = 0.421 End If If ComboBoxVille2.Text = "Château-Chinon" Then Labela2.Text = 591 Labelb2.Text = 0.719 End If If ComboBoxVille2.Text = "Dijon" Then Labela2.Text = 234 Labelb2.Text = 0.431 End If If ComboBoxVille2.Text = "Mont-St-Vincent" Then Labela2.Text = 175 Labelb2.Text = 0.361 End If If ComboBoxVille2.Text = "Rostrenen" Then Labela2.Text = 186 Labelb2.Text = 0.506 End If If ComboBoxVille2.Text = "Reims" Then Labela2.Text = 282 Labelb2.Text = 0.527 End If If ComboBoxVille2.Text = "Chartres" Then Labela2.Text = 211 Labelb2.Text = 0.496 End If If ComboBoxVille2.Text = "Orléans" Then Labela2.Text = 226 Labelb2.Text = 0.475 End If If ComboBoxVille2.Text = "Belfort" Then Labela2.Text = 161 Labelb2.Text = 0.355 End If If ComboBoxVille2.Text = "Limoges" Then Labela2.Text = 196 Labelb2.Text = 0.44 End If If ComboBoxVille2.Text = "Carcassonne" Then Labela2.Text = 259 Labelb2.Text = 0.364 End If If ComboBoxVille2.Text = "Montpellier" Then Labela2.Text = 310 Labelb2.Text = 0.362 End If If ComboBoxVille2.Text = "Nîmes" Then Labela2.Text = 199 Labelb2.Text = 0.198 End If If ComboBoxVille2.Text = "Perpignan" Then Labela2.Text = 234 Labelb2.Text = 0.356 End If If ComboBoxVille2.Text = "Metz" Then Labela2.Text = 327 Labelb2.Text = 0.617 End If If ComboBoxVille2.Text = "Gourdon" Then Labela2.Text = 216 Labelb2.Text = 0.418 End If If ComboBoxVille2.Text = "Millau" Then Labela2.Text = 302 Labelb2.Text = 0.514 End If If ComboBoxVille2.Text = "Ossun" Then Labela2.Text = 364 Labelb2.Text = 0.55 End If If ComboBoxVille2.Text = "Toulouse" Then Labela2.Text = 327 Labelb2.Text = 0.494 End If If ComboBoxVille2.Text = "Lille" Then Labela2.Text = 323 Labelb2.Text = 0.499 End If If ComboBoxVille2.Text = "Alençon" Then Labela2.Text = 359 Labelb2.Text = 0.699 End If If ComboBoxVille2.Text = "Caen" Then Labela2.Text = 320 Labelb2.Text = 0.542 End If If ComboBoxVille2.Text = "Rouen" Then Labela2.Text = 241 Labelb2.Text = 0.426 End If If ComboBoxVille2.Text = "Angers" Then Labela2.Text = 293 Labelb2.Text = 0.52 End If If ComboBoxVille2.Text = "Le Mans" Then Labela2.Text = 210 Labelb2.Text = 0.441 End If If ComboBoxVille2.Text = "Nantes" Then Labela2.Text = 129 Labelb2.Text = 0.352 End If If ComboBoxVille2.Text = "Abbeville" Then Labela2.Text = 252 Labelb2.Text = 0.469 End If If ComboBoxVille2.Text = "St-Quentin" Then Labela2.Text = 246 Labelb2.Text = 0.492 End If If ComboBoxVille2.Text = "Angoulême" Then Labela2.Text = 297 Labelb2.Text = 0.511 End If If ComboBoxVille2.Text = "Cognac" Then Labela2.Text = 242 Labelb2.Text = 0.431 End If If ComboBoxVille2.Text = "Poitiers" Then Labela2.Text = 272 Labelb2.Text = 0.437 End If If ComboBoxVille2.Text = "Ajaccio" Then Labela2.Text = 299 Labelb2.Text = 0.376 End If If ComboBoxVille2.Text = "Bastia" Then Labela2.Text = 291 Labelb2.Text = 0.308 End If If ComboBoxVille2.Text = "Marignane" Then Labela2.Text = 159 Labelb2.Text = 0.257 End If If ComboBoxVille2.Text = "Nice" Then Labela2.Text = 216 Labelb2.Text = 0.24 End If If ComboBoxVille2.Text = "Salon" Then Labela2.Text = 302 Labelb2.Text = 0.349 End If If ComboBoxVille2.Text = "Brétigny" Then Labela2.Text = 226 Labelb2.Text = 0.499 End If If ComboBoxVille2.Text = "Paris-Montsouris" Then Labela2.Text = 362 Labelb2.Text = 0.491 End If If ComboBoxVille2.Text = "Challes-les-Eaux" Then Labela2.Text = 285 Labelb2.Text = 0.469 End If If ComboBoxVille2.Text = "Grenoble" Then Labela2.Text = 273 Labelb2.Text = 0.397 End If If ComboBoxVille2.Text = "Lyon" Then Labela2.Text = 311 Labelb2.Text = 0.436 End If If ComboBoxVille2.Text = "Montélimar" Then Labela2.Text = 249 Labelb2.Text = 0.379 End If End Sub Private Sub ButtonCalcul2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalcul2.Click If Verification() Then Me.DataGridView2.Rows(0).Cells("debits").Value = CalculCaquot(1).ToString("0.0#") Me.DataGridView2.Rows(1).Cells("debits").Value = CalculCaquot(2).ToString("0.0#") Else Me.erreur2.Visible = True End If End Sub Function Verification() As Boolean Dim Bon As Boolean = True If Me.Labela2.Text Is Nothing Or Not IsNumeric(Me.Labela2.Text) Then MessageBox.Show("Entrez une valeur numérique pour a") Bon = False Else Select Case CType(Me.Labela2.Text, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour a") Bon = False End Select End If If Me.Labelb2.Text Is Nothing Or Not IsNumeric(Me.Labelb2.Text) Then MessageBox.Show("Entrez une valeur numérique pour b") Bon = False Else Select Case CType(Me.Labelb2.Text, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour b") Bon = False Case Is > 1 MessageBox.Show("Entrez une valeur entre 0 et 1 pour b") Bon = False End Select End If If Me.DataGridView1.Rows(0).Cells("Surfacetotale").Value Is Nothing Or Not IsNumeric(Me.DataGridView1.Rows(0).Cells("Surfacetotale").Value) Then MessageBox.Show("Entrez une valeur numérique pour S") Bon = False Else Select Case CType(Me.DataGridView1.Rows(0).Cells("Surfacetotale").Value, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour S") Bon = False End Select End If If Me.DataGridView1.Rows(0).Cells("longueur").Value Is Nothing Or Not IsNumeric(Me.DataGridView1.Rows(0).Cells("longueur").Value) Then MessageBox.Show("Entrez une valeur numérique pour L") Bon = False Else Select Case CType(Me.DataGridView1.Rows(0).Cells("longueur").Value, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour L") Bon = False End Select End If If Me.DataGridView1.Rows(0).Cells("Coefficientimpermeabilisation").Value Is Nothing Or Not IsNumeric(Me.DataGridView1.Rows(0).Cells("Coefficientimpermeabilisation").Value) Then MessageBox.Show("Entrez une valeur numérique pour C") Bon = False Else Select Case CType(Me.DataGridView1.Rows(0).Cells("Coefficientimpermeabilisation").Value, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour C") Bon = False End Select End If If Me.DataGridView1.Rows(0).Cells("pente").Value Is Nothing Or Not IsNumeric(Me.DataGridView1.Rows(0).Cells("pente").Value) Then MessageBox.Show("Entrez une valeur numérique pour p") Bon = False Else Select Case CType(Me.DataGridView1.Rows(0).Cells("pente").Value, Double) Case Is < 0 MessageBox.Show("Entrez une valeur positive pour p") Bon = False End Select End If Return Bon End Function Function CalculCaquot(ByVal i) As Double Dim a2 As Double = Convert.ToDouble(Me.Labela2.Text) Dim b2 As Double = Convert.ToDouble(Me.Labelb2.Text) Dim LabelQmaxi As Double Dim ValeurSi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("Surfacetotale").Value) Dim ValeurLi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("longueur").Value) Dim ValeurCi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("Coefficientimpermeabilisation").Value) Dim ValeurPi As Double = Convert.ToDouble(Me.DataGridView1.Rows(i - 1).Cells("pente").Value) i = 1 While i < 100 LabelQmaxi = ((((a2 / 60) / 6.6) * (0.28 * (ValeurLi / 100) ^ 0.84 * (ValeurSi / 10000) ^ -0.42) ^ -b2) ^ (1 / (1 - 0.287 * b2))) * (ValeurCi ^ (1 / (1 - 0.287 * b2))) * ((ValeurPi / 100) ^ (0.41 * b2 / (1 - 0.287 * b2))) * ((ValeurSi / 10000) ^ ((0.95 - 0.507 * b2) / (1 - 0.287 * b2))) * 1000 i += 1 End While Return LabelQmaxi End Function End Class
Partager