|
-
May 1st, 2009, 11:03 AM
#1
Thread Starter
Junior Member
BMI Program
I'm making a program which calculates a user's BMI (Body Mass Index). I am fairly new to VB.NET so please bare with me.
This is what I have so far...
Code:
Public Class BMI
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'an integer is one or a group of characters has a value ranging from 0 to 255
Dim number1 As Decimal 'user enters height
Dim number2 As Integer 'user enters weight
Dim answer As Decimal 'signals that the answer must be a decimal
'Val returns the numbers contained in a string as a numeric value of appropriate type
number1 = Val(TextBox1.Text) 'number 1 equals TextBox1
number2 = Val(TextBox2.Text) 'number 2 equals TextBox2
answer = number2 / (number1 * 2) 'this shows what the calculation is and both number1 and number2 will be added together
MsgBox(answer) 'a message box will appear with the user's BMI
End Sub
End Class
The concept works absolutely fine, however, I want to extend it a bit.
I'd like to include some sort of validation, so the user is permitted only to use numbers and not letters. So if they did enter a letter or having said that, if they enter anything in the wrong format, an error message will appear.
I'd also like the pop-up box with the user's BMI to say whether they are under, over, or a healthy weight.
Could anybody help me with this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|