。 Dim a(1 To 9)As Integer Private Sub Command1_Click ( ) Dim column As Integer,row As Integer,t As Integer,tmp As Integer Dim s As String,ch As String,result As String s=Text1.Text:result=““ For i=1 To Len(s) ch=Mid(s,i,1):t=①
Asc(ch)
Asc(ch)
column=(t-1)Mod 3+1 Do While t>=3 t=t\3 Loop row= tmp=(Asc(ch)+②
a((row-1)*3+column)
a((row-1)*3+column)
-65)Mod 26+65 result=result+Chr(tmp) Next i Text2.Text=result End Sub Private Sub Form_Load ( ?。?用來生成3*3矩陣 For i=1 To 9 a(i)=Int(Rnd*9)+1 s=s+Str(a(i)) If i Mod 3=0 Then List1.AddItem s s=““ End If Next i End Sub
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: