18.行程編碼(Rim-length Coding)是一種相對簡單的壓縮技術,是將一個相同字符的連續 串用一個串長和字符來代替。例如,有一個字符串“aaabccddddd”,經過行程編碼壓縮后 可以用“3a1b2c5d”來表示。小李編寫了一個行程編碼的 VB 程序,功能如下:在文本框 Text1 中輸入原碼,單擊“壓縮”按鈕 Command1 后,在文本框 Text2 中顯示壓縮碼。程序設計界 面和運行界面分別如圖 a 和圖 b 所示。 (1)在設計程序界面時,要使文本框 Text2 顯示為空,可在其屬性窗口中將
屬性的 屬性值修改為空。 (2)實現上述功能的 VB 程序如下。請在橫線處填入合適代碼。 Private Sub Command1_Click ( ) Dim i As Integer,count As Integer,length As Integer Dim ch As String,key As String,s As String s=Text1.Text length=Len(s) key=①
i=2:count=1 Do While i<=length ch=Mid(s,i,1)If ch=key Then count=count+1 Else Text2.Text=Text2.Text+Str(count)+key count=1key=ch End If ②
Loop Text2.Text=Text2.Text+Str(count)+key'③ End Sub (3)如果刪除“③”所處的那一行代碼,運行該程序,在文本框 Text1 中輸入 aaabccddddd,單擊“壓縮”按鈕,則文本框 Text2 中顯示的內容為