Private Sub Command1_Click() Dim MyOne, MyTwo Dim i As Integer, j As Integer MyOne = Array("1", "2", "3", "4", "2", "3") For i = 0 To 5 MyTwo = MyOne(i) For j = i + 1 To 5 If (MyTwo = MyOne(j)) Then Dim newr(4) For k = 0 To 5 If (k <> j) Then newr(k) = MyOne(k) End If Next End If Next Next End Sub我折腾了半天,把自己折腾糊涂了。总之是这个思路。
Sub test() Dim arrayTest(7) As String arrayTest(0) = "1" arrayTest(1) = "2" arrayTest(2) = "3" arrayTest(3) = "4" arrayTest(4) = "3" arrayTest(5) = "2" arrayTest(6) = "8" Dim flag As Integer Dim tempStr As String Dim arrayTest1() ReDim arrayTest1(1) Dim i As Integer Dim j As Integer For i = 0 To UBound(arrayTest) - 1 flag = 0 If i = 0 Then ReDim Preserve arrayTest1(UBound(arrayTest1)) arrayTest1(UBound(arrayTest1) - 1) = arrayTest(i) Else For j = 0 To UBound(arrayTest1) - 1 If arrayTest1(j) = arrayTest(i) Then flag = flag + 1 Else '不添加 End If Next ' If flag = 0 Then ReDim Preserve arrayTest1(UBound(arrayTest1) + 1) arrayTest1(UBound(arrayTest1) - 1) = arrayTest(i) End If End If If i = UBound(arrayTest) - 1 Then Exit For End If Next For i = 0 To UBound(arrayTest1) - 1 MsgBox arrayTest1(i) Next End Sub 我自己研究出来了,不要for嵌套,那个到时候很乱,不怎么好处理。我这样貌似OK了,谢谢你的支持
Private Sub Command1_Click()
Dim MyOne, MyTwo
Dim i As Integer, j As Integer
MyOne = Array("1", "2", "3", "4", "2", "3")
For i = 0 To 5
MyTwo = MyOne(i)
For j = i + 1 To 5
If (MyTwo = MyOne(j)) Then
Dim newr(4)
For k = 0 To 5
If (k <> j) Then
newr(k) = MyOne(k)
End If
Next
End If
Next
Next
End Sub我折腾了半天,把自己折腾糊涂了。总之是这个思路。
Dim arrayTest(7) As String
arrayTest(0) = "1"
arrayTest(1) = "2"
arrayTest(2) = "3"
arrayTest(3) = "4"
arrayTest(4) = "3"
arrayTest(5) = "2"
arrayTest(6) = "8"
Dim flag As Integer
Dim tempStr As String
Dim arrayTest1()
ReDim arrayTest1(1)
Dim i As Integer
Dim j As Integer
For i = 0 To UBound(arrayTest) - 1
flag = 0
If i = 0 Then
ReDim Preserve arrayTest1(UBound(arrayTest1))
arrayTest1(UBound(arrayTest1) - 1) = arrayTest(i)
Else
For j = 0 To UBound(arrayTest1) - 1
If arrayTest1(j) = arrayTest(i) Then
flag = flag + 1
Else
'不添加
End If
Next
'
If flag = 0 Then
ReDim Preserve arrayTest1(UBound(arrayTest1) + 1)
arrayTest1(UBound(arrayTest1) - 1) = arrayTest(i)
End If
End If
If i = UBound(arrayTest) - 1 Then
Exit For
End If
Next For i = 0 To UBound(arrayTest1) - 1
MsgBox arrayTest1(i)
Next
End Sub
我自己研究出来了,不要for嵌套,那个到时候很乱,不怎么好处理。我这样貌似OK了,谢谢你的支持