實現(xiàn)上述功能的VB程序如下,波浪線處有錯誤,請改正。 Private Sub Command1_Click ( ?。?br />Dim a(1 To 100)As String Dim s As String,i As Integer Dim j As Integer,n As Integer Label4.Caption=““ s=Text1.Text n=Val(Text2.Text) i=1 Do While i<=Len(s) c=Mid(s,i,1) If c>=“A“And c<=“Z“Then a(i)=Chr((Asc(c)-Asc(“A“)+n) Mod 26+Asc(“A“)) ElseIf c>=“a“And c<=“z“Then a(i)=Chr((Asc(c)-Asc(“a“)+n) Mod 26+Asc(“a“)) Else a(i)=c End If i=i+1 Loop ‘① For i=2 To Len(s)\2 Step 2 t=a(i):a(i)=a(j):a(j)=t ‘② Next i For i=1 To Len(s) Label4.Caption=Label4.Caption+a(i) Next i End Sub
根據(jù)上述算法,小明編寫如下VB程序。 (1)若文本框Text1中輸入數(shù)據(jù)為“0,25,0,78,78,0,0”(不含引號),點擊“壓縮”命令按鈕,在文本框Text2輸出數(shù)據(jù)里有個0。 (2)實現(xiàn)上述功能的VB程序如下。請在橫線處填入合適代碼。 Dim a(1 To 100)As Integer,b(1 To 100)As Integer,c(1 To 100)As Integer Dim n As Integer,num As Integer Private Sub Init1 ( ) Dim s1 As String,c1 As String Dim i As Integer,t As Integer,len1 As Integer n=0:t=0:s1=Text1.Text len1=Len(s1) For i=1 To len1 ch=Mid(s1,i,1) If ch<>“,“Then ①
Else n=n+1:a(n)=t:t=0 End If Next i n=n+1:a(n)=t End Sub Private Sub Command1_Click ( ?。?br />Call Init1 Dim pa As Integer,pb As Integer Dim firstdata As Integer,count As Integer,i As Integer pb=1 firstdata=a(1) n=n+1 a(n)=a(n-1)+1 count=1 For i=2 To n If a(i)=firstdata Then count=count+1 Else If count=1 Then If firstdata>0 Then b(pb)=firstdata:pb=pb+1 Else b(pb)=0:b(pb+1)=0:pb=pb+2 End If Else b(pb)=0 b(pb+1)=count ②
pb=pb+3 End If count=1 firstdata=a(i) End If Next i Text2.Text=Str(b(1)) For i=③
Text2.Text=Text2.Text+“,“+Str(b(i)) Next i End Sub