Hey, so basically, I have to do some exercises out of the Visual Basic 2008 book, and they are quiet simple, but I always make my code more complicated than needed. Basically, the program has to turn Mass into Weight by multiplying the users input for Mass by 9.8.
That is my code as of right now.. I need the program to display an error message when the user types in a letter, and if they type in an integer then the input for Mass is multiplied by 9.8 and displayed in the txtWeight. I think I need to use a CInt somewhere in here...
VB.NET:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim Mass As Integer
Dim Weight As Integer
Mass = CInt(txtMass.Text)
If Integer.TryParse(txtMass.Text, Mass) AndAlso Integer.TryParse(txtWeight.Text, Weight) = True Then
txtWeight.Text = txtMass.Text * 9.8
lblMessage.Text = "Successful Sequence!"
Else
MessageBox.Show("You must use a valid number", "Important Message", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
That is my code as of right now.. I need the program to display an error message when the user types in a letter, and if they type in an integer then the input for Mass is multiplied by 9.8 and displayed in the txtWeight. I think I need to use a CInt somewhere in here...