编写VB程序,实现上述功能。运行程序,在列表框List1中显示全部选票,小李收集的选票在前,小王收集的选票在后。单击“分析”按钮Command1,在列表框List2中按作品编号非降序显示全部选票,在文本框Text1中显示最具人气奖的作品编号。程序运行界面如图所示。
'm和n是常量,代码略
Dim a(l To n) As String,c(1 To n) As String
Private Sub Form_ Load( )
'将n张选票的作品编号存入数组a,在List1中显示,代码略
'a(1)~ a(m)、a(m+1)~ a(n)分别为小李和小王收集选票的作品编号
End Sub
Private Sub Command1_ Click()
Dim iAs Integer, j As Integer, k As Integer, t As String
For i=m+ 1To n-1
For j=n- 1 To i Step-1
If a(k) < a(i) Then t= a(j): a(j)= a(k): a(k)=t
Next j
Next i
i= 1
For k=1 To n
If j> n Then
c(k)=a(i)i=i+1
Elself Then
c(k)=a(i)ti=i+ I
Else
c(k)=a():j=j+ 1
End If
List2. Addtem c(k)
Next k
Text1.Text = "无"
For i=
If c(i)=c(i+n \ 2) Then
Text1.Text = c(i): Exit For 'Exit For表示退出循环
End If
Next i
End Sub