條(填數(shù)字)。 (2)實(shí)現(xiàn)上述功能的 VB 程序如下,請(qǐng)?jiān)跈M線處填入合適代碼。 Const n=20 Dim score(1 To n)As Single Function adj(s As String,n As Integer) ‘此函數(shù)功能:在字符串 s 前添加若干個(gè)空格,使其長(zhǎng)度變?yōu)?nbsp;n。代碼略 End Function Function search_left(key As Integer) ‘此函數(shù)功能:返回大于等于 key 的數(shù)組元素的起始位置。代碼略。 End Function Function search_right(key As Integer) Dim i As Integer,j As Integer,m As Integer i=1:j=n Do While i<=j ①
If key>=score(m)Then i=m+1 Else j=m-1 Loop ②
End Function Private Sub Form_Load ( ) ‘從數(shù)據(jù)庫(kù)中讀取成績(jī)存數(shù)組 score,記錄數(shù)存 n,并對(duì)此數(shù)組 score 升序排序,代碼略 End Sub Private Sub Command1_Click ( ) Dim num1 As Integer,num2 As Integer,first As Integer,last As Integer List2.Clear num1=Val(Text1.Text):num2=Val(Text2.Text) first=search_left(num1):last=search_right(num2) ③
If total<=0 Then List2.AddItem“無(wú)篩選到的記錄!“ Else List2.AddItem“篩選到“+Str(total)+“條記錄!“ List2.AddItem“依次是:“ For i=first To last List2.AddItem adj(Str(i),3)+adj(Str(score(i)),6) Next i End If End Sub