實(shí)現(xiàn)上述功能的VB代碼如下,但加框處代碼有錯(cuò),請(qǐng)改正. Dim a(1To 8)As Integer Dim n As Integer Private Sub Form_Load
'n=8,排序前數(shù)據(jù)存儲(chǔ)在數(shù)組a中,并在列表框Listl中顯示 '代碼略 End Sub Private Sub Command1_Click
Dim flag As Boolean'flag值為True表示一遍加工中發(fā)生過交換 i=1 flag=True Do While'(1)i<=n-1Or flag=True
flag=False For j=n To i+1Step-1 If a(j)<a(j-1)Then k=a(j):a(j)=a(j-1):a(j-1)=k flag=True End If Next j i=i+1 Loop Str(i) Label3.Caption=“排序過程的加工遍數(shù)為“+'(2) For i=1To n List2.AddItem Str(a(i)) Next i End Sub.
程序運(yùn)行效果如圖2所示. 實(shí)現(xiàn)上述功能的VB程序如下: (1)請(qǐng)?zhí)钊牒线m代碼. Private Sub Command1_Click ( ?。?br />Dim n As Integer,s As String,i As Integer,ss As String Dim a As Integer'存儲(chǔ)加密前字符的ASCII碼 Dim b1As Integer,b2As Integer'分別存儲(chǔ)分割、轉(zhuǎn)換后的兩個(gè)十進(jìn)制數(shù) s=Text1.Text ①
For i=1To n a=Asc(Mid(s,i,1)) b1=a\16 b2=a Mod 16 ss=ss+Code2Char(b1)+Code2Char(b2) Text2.Text=ss Next i End Sub '十進(jìn)制值轉(zhuǎn)換為加密字符的函數(shù) Function Code2Char(c As Integer) As String Dim s As String s=“IlikeCHNpostcard” Code2Char=②
End Function (2)若將“密碼表”中值為“0”對(duì)應(yīng)的加密字符“I”改成“i”,加密后的密文可能無法解密,原因是