Dim altezza As Integer
Dim peso As Integer
Dim b As Single
Sub init()
Txtpeso.Text = ""
Txtalt.Text = ""
Txtpeso.SetFocus
Label3.Visible = False
altezza = 0
peso = 0
b = 0
End Sub
Public Function calcola(p As Integer, a As Integer) As Single
Dim pes As Integer, alt As Single, al As Single
pes = Int(Txtpeso.Text)
al = a / 100
alt = al ^ 2
calcola = p / alt
End Function
Private Sub Cmdbmi_Click()
If Txtpeso.Text <> "" And Txtalt.Text <> "" Then
peso = Int(Txtpeso.Text)
altezza = Int(Txtalt.Text)
If altezza > 250 Then
MsgBox "Dai che non sei cosi alto!!!", vbInformation, "Info"
Call init
Exit Sub
End If
If peso > 400 Then
MsgBox "Pesi troppo", vbInformation, "Info"
Call init
Exit Sub
End If
b = calcola(peso, altezza)
Label3.Visible = True
If b < 18.5 Then
Label3.Caption = "Sei sottopeso"
End If
If b >= 18.5 And b <= 25 Then
Label3.Caption = "Sei normopeso"
End If
If b > 25 And b <= 30 Then
Label3.Caption = "Sei in sovrappeso"
End If
If b > 30 And b <= 40 Then
Label3.Caption = "Sei obeso"
End If
If b > 45 Then
Label3.Caption = "Sei obeso grave"
End If
End If
End Sub
Private Sub Cmdres_Click()
Call init
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim ris As Integer
ris = MsgBox("Sei sicuro di uscire?", vbQuestion + vbYesNoCancel, "Esci")
If ris = vbYes Then
MsgBox "Programma creato da Albertking82!", vbInformation, "Albertking82"
End
Else
Cancel = True
End If
End Sub
Private Sub Txtalt_Change()
If Txtalt.Text <> "" Then
If Not IsNumeric(Txtalt.Text) Then
Txtalt.Text = ""
End If
End If
End Sub
Private Sub Txtalt_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 188 Or KeyCode = 190 Then
Txtalt.Text = ""
End If
End Sub
Private Sub Txtpeso_Change()
If Txtpeso.Text <> "" Then
If Not IsNumeric(Txtpeso.Text) Then
Txtpeso.Text = ""
End If
End If
End Sub
Private Sub Txtpeso_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 188 Or KeyCode = 190 Then
Txtpeso.Text = ""
End If
End Sub