【加试题】小张同学设计一个“简单数据筛选”程序。程序启动时运行界面如第17题图所示。程序运行时列表框List1中产生15个随机整数。在文本框Text1中输入筛选条件(大于或小于某个数)后单击“筛选”按钮Command1,右边列表框List2中显示符合筛选条件的数据,同时标签Label2上显示符合条件的数据个数。实现上述功能的VB程序如下,但加框处代码有错误,请改正。
Dim a(1 To 15) As Integer
Dim n As Integer 'n为计数器
Dim key As Integer 'key存放筛选条件的数字部分
Dim f As String 'f存放筛选天健的符号部分:大于号或者小于号
Private Sub FormLoad()
Randomize
For i = 1 To 15
a(i) = Int(Rnd * 100)
List1.AddItem Str(a(i))
Next i
End Sub
Private Sub Command1Click()
Dim c As Integer
Dim st As String
n = 0
c = Len(st)
f = Mid(st, 1, 1)
If f = "<" Then Se2 '调用过程
If f = ">" Then Se1 '调用过程
Label2.Caption = "有" + Str(n) + "个筛选结果"
End Sub
Private Sub Se1() '筛选过程1
For i = 1 To 15
If a(i) > key Then
List2.AddItem Str(a(i))
n = n + 1
End If
Next i
End Sub
Private Sub Se2() '筛选过程2
For i = 1 To 15
List2.AddItem Str(a(i))
n = n + 1
End If
Next i
End Sub