(4)
编写事件代码
1. 填写基本设置
Private Sub Form_Load()
Me.Caption = \欢迎使用计算体脂肪率软件\ Me.age17.Value = \ Me.height17.Value = \ Me.weight17.Value = \ Me.rate17.Value = \ Me.Option617.Value = False Me.Option17.Value = False End Sub
2.定义男性为true
Private Sub option17_click() Me.Option17.Value = True Me.Option617.Value = False End Sub
3.定义女性为true
Private Sub option617_click()
Me.Option617.Value = True Me.Option17.Value = False End Sub
4.体脂肪率计算编程
Private Sub command1617_click() Dim age17, sex17 As Integer
Dim weight17, hight17, rate17 As Double If Me.Option17.Value Then sex17 = 0
ElseIf Me.Option617.Value Then sex17 = 1 End If
age17 = Me.age17.Value height17 = Me.height17.Value weight17 = Me.weight17.Value
rate17 = 1.2 * weight17 / (height17 ^ 2) + 0.23 * age17 - 10.8 * sex17 - 5.4
Me.rate17.Value = rate17
If sex17 = 1 And rate17 >= 10 And rate17 <= 25 Then MsgBox (\靓仔,您的体型正常,请保持\ ElseIf sex17 = 1 And rate17 < 10 Then
MsgBox (\老弟,请加强营养\ ElseIf sex17 = 1 And rate17 > 25 Then MsgBox (\啊喔,请注意节食\ End If
If sex17 = 0 And rate17 >= 15 And rate17 <= 33 Then MsgBox (\靓女,您的体型正常,请保持\ ElseIf sex17 = 0 And rate17 < 15 Then MsgBox (\老妹,您需要加强营养\ ElseIf sex17 = 0 And rate17 > 33 Then MsgBox (\啊喔,请注意节食\ End If End Sub
5.清空数据
Private Sub Command17_Click() Me.age17 = \ Me.weight17 = \ Me.height17 = \ Me.rate17 = \
Me.Option617.Value = False Me.Option17.Value = False
三、 软件测试
选择性别、输入身高、体重、年龄,软件运行结果如下: