16.小明用VB編寫計算20位以內(nèi)2個正整數(shù)相減程序.程序功能如下:在文本框Text1中輸入被減數(shù),在文本框Text2中輸入減數(shù),單擊“計算”按鈕Comnand1,將相減的結(jié)果輸出到文本框Text3中.運行界面如圖所示. 實現(xiàn)上述功能的VB程序如下,但加框處代碼有錯,請改正. Private Sub Command1_Click ( ?。?br />Dim c(1To 50)As Integer Dim jiewei As Integer'存儲向高位借位 Dim ad As Integer,bd As Integer'存儲被減數(shù)和減數(shù)的每一位值 Dim e As Integer,alen As Integer,blen As Integer Dim a As String,b As String,s As String a=Text1.Text:b=Text2.Text '將大數(shù)存儲在a中 If Len(a)<Len(b) Then s=a:a=b:b=s ElseIf Len(a)=Len(b) Then ad=Val(Mid(a,1,1)) bd=Val(Mid(b,1,1)) If ad<bd Then s=a:a=b:b=s End If End If alen=Len(a):blen=Len(b) For i=1To alen If i<=blen Then ad=Val(Mid(a,alen-i+1,1)) bd=Val(Mid(b,blen-i+1,1)) e=ad+10-bd-1+jiewei Else ad=Mid(a,alen-i+1,1) e=ad+10+jiewei-1 End If jiewei=e\10 Next i If c(alen)<>0Then s=Str(c(alen)) For i=alen-1To 1Step-1 s=s+CStr(c(i)) Next i Text3.Text=s End Sub.
17.編寫一個統(tǒng)計公司地區(qū)銷售數(shù)據(jù)庫中每個銷售員銷售額的VB程序,實現(xiàn)如下功能: (1)在文本框Text1中輸入要統(tǒng)計的銷售地區(qū),單擊“讀取數(shù)據(jù)”按鈕Command1,該過程從數(shù)據(jù)庫讀取該銷售地區(qū)所有的銷售員姓名和銷售數(shù)據(jù),分別存儲在數(shù)組xm和xse中; (2)在文本框Text2中輸入需要統(tǒng)計銷售排名的數(shù)組存儲在變量pm中,單擊“統(tǒng)計”按鈕Command2,求出銷售額排名前m位的銷售人員并顯示在List1中(銷售額相同則排名也相同); (3)計算輸出該地區(qū)平均銷售額(保留2位小數(shù),不要求四舍五入),程序運行界面如圖所示: Dim xm(1to 30000)as long'存儲銷售員工的姓名數(shù)據(jù),最大處理個數(shù)為30000 Dim xse(1to 30000)as string'存儲銷售員工的銷售量數(shù)據(jù),最大處理個數(shù)為30000 Dim mc(1to 30000)as integer'存儲銷售員工的排名 Dim num as integer Dim pm as integer,sum as single Private Sub command1_click ( ?。?br />Dim conn As New ADODB.Connection,rs As New ADODB.Recordset Dim strSQL As String conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=“+App.Path+“\data.jye.ai“'打開到數(shù)據(jù)庫的鏈接 conn.Open strSQL=“select*from tab where'dq=“+Text1.Text+“'“ Set rs.ActiveConnection=conn'設(shè)置rs的ActiveConnection屬性,指定與其關(guān)聯(lián)的數(shù)據(jù)庫鏈接 rs.Open strSQL'打開記錄集,將從表student中讀取的結(jié)果集保存到記錄集rs中 List1.Clear num=0 Do while not rs.EOF xse(num)=rs.Fields(“銷售額“):xm(num)=rs.jye.ai(“姓名“) num=num+1 rs.MoveNext loop For i=1to num mc(i)=0:xse(i)=xse(i)/10000 ① next i rs.Close conn.close End Sub Private Sub command1_click ( ?。?統(tǒng)計數(shù)據(jù)的過程 Dim max as single,ave as single Dim i as integer,flag as integer pm=val(text1.text) dq=text1.text For j=1to pm max=xse(j) flag=j ② If xse(i)>max then max=xse(i):flag=i Next i If flag<>j then t=xse(j):xse(j)=xse(flag):xse(flag)=t st=xm(j):xm(j)=xm(flag):xm(flag)=st Endif Next j mc(1)=1 For i=2to pm if xse(i)=xse(i-1)then mc(i)=mc(i-1)else mc(i)=i Next i List1.clear For i=1to pm List1.a(chǎn)dditem str(mc(i)+““+xm(i)+““+str(xse(i)) Next i ave=③ label1.caption=str(ave) End Sub (1)分析程序代碼,當前處理的數(shù)據(jù)庫文件名為