Public Class Form1
Dim num, sum As Integer 'num用于存放题目序号,sum用于累加扣分值
Sub outresult() '用于输出结果的自定义过程
Select Case sum
Case Is >= 20 '扣分大于等于
MsgBox("扣分:" & sum & " 严重睡眠障碍", MsgBoxStyle.Information, "测试结果")
Case 13 To 19
MsgBox("扣分:" & sum & " 睡眠质量较差", MsgBoxStyle.Information, "测试结果")
Case 5 To 12
MsgBox("扣分:" & sum & " 睡眠质量较好", MsgBoxStyle.Information, "测试结果")
Case Is < 5
MsgBox("扣分:" & sum & " 良好睡眠", MsgBoxStyle.Information, "测试结果")
End Select
num = 0
display()
End Sub
Sub display() '用于显示问量的自定义过程
Select Case num '根据当前题目序号在标签中显示题目内容
Case 0
Label2.Text = "1.睡眠时间很不规律,不能按时上床睡眠。"
Case 1
Label2.Text = "2.工作或娱乐至深夜。"
Case 2
Label2.Text = "3.躺在床上脑子里全是白天出现的人和事。"
Case 3
Label2.Text = "4.入睡后稍有动静就能知道。"
Case 4
Label2.Text = "5.整夜做梦,醒来感觉很累。"
Case 5
Label2.Text = "6.很早就醒,但再也睡不着了。"
Case 6
Label2.Text = "7.有点不顺心的事就彻夜难眠。"
Case 7
Label2.Text = "8.换个地方就很难入睡。"
Case 8
Label2.Text = "9.一倒夜班就睡不好。"
Case 9
Label2.Text = "10.步入中年后开始使用安眠药。"
End Select
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call display()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = False And RadioButton2.Checked = False And RadioButton3.Checked = False And RadioButton4.Checked = False Then
MsgBox("你必须有一个选择", MsgBoxStyle.Information, "提示")
Exit Sub
End If
If num = 9 Then '如果所有个问题(0-9)已显示完毕
outresult() '调用用于显示测试结果的自定义的Sub过程
Else
num = num + 1
display()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged, RadioButton4.CheckedChanged
If RadioButton1.Checked Then sum = sum + 5
If RadioButton2.Checked Then sum = sum + 2
If RadioButton3.Checked Then sum = sum + 1
End Sub
End Class