怎样用vb把两个文本框中相同的数字找出来,显示在第三个文本框中?

2024-12-12 15:31:08
推荐回答(3个)
回答1:

先说下我的做法
窗体上有三个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

回答2:

Private Sub Command1_Click()
Dim Str1 As String, Str2 As String
Dim I As Integer, J As Integer
Str1 = Text1
Str2 = Text2
For I = 0 To 9
If InStr(Str1, Trim(Str(I))) > 0 And InStr(Str2, Trim(Str(I))) > 0 Then Text3 = Text3 & I
Next I
End Sub

回答3:

先用查找语句,在a$=那个数,再text3.text=a$