vb分组合并文本框数组
vb分组合并文本框数组数据,如文本框有很多数组数据,如1251017,25111822,138916,1381516,1391516,39151620,39151621怎...
vb分组合并文本框数组数据,如文本框有很多数组数据,如1 2 5 10 17,2 5 11 18 22,1 3 8 9 16,1 3 8 15 16,1 3 9 15 16,3 9 15 16 20,3 9 15 16 21怎么把含有四个相同数的数组进行合并,如1 3 8 9 16与1 3 8 15 16合并得到数组1 3 8 16 9 15,同一数组只能被合并一次,如1 3 8 15 16 与1 3 9 15 16也有四个数相同,但1 3 8 15 16已经被合并了,就不能再次合并,那1 3 9 15 16就与剩下数组3 9 15 16 20,3 9 15 16 21合并,得到3 9 15 16 1 20 21数组,相同的四个数排在前面,不包含四个相同数的显示到另一个文本框,先谢谢了!
展开
2个回答
展开全部
首先,是不是每一组原始数据兄亏都是5个数字?
Private Sub Command1_Click()
'************定义变量***************
Dim A() As String '记录分离好的二维数组A(i,j)——i指数据组序号,取值为0-N,凯漏j=5依次放五个元素
Dim N As Integer '记录text1中一共有多少组数据
Dim B(5) As Integer '分离每一组数据中的五个元素使盯尘烂用的临时数组
Dim C() As Boolean '记录每一组数据是否已经得到合并,true——已经合并过,false——没有合并过
Dim D() As String '分离元素时使用(下标从0-4)
Dim I As Integer, J As Integer, K As Integer, L As Integer 'I——L为循环变量
Dim M As Integer '记录相同数字的个数
Dim S1 As String '记录要在text2中显示的内容
Dim Num1 As Integer '记录有重复数字的数组的个数
Dim Str1() As String '分离数组时使用(下标从0-N)
'************初始值设置,将text1分离成数组数据***************
Str1() = Split(Text1.Text, ",")
N = UBound(Str1())
ReDim A(N, 5)
ReDim C(N)
For I = 0 To N
C(I) = False
D() = Split(Str1(I), " ")
For J = 0 To UBound(D())
A(I, J) = D(J)
Next
Next
S1 = "能合并的数组:"
'************开始查找有相同元素的数组***************
For I = 0 To N - 1
Num1 = 0
If Not C(I) Then
For J = I + 1 To N
If C(J) = False Then
M = 0
If Num1 = 0 Then
Dim T(3) As String '记录4个相同的数字
For K = 0 To 4
For L = 0 To 4
If A(I, K) = A(J, L) Then
T(M) = A(I, K)
M = M + 1
If M = 4 Then
C(I) = True
C(J) = True
Num1 = Num1 + 1
Dim C1 As Integer '临时循环变量
For C1 = 0 To 3
If C1 <> 0 Then S1 = S1 & " "
S1 = S1 & T(C1)
Next
S1 = S1 & " " & Bchf(T(), A(), I)
S1 = S1 & " " & Bchf(T(), A(), J)
Exit For
End If
End If
Next
If M = 4 Then Exit For
Next
Else
For K = 0 To 3
For L = 0 To 4
If T(K) = A(J, L) Then
M = M + 1
If M = 4 Then
C(J) = True
Num1 = Num1 + 1
S1 = S1 & " " & Bchf(T(), A(), J)
Exit For
End If
End If
Next
If M = 4 Then Exit For
Next
End If
End If
Next
End If
If Num1 > 0 Then S1 = S1 & ","
Next
S1 = Left(S1, Len(S1) - 1) & vbCrLf
S1 = S1 & "不能合并的数组:"
For I = 0 To N
If Not C(I) Then
For J = 0 To 4
If J <> 0 Then S1 = S1 & " "
S1 = S1 & A(I, J)
Next
S1 = S1 & ","
End If
Next
S1 = Left(S1, Len(S1) - 1)
Text2.Text = S1
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = "1 2 6 15 16,1 2 7 17 18,1 2 7 15 16,1 2 8 15 16,1 2 9 15 16,1 2 10 15 16,2 4 6 18 19,2 4 7 18 19,2 4 8 18 19,2 5 11 19 21,2 7 15 16 23"
Text2.Text = ""
Command1.Caption = "开始"
Command2.Caption = "退出"
End Sub
Private Function Bchf(X() As String, Y() As String, Z As Integer) As String
Dim Af1 As Integer, Af2 As Integer
For Af2 = 0 To 4
For Af1 = 0 To 3
If Y(Z, Af2) = X(Af1) Then Exit For
Next
If Af1 = 4 Then
Bchf = Y(Z, Af2)
Exit For
End If
Next
End Function
Private Sub Command1_Click()
'************定义变量***************
Dim A() As String '记录分离好的二维数组A(i,j)——i指数据组序号,取值为0-N,凯漏j=5依次放五个元素
Dim N As Integer '记录text1中一共有多少组数据
Dim B(5) As Integer '分离每一组数据中的五个元素使盯尘烂用的临时数组
Dim C() As Boolean '记录每一组数据是否已经得到合并,true——已经合并过,false——没有合并过
Dim D() As String '分离元素时使用(下标从0-4)
Dim I As Integer, J As Integer, K As Integer, L As Integer 'I——L为循环变量
Dim M As Integer '记录相同数字的个数
Dim S1 As String '记录要在text2中显示的内容
Dim Num1 As Integer '记录有重复数字的数组的个数
Dim Str1() As String '分离数组时使用(下标从0-N)
'************初始值设置,将text1分离成数组数据***************
Str1() = Split(Text1.Text, ",")
N = UBound(Str1())
ReDim A(N, 5)
ReDim C(N)
For I = 0 To N
C(I) = False
D() = Split(Str1(I), " ")
For J = 0 To UBound(D())
A(I, J) = D(J)
Next
Next
S1 = "能合并的数组:"
'************开始查找有相同元素的数组***************
For I = 0 To N - 1
Num1 = 0
If Not C(I) Then
For J = I + 1 To N
If C(J) = False Then
M = 0
If Num1 = 0 Then
Dim T(3) As String '记录4个相同的数字
For K = 0 To 4
For L = 0 To 4
If A(I, K) = A(J, L) Then
T(M) = A(I, K)
M = M + 1
If M = 4 Then
C(I) = True
C(J) = True
Num1 = Num1 + 1
Dim C1 As Integer '临时循环变量
For C1 = 0 To 3
If C1 <> 0 Then S1 = S1 & " "
S1 = S1 & T(C1)
Next
S1 = S1 & " " & Bchf(T(), A(), I)
S1 = S1 & " " & Bchf(T(), A(), J)
Exit For
End If
End If
Next
If M = 4 Then Exit For
Next
Else
For K = 0 To 3
For L = 0 To 4
If T(K) = A(J, L) Then
M = M + 1
If M = 4 Then
C(J) = True
Num1 = Num1 + 1
S1 = S1 & " " & Bchf(T(), A(), J)
Exit For
End If
End If
Next
If M = 4 Then Exit For
Next
End If
End If
Next
End If
If Num1 > 0 Then S1 = S1 & ","
Next
S1 = Left(S1, Len(S1) - 1) & vbCrLf
S1 = S1 & "不能合并的数组:"
For I = 0 To N
If Not C(I) Then
For J = 0 To 4
If J <> 0 Then S1 = S1 & " "
S1 = S1 & A(I, J)
Next
S1 = S1 & ","
End If
Next
S1 = Left(S1, Len(S1) - 1)
Text2.Text = S1
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = "1 2 6 15 16,1 2 7 17 18,1 2 7 15 16,1 2 8 15 16,1 2 9 15 16,1 2 10 15 16,2 4 6 18 19,2 4 7 18 19,2 4 8 18 19,2 5 11 19 21,2 7 15 16 23"
Text2.Text = ""
Command1.Caption = "开始"
Command2.Caption = "退出"
End Sub
Private Function Bchf(X() As String, Y() As String, Z As Integer) As String
Dim Af1 As Integer, Af2 As Integer
For Af2 = 0 To 4
For Af1 = 0 To 3
If Y(Z, Af2) = X(Af1) Then Exit For
Next
If Af1 = 4 Then
Bchf = Y(Z, Af2)
Exit For
End If
Next
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询