根据上述要求编写VB程序,功能如下:读取高一年级n个班级学生学号信息,显示在列表框List1中。程序运行时,单击“抽取”按钮Command1,在列表框List2中显示每班被抽取中的两名学生学号。程序运行界面如图所示。
Constn=8
Dim a(1 To 500) As String
Private Sub Form_Load()
‘读取数据库中学生学号信息并存储于数组a中,过程略。
EndSub
Private Sub Command1_Click( )
Dim s(1 To 8) As String
Dim flag(1 To 500) As Integer
Dim b(1 To n) As Integer
Dim w As Integer, t As Integer, i As Integer, j As Integer
Dim x As String
For i=1 To 45*n
flag(i)=0
Next i
For i=1 To n
b(i)=0
Next i
w=0
For i=1 To n
t=
If flag(t)=1 Then
i=i-1
ElseIf b(i)<2 Then w=w+1
b(i)=b(i)+1
flag(t)=1
If w Mod 2=1 Then i=i-1
End If
Next i
For i=1 To 2*n-1 '排序并输出被抽中学生学号
If Then x=s(i+1): s(i+1)=s(i):s(i)=x
End If
For j=i To i+1
List2.AddItem s(j)
Next j
Next i
End Sub