Hello,
I finishing a program I started two days ago. In fact it is working fine. But I would like to know if there is another method to do one part.
The think is that there are 49 products that must do calculations using a numericupdown and if a checkbox is tick must to sum more quantity.
To do this I have created 49 variables.
and at the end I have to create the sum function
I need to know if exist another method to avoid having to repeat 49 times the same code, that allow to make the sum into each variable.
As I said it is working. But I am sure should be another method to simplified the code.
Thank you.
I finishing a program I started two days ago. In fact it is working fine. But I would like to know if there is another method to do one part.
The think is that there are 49 products that must do calculations using a numericupdown and if a checkbox is tick must to sum more quantity.
Code:
'NumericUpDown click event
Private Sub UDpan1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UDpan1.Click
Dim cortado As Double
If CKcortado1.Checked = False Then
cortado = 0
ElseIf CKcortado1.Checked = True Then
'if cortado checkbox is enable then value of cortado is 0,05
cortado = PRECIOCORTADO
End If
If CKPan1.Checked = True Then
sumapan1 = 2.5 * UDpan1.Value.ToString + cortado
TotalPan1.Text = sumapan1
ElseIf CKPan1.Checked = False Then
sumapan1 = 0
TotalPan1.Text = sumapan1
End If
End SubCode:
Private resultado As Double
Private sumapan1, sumapan2, sumapan3, sumapan4, sumapan5, sumapan6, sumapan7, sumapan8, sumapan9, sumapan10 As Double
Private sumapan11, sumapan12, sumapan13, sumapan14, sumapan15, sumapan16, sumapan17, sumapan18, sumapan19, sumapan20 As Double
Private sumapan21, sumapan22, sumapan23, sumapan24, sumapan25, sumapan26, sumapan27, sumapan28, sumapan29, sumapan30 As Double
Private sumapan31, sumapan32, sumapan33, sumapan34, sumapan35, sumapan36, sumapan37, sumapan38, sumapan39, sumapan40 As Double
Private sumapan41, sumapan42, sumapan43, sumapan44, sumapan45, sumapan46, sumapan47, sumapan48, sumapan49 As Double
Dim PRECIOCORTADO As Double = 0.05
Dim PRECIOMINIMO As Double = 0.9Code:
Private Sub BTCalcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTCalcular.Click
resultado = sumapan1 + sumapan2 + sumapan3 + sumapan4 + sumapan5 + sumapan6 + sumapan7 + sumapan8 + sumapan9 + sumapan10 _
+ sumapan11 + sumapan12 + sumapan13 + sumapan14 + sumapan15 + sumapan16 + sumapan17 + sumapan18 + sumapan19 + sumapan20 _
+ sumapan21 + sumapan22 + sumapan23 + sumapan24 + sumapan25 + sumapan26 + sumapan27 + sumapan28 + sumapan29 + sumapan30 _
+ sumapan31 + sumapan32 + sumapan33 + sumapan34 + sumapan35 + sumapan36 + sumapan37 + sumapan38 + sumapan39 + sumapan40 _
+ sumapan41 + sumapan42 + sumapan43 + sumapan44 + sumapan45 + sumapan46 + sumapan47 + sumapan48 + sumapan49
If SBTminimo.Value = True Then
If resultado > PRECIOMINIMO Then
resultadomodulo = resultado
Total.Text = resultado
ElseIf resultado <= PRECIOMINIMO Then
resultado = PRECIOMINIMO
resultadomodulo = resultado
Total.Text = resultado
End If
ElseIf SBTminimo.Value = False Then
resultadomodulo = resultado
Total.Text = resultado
End If
End SubAs I said it is working. But I am sure should be another method to simplified the code.
Thank you.