用户窗体设计如下:
VBA代码如下:
'定义通用变量:体表面积-BSA
Dim BSA As Double
Private Sub CaculateBSAButton_Click() '单击“计算”按钮实现的功能
' 定义变量
Dim Weight As Double
Dim Height As Double
Dim Drug1 As Double
Dim Drug2 As Double
Dim Drug3 As Double
Dim Drug4 As Double
Dim Dose1 As Double
Dim Dose2 As Double
Dim Dose3 As Double
Dim Dose4 As Double
'获取单位表面积剂量
'Drug1为表柔比星,Drug2为环磷酰胺,Drug3为奈达铂,Drug4为多西他赛
'通过一些简单的条件判断来对输入的参数进行一些限制,如必须输入身高体重等。
If WeightBox.Value = "" Or HeightBox.Value = "" Then
MsgBox "身高或体重不能为空,请重新填写", vbOKOnly
ResultBox.Value = ""
Exit Sub
ElseIf DrugBox1.Value = "" Or DrugBox2.Value = "" Or DrugBox3.Value = "" Or DrugBox4.Value = "" Then
answer = MsgBox("剂量参数不能为空,不需要的剂量参数请设为0!", vbOKOnly)
ResultBox.Value = ""
Exit Sub
ElseIf DrugBox1.Value > 120 Or DrugBox2.Value > 1600 Or DrugBox3.Value > 100 Or DrugBox4.Value > 75 Then
answer = MsgBox("有药物超过最大剂量,请检查后重新填写药物参数", vbOKOnly)
ResultBox.Value = ""
Exit Sub
Else
Drug1 = CDbl(DrugBox1.Value)
Drug2 = CDbl(DrugBox2.Value)
Drug3 = CDbl(DrugBox3.Value)
Drug4 = CDbl(DrugBox4.Value)
End If
'获取用户输入的体重和身高
Weight = CDbl(WeightBox.Value)
Height = CDbl(HeightBox.Value)
'计算体表面积
BSA = 0.0061 * Height + 0.0128 * Weight - 0.1529
'计算药物剂量
Dose1 = Drug1 * BSA
Dose2 = Drug2 * BSA
Dose3 = Drug3 * BSA
Dose4 = Drug4 * BSA
'输出计算结果
ResultBox.Value = "体表面积为:" & BSA & "平方米" _
& vbCrLf & "所用药物剂量为:" _
& vbCrLf & Chr(9) & "表柔比星:" & Dose1 & "mg" _
& vbCrLf & Chr(9) & "环磷酰胺:" & Dose2 & "mg" _
& vbCrLf & Chr(9) & "奈达铂:" & Dose3 & "mg" _
& vbCrLf & Chr(9) & "多西他赛:" & Dose4 & "mg"
End Sub
Private Sub ClearButton_Click()
'清空所有文本框中的值
WeightBox.Value = ""
HeightBox.Value = ""
DrugBox1.Value = ""
DrugBox2.Value = ""
DrugBox3.Value = ""
DrugBox4.Value = ""
ResultBox.Value = ""
End Sub
Private Sub QuitButton_Click()
ActiveWorkbook.Save
Application.Quit
End Sub
- 给`ThisWorkbook’对象加上如下代码,可以在Excel打开的时候自动弹出用户窗体:
Private Sub Workbook_Open()
计算化疗药物剂量.Show
End Sub
- 也可以在表单上设计控件,将之与启动用户窗体的宏关联。
转载请注明来源:化疗药物剂量计算器_VBA
本文链接地址:https://omssurgeon.com/2141/