實現(xiàn)上述功能的VB程序如下: Dim xm(1 To 500)As String,xh(1 To 500)As String,xb(1 To 500)As String Dim n As Integer'學生總人數(shù) Dim a(1 To 100)As Integer'抽中序號 Private Sub Form_Load ( ?。?br />'本過程讀取n位同學的序號、姓名和性別, '分別存儲在數(shù)組xh、xm、xb中 '并在List1中顯示,代碼略 End Sub Private Sub Command1_Click ( ?。?br />Dim rs As Integer,m As Integer,x As Integer,girl As Integer,i As Integer Dim xbs(1 To 500)As Integer Randomize List2.Clear List2.AddItem“姓名“&““&“性別“ rs=
Val(Text1.Text)
Val(Text1.Text)
For i=1 To n If xb(i)=“女“Then xbs(i)=1 Else xbs(i)=0 Next i m=0 girl=0 If rs=1 Then x=Int(Rnd*n)+1 List2.AddItem xm(x) &““& xb(x) Else Do While m<rs x=Int(Rnd*n)+1 If checkf(x) Then m=m+1:a(m)=x girl=girl+xbs(a(m)) If
m-girl>rs\2
m-girl>rs\2
Then a(m)=0:m=m-1 ElseIf girl>(rs+1)\2 Then a(m)=0:m=m-1
girl=girl-1
girl=girl-1
End If End If Loop For i=1 To m List2.AddItem Next i End If End Sub Function checkf(p As Integer) As Boolean '核對重復中獎,未中過獎返回True '代碼略 End Function (1)請在橫線處填入合適的代碼。 (2)程序中加框代碼有錯,請改正。