先说下我的做法
窗体上有三个text,三个command text1输入你任意你想的数字,不同数字间用一个空格隔开
text2和text1是一样的 text3中输出两个文本框相同的数字,不同数字之间是写一个空格隔开的
程序使用: 1,按下command2此时会提醒在text1中输入你想要的数字 2,按下command3此时会提醒在text2中输入你想要的数字 3,按下command3此时就会显示两文本框中相同的数字
程序如下: 已测试通过,希望能对你有所帮助
Function f(a As String, b As String) As Integer
Dim s() As String, i%, j%
Dim y() As String
s = Split(a, " ")
y = Split(b, " ")
For i = 0 To UBound(s)
For j = 0 To UBound(y)
If s(i) = y(j) Then
Text3.Text = Text3.Text & " " & s(i)
GoTo h
End If
Next j
h: Next i
End Function
Private Sub Command1_Click()
Dim i As Integer
i = f(Text1.Text, Text2.Text)
End Sub
Private Sub Command2_Click()
Print "请输入text1里的数,不同的数用空格分开"
Text1.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
Private Sub Command3_Click()
Print "请输入text2里的数,不同的数用空格分开"
Text2.Text = ""
Text2.SetFocus
End Sub
追问两个文本框中相同的数字并不是我想要的,而是它已经自然生成的,也就是说是在自然生成的数字中找相同的数字。