。 (2)請在橫線處填入合適的代碼。 Dim a(1 To 100)As String'數組大小滿足處理要求,學生學號 Dim b(1 To 100)As String'數組大小滿足處理要求,學生姓名 Dim i As Integer'學生總數 Dim j As Integer Dim dd(1 To 100)As Integer Private Sub Form_Load
( )
( )
‘從數據庫讀取全班同學的相關信息,存儲在數組a、數組b和變量i中 Dim n As Integer Dim conn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strSQL As String conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=“& App.Path &“\1718.jye.ai“ conn.Open Set rs.ActiveConnection=conn strSQL=“SELECT*FROM stuinfo“ rs.Open strSQL '本過程的其他語句略 End Sub Private Sub Command1_Click ( ) Dim ShuruNum As Integer,k As Integer,y As Integer,n As Integer Randomize ShuruNum=Val(Text1.Text) Label4.Caption=““ For k=1 To i dd(k)=0 Next k If ShuruNum>0 And ShuruNum<=i Then j=1 Do While j<=ShuruNum y=Int(Rnd
( )
( )
*i)+1 If
CheckCF(y)=True
CheckCF(y)=True
Then'① dd(j)=y j=j+1 End If Loop List2-Clear For n=1 To ShuruNum List2.AddItem
a(dd(n))+b(dd(n))或a(dd(n))&b(dd(n))
a(dd(n))+b(dd(n))或a(dd(n))&b(dd(n))
'② Next n Else Label4.Caption=“錯誤:沒有輸入中獎人數或超過學生總數“ End If End Sub '核對重復,避免同一人再次中獎 Private Function CheckCF(p As Integer) As Boolean Dim m As Integer,x As Boolean x=True'初始化 For m=1 To j If
p=dd(m)
p=dd(m)
Then'③ x=False Exit For End If Next m CheckCF=x End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: