Índice De masa Corporal
Formulario Principal
Ahora ingresaremos un peso (KG) y talla (M) será:
Ahora mostraremos el código en visual basic:
Public Class Form1
Dim Imc As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Imc = Val(Peso.Text) / (Val(Altura.Text) * Val(Altura.Text))
Label3.Text = Format(Imc, "##.##")
Label3.Visible = True
Button2.Enabled = True
Select Case Imc
Case Is < 17
Label4.Text = "Delgadez severa."
Label4.Visible = True
Case 17 To 18.49
Label4.Text = "Delgadez aceptable."
Label4.Visible = True
Case 18.5 To 24.99
Label4.Text = "Peso normal."
Label4.Visible = True
Case 25 To 29.99
Label4.Text = "Sobrepeso."
Label4.Visible = True
Case 30 To 34.99
Label4.Text = "Obeso: Tipo I."
Label4.Visible = True
Case 35 To 39.99
Label4.Text = "Obeso: Tipo II."
Label4.Visible = True
Case 40 To 60
Label4.Text = "Obeso: Tipo III."
Label4.Visible = True
End Select
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then
If Val(Peso.Text) < 40 Or Val(Altura.Text) > 200 Then
MsgBox("Valor de PESO erróneo. Será corregido.")
Peso.Text = 60
End If
End If
End Sub
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Peso.LostFocus
TextBox1_KeyPress(Asc(vbCr))
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then
If Val(Altura.Text) < 1.4 Or Val(Altura.Text) > 2.1 Then
MsgBox("Valor de la TALLA errónea. Será corregida.")
Altura.Text = 1.65
End If
End If
End Sub
Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Altura.LostFocus
TextBox2_KeyPress(Asc(vbCr))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Peso.Text = ""
Altura.Text = ""
Label3.Visible = False
Label4.Visible = False
Peso.Focus()
Button2.Enabled = False
End Sub
End Class

índice De masa corporal

  • 1.
    Índice De masaCorporal Formulario Principal Ahora ingresaremos un peso (KG) y talla (M) será:
  • 2.
    Ahora mostraremos elcódigo en visual basic: Public Class Form1 Dim Imc As Double Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Imc = Val(Peso.Text) / (Val(Altura.Text) * Val(Altura.Text)) Label3.Text = Format(Imc, "##.##") Label3.Visible = True Button2.Enabled = True Select Case Imc Case Is < 17 Label4.Text = "Delgadez severa." Label4.Visible = True Case 17 To 18.49 Label4.Text = "Delgadez aceptable." Label4.Visible = True Case 18.5 To 24.99 Label4.Text = "Peso normal." Label4.Visible = True Case 25 To 29.99 Label4.Text = "Sobrepeso." Label4.Visible = True Case 30 To 34.99 Label4.Text = "Obeso: Tipo I." Label4.Visible = True Case 35 To 39.99 Label4.Text = "Obeso: Tipo II." Label4.Visible = True Case 40 To 60 Label4.Text = "Obeso: Tipo III." Label4.Visible = True End Select End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As Integer) If KeyAscii = Asc(vbCr) Then If Val(Peso.Text) < 40 Or Val(Altura.Text) > 200 Then MsgBox("Valor de PESO erróneo. Será corregido.") Peso.Text = 60 End If End If End Sub Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Peso.LostFocus TextBox1_KeyPress(Asc(vbCr)) End Sub
  • 3.
    Private Sub TextBox2_KeyPress(ByValKeyAscii As Integer) If KeyAscii = Asc(vbCr) Then If Val(Altura.Text) < 1.4 Or Val(Altura.Text) > 2.1 Then MsgBox("Valor de la TALLA errónea. Será corregida.") Altura.Text = 1.65 End If End If End Sub Private Sub TextBox2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Altura.LostFocus TextBox2_KeyPress(Asc(vbCr)) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Peso.Text = "" Altura.Text = "" Label3.Visible = False Label4.Visible = False Peso.Focus() Button2.Enabled = False End Sub End Class