RoccoSiffredi
Technical User
I've created vba to calculate the area of a parcel.
There are two valdiation checks :
If the parcels weight is less than or equal to 25
If the parcels height is less than or equal to 100
Then the formula to calculate the area is run otherwise error messages are displayed in message boxes.
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim hcm As Integer
Dim weight As Integer
Dim length As Integer
Dim Cubic As Integer
If txtweight.Text <= 25 Then
hcm = CInt(txthcm.Text)
weight = CInt(txtweight.Text)
length = CInt(txtlength.Text)
Cubic = weight * hcm * length
mcubed.Text = "The Parcel in square metres is " & Cubic.ToString
Else
MessageBox.Show("Please enter a value between 0 and 20kg")
End If
If txthcm.Text <= 100 Then
hcm = CInt(txthcm.Text)
weight = CInt(txtweight.Text)
length = CInt(txtlength.Text)
Cubic = weight * hcm * length
Else
MessageBox.Show("Please enter a value between 1 cm and 100 cm")
End If
End Sub
If there a way to nest these two if then else statements together so that if either condition is not met the error messages are displayed?
Also how to I display the results of the calculation correct to 2 decimal places, this is for my general interest and doesn't relate to this problem.
There are two valdiation checks :
If the parcels weight is less than or equal to 25
If the parcels height is less than or equal to 100
Then the formula to calculate the area is run otherwise error messages are displayed in message boxes.
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim hcm As Integer
Dim weight As Integer
Dim length As Integer
Dim Cubic As Integer
If txtweight.Text <= 25 Then
hcm = CInt(txthcm.Text)
weight = CInt(txtweight.Text)
length = CInt(txtlength.Text)
Cubic = weight * hcm * length
mcubed.Text = "The Parcel in square metres is " & Cubic.ToString
Else
MessageBox.Show("Please enter a value between 0 and 20kg")
End If
If txthcm.Text <= 100 Then
hcm = CInt(txthcm.Text)
weight = CInt(txtweight.Text)
length = CInt(txtlength.Text)
Cubic = weight * hcm * length
Else
MessageBox.Show("Please enter a value between 1 cm and 100 cm")
End If
End Sub
If there a way to nest these two if then else statements together so that if either condition is not met the error messages are displayed?
Also how to I display the results of the calculation correct to 2 decimal places, this is for my general interest and doesn't relate to this problem.