16.【加試題】小柯編寫(xiě)了一個(gè)多位數(shù)乘法的VB程序,運(yùn)行界面如圖所示。文本框Text1中輸入一個(gè)小于等于1000位的被乘數(shù),文本框Text2中輸入1位乘數(shù),點(diǎn)擊“開(kāi)始計(jì)算”按鈕Command1后,在文本框Text3中顯示計(jì)算結(jié)果。 實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有錯(cuò),請(qǐng)改正。 Private Sub Command1_Click( ?。?br />Dim d(1 To 1001)As Integer Dim strl As String,str2 As String Dim i As Integer,n As Integer,k As Integer,s As Integer strl=Text1.Text n=Len(strl) For i=1 To n d(i)=Val(Mid(strl,i,1)) Next i s=0's表示進(jìn)位 k=Val(Text2.Text) For i=n To 1 Step-1 '① s=d(i)\10 d(i)=d(i) Mod 10 Next i If s<>0 Then str2=Trim(Str(s)) Else str2=““'Trim函數(shù)用來(lái)刪除字符串首尾的空格 For i=1 To n
實(shí)現(xiàn)上述功能的VB程序段如下: (1)請(qǐng)?jiān)跈M線(xiàn)處填入合適代碼: Dim f(0 To 15)As Integer Const Code=“KnGjLtWb0aPHZqYc“ Private Sub Command1_Click( ) Dim rq As String,sq As String Dim c As Integer,i As Integer,d As Integer For i=0 To 15 f(i)=0 Next i rq=Text1.text sq=““:d=0 If Len(rq)<>8 Then Label2.Caption=“請(qǐng)輸入8位日期!“ Else For i=1 To 8 c=Val(Mid(rq,i,1)) d=d+c sq=
+sq Next i If d>=16 Then yz=GetChar(d Mod 16+1)+GetChar(d\16+1) Else yz=GetChar(d Mod 16+1)+“X“ End If Label2.Caption=sq+yz End If End Sub '獲取不重復(fù)的加密字符 Function GetChar(x As Integer) As String Dim flag As Boolean flag=False Do While flag=False f(x)=f(x)+1 If f(x)=1 Then
f(x)=f(x)+1 flag=True Else x=(x+1)Mod 10 End If Loop End Function (2)若輸入的日期是“20170818”,則該授權(quán)碼的驗(yàn)證碼字符是