16.小明想用VB編程制作一個名次計算器,首先將同學的成績錄入到計算機中,同時存放在數組a中,顯示在左邊列表框中.點擊“排序”按鈕后,程序會將成績從高到低依次排序顯示在右邊的列表框中.運行界面如圖所示,請在兩個橫線處填入代碼. Dim a(1To 100)As Single Dim shu As Integer Private Sub Command1_Click Dim i,j,k As Integer Dim t As Single For i=1To shu-1 k=i For j=i+1 To shu If ①
Then t=a(j):a(j)=a(k):a(k)=t End If Next j Next i For i=1 To shu List2.AddItem“第“& Str(i) &“名:“& Str(a(i)) Next i End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Dim cj As Single If KeyAscii=13Then cj=Val(Text1.Text) If cj>0Then ②
List1.AddItem Str(shu) &“:“& Str(cj) a(shu)=cj End If Text1.Text=““ End If End Sub.
17.小王模擬超市收銀機掃描商品條形碼后計算總價的過程制作了一個VB程序.功能如下:在文本框Text1中輸入商品條形碼,按回車鍵后會將已經輸入的條形碼顯示在列表框List1中,同時將商品明細顯示在列表框List2中.點擊按鈕“計算商品總價”后,會將所有商品的總價顯示在文本框Text2中.程序界面如圖所示: 實現上述功能的部分VB程序如下,請在三個橫線處填入合適代碼. '定義全局數組變量 Dim a(1To 10)As Long Dim b(1To 10)As String '自動加載條形碼信息以及對應的商品信息 Private Sub Form_Load Dim i As Integer a(1)=503741 For i=2To 10 a(i)=a(i-1)+1 Next i b(1)=“可樂 5.00“ b(2)=“薯片 7.50“ b(3)=“牛奶 5.60“ b(4)=“橙汁 7.50“ b(5)=“面包 4.00“ b(6)=“蜂蜜 28.00“ b(7)=“蛋糕 12.00“ b(8)=“綠箭 3.50“ b(9)=“餅干 6.00“ b(10)=“雪碧 5.00“ End Sub '輸入條形碼,查找條形碼,并顯示條形碼及其對應的商品信息 Private Sub Text1_KeyPress(KeyAscii As Integer) Dim txm As Long: Dim i As Integer: Dim j As Integer txm=Val(Text1.Text) If KeyAscii=13Then If txm>=503741And txm<=503750Then List1.AddItem txm Text1.Text=““ i=1:j=10 Do While i<=j ①
If txm=a(m) Then List2.AddItem b(m) Exit Do ElseIf txm>a(m) Then i=m+1 Else ②
End If Loop Else MsgBox“條形碼輸入錯誤,無此商品“ Text1.Text=““ End If End If End Sub '計算所購商品的總額 Private Sub Command1_Click Dim i As Integer,mx As String,jg As String,sum As Single For i=0To 9 If List2.List(i)<>““Then mx=List2.List(i) sum=sum+Mid(mx,4) End If Next i Text2.Text=③