华北科技学院计算机系综合性实验.doc
华北科技学院安全工程学院综合性
实 验 报 告
课程名称 程序设计语言(VB)
实验学期 2011 至 2012 学年 第 2 学期
学生所在系部 安全工程学院
年级 大一 专业班级 安全B116班
学生姓名 胡海波 学号 201110044604
任课教师 狐为民
实验成绩
1先进入欢迎界面,在屏幕上显示"欢迎您使用",并弹出密码框,等待输入密码。(5%)(密码为123456)
程序代码如下
Private Sub Command1_Click()
If Text1.Text <> "123456" Then
Text1.SetFocus
Text1.Text = ""
Else
Unload Me
Form2.Show
End If
End Sub
Private Sub Text1_Change()
Text1.PasswordChar = "*"
End Sub
2密码正确后进入系统主界面,主界面包括“数组应用”、“过程应用”、“控件应用”和“退出”等菜单,并提供相关工具栏或命令按钮。
(1)“数组应用”菜单中包括“数组操作”子菜单,单击此菜单,弹出“数组操作”对话框,如图1所示。(35%,每个按钮功能为5%)。
程序界面及代码如下
Dim a(1 To 10) As Long
Private Sub Command1_Click()
For i = 1 To 10
For j = i + 1 To 10
If a(j) < a(i) Then
t = a(j): a(j) = a(i): a(i) = t
End If
Next j
Next i
Text1.Text = ""
For i = 1 To 10
Text1.Text = Text1.Text + Str(a(i))
Next i
End Sub
Private Sub Command2_Click()
For i = 1 To 10
For j = i + 1 To 10
If a(j) > a(i) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
Text2.Text = ""
For i = 1 To 10
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
Private Sub Command3_Click()
Max = a(1)
For i = 2 To 10
If Max < a(i) Then Max = a(i)
Next i
Text3.Text = Max
End Sub
Private Sub Command4_Click()
Min = a(1)
For i = 2 To 10
If a(i) < Min Then Min = a(i)
Next i
Text4.Text = Min
End Sub
Private Sub Command5_Click()
Dim i As Long
For i = 1 To 10
a(i) = Rnd * 100
a(i) = InputBox("请输入第" & i & "个数")
If Not IsNumeric(a(i)) Then
MsgBox "输入必须为数字", , "警告"
End If
Next i
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
Command6.Enabled = True
Command1.Enabled = True
For i