Dim s1 As String, s2 As string, maxstr As string
Dim len1 As Integer, len2 As Integer, maxlen As Integer
Function Min (a As Integer, b As Integer) As Integer
If a >=b Then min = b else min = a
End Function
Function Search (m As Integer, n As Integer) As Integer
Dim c As Integer
c = 1
Do While c<= Min (len1 -m, len2 - n)
If Mid (s1, m+ c, 1) = Mid(s2,n+c,1) Then
Else
Exit Do 'Exit Do的作用是退出Do循环
End if
Loop
Search = c -1
End function
Private Sub Command1_Click()
s1 = Text1. Text
s2 = Text2. Text
len1 = Len (s1)
len2 = Len (s2)
maxlen = 0: maxstr = ""
Dim i As Integer, j As Integer, k As Integer
For i=1 To len1
For j=1 To len2
If Mid(s1, i, 1) = Mid(s2,j,1) Then
k = 'k用于记录连续公共子串的长度
If (k> maxlen) Then
maxlen = k
maxstr =
End if
End If
Next j
Next i
Labe13. Caption= "最长连续公共子串为:"& maxstr
Labe14. Cantion = "该子串长度是:"& str (maxlen)
End sub