16.用VB程序編寫計(jì)算兩個(gè)字符環(huán)上最長連續(xù)公共字符串長度的程序.例如,字符串“ABCEFAGADEGKABUVKLM”的首尾連在一起,構(gòu)成一個(gè)環(huán);字符串“MADJKLUVKL”的首尾連在一起,構(gòu)成另一個(gè)環(huán);“UVKLMA”是這兩個(gè)環(huán)的一個(gè)連續(xù)公共字符串. 功能如下:在文本框Text1中輸入字符串1,在文本框Text2中輸入字符串2,單擊“判斷”按鈕Command1后, 在文本框Text1中顯示公共字符串,程序運(yùn)行界面如圖所示. 實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有誤,請改正. Function maxnum(a As Integer,b As Integer)As Integer If a<b Then maxnum=a Else maxnum=b End Function Private Sub Command1_Click ( ?。?br /> Dim sl As String,s2 As String,res As String'存儲2個(gè)字符環(huán) Dim i As Integer,j As Integer,m As Integer Dim num As Integer,pd As Boolean,n As Integer Dim max As Integer'存儲字符環(huán)中最長的連續(xù)公共字符串長度 Dim resmax As string'存儲字符環(huán)中最長的連續(xù)公共字符串 s1=Text1.Text:s2=Text2.Text max=0:res='''' For i=1 To Len(s1) For j=1 To Len(s2) If Mid(s1,i,1)=Mid(s2,j,1)Then res=Mid(s1,i,1) num=l:m=i:n=j pd=True EndIf Do While pd=True m=m+1:n=n+1 If m>Len(s1)Then m=m-Len(s1) If n>Len(s2)Then n=n-Len(s2) If Then'(1) pd=flash Else num=num+1 res=res+Mid(s2,n,1) EndIf If num>=maxnum (Len(s1),Len(s2)) Then pd=False Loop If num>max Then '(2) resmax=res res='''' EndIf Next j Next i Text3.Text=resmax End Sub.
(填數(shù)據(jù)表名). (3)請?jiān)跈M線處填入合適的代碼. Dim xs(1 To 1000)As Integer,jg(1 To 1000)As Integer'數(shù)組大小滿足處理要求 Dim n As Integer'存儲數(shù)據(jù)庫總的記錄數(shù) Private Sub Form_Load( ) Dim conn As New adodb.Conncction,rs As New adodb.Recordset Dim strSQL As String conn.ConnectionString=“Provider=Microsoft.ACE.OLEDB.12.0; Data Source=“+App.Path+“\date.jye.ai“ conn.Open strSQL=“SELECT*From tab“ Set rs.ActiveConnection=conn '本過程的其他語句略 '本過程求出n的值 End Sub Private Sub Command1_Click( ?。?br /> Dim bf(1 To 1000)As Integer'數(shù)組bf存儲大于等于輸入零件數(shù)的數(shù)據(jù) Dim maxn As Integer,d As Integer,k As Integer,da As Integer Dim i As Integer,j As Integer,flag As Integer da=Val(Text1.Text):maxn=0 For j=1 To n If xs(j)>=da Then maxn=maxn+1:bf(maxn)=xs(j) Next j k=1 For i=1 To maxn flag=0 For j=1 To i-1 If bf(i)=bf(j) Then flag=1 Next j If flag=0 Then
d=1 For j=i+1 To maxn If bf(i)=bf(j) Then
Next j jg(2*k)=d k=k+1 EndIf Next i k=k-1:List1.Clear For j=1 To 2*k Step 2 List1.AddItem Str(jg(j))+““+Str(jg(j+1)) Next j End Sub.