vb 编写一个程序,在2个TextBox中输入某人的身高(cm)和体重(kg),按下式确定其体重是否为标准、过胖或

2024-12-02 09:50:13
推荐回答(3个)
回答1:

Private Sub Command1_Click()’
 '标准体重(kg)=身高(cm)-100  上下可浮动5kg
If Val(Text2.Text) < Val(Text1.Text) - 100 - 5 Then
MsgBox "你的身体太瘦,请注意营养", , "太瘦"
ElseIf Val(Text2.Text) >= Val(Text1.Text) - 100 - 5 And Val(Text2.Text) <= Val(Text1.Text) - 100 + 5 Then
MsgBox "你的身体标准,请继续保持", , "标准"
ElseIf Val(Text2.Text) > Val(Text1.Text) - 100 + 5 Then
MsgBox "你的身体太胖,请注意减肥", , "太胖"
End If
End Sub

回答2:

c = Text1.Text / (Val(Text2.Text) / 100) ^ 2: Print c
If c < 18 Then MsgBox "瘦"
If c >= 18 And c <= 25 Then MsgBox "正常体重"
If c > 25 And c <= 30 Then MsgBox "超重"
If c > 30 And c <= 35 Then MsgBox "轻度肥胖"
If c > 35 And c <= 40 Then MsgBox "中度肥胖"
If c > 40 Then MsgBox "重度肥胖"

感谢2楼的,我把它压缩了一下

回答3:

c = Text2.Text / (Val(Text3.Text)/100) ^ 2
Print c
If c < 18 Then
Text4 = "瘦"
End If
If c >= 18 And c <= 25 Then
Text4 = "正常体重"
End If
If c > 25 And c <= 30 Then
Text4 = "超重"
End If
If c > 30 And c <= 35 Then
Text4 = "轻度肥胖"
End If
If c > 35 And c <= 40 Then
Text4 = "中度肥胖"
End If
If c > 40 Then
Text4 = "重度肥胖"
End If