2017-09-13 50 views
-1

我被要求做的是把一个用户输入作为一个整数。例如,6是输入。 6变成等式(6-1)*(6)/ 2,这相当于15对。然后,我再调用另一个将输入处理为{for next}循环的子集。我有一个If语句来检查重复项,但它是有限的。我曾尝试将迭代变量传入if语句中,但这样做无法正常工作。VBA匹配对没有重复

下面是代码:

For intOuter = 1 To options - 1 

    'The intInner loop cycles through and sets up the loop for the combination and determines if 
    'the combination has been made already 

     For intInner = 1 To options 

    'If statement tests if a combination has already been made if it has it will not be printed 
    'if it has not been combined then it will be printed to the immediate window 


       If intOuter <> intInner And intOuter <> value + 1 And intOuter <> value + 2 And intOuter <> value + 3 _ 
       And intOuter <> value + 4 Then 
         Debug.Print intOuter & " vs " & intInner & " Actual" 
       End If 

     Next intInner 

    Next intOuter 

输出这个例子正确显示将是(与6的用户输入)预先

1vs2 
1vs3 
1vs4 
1vs5 
1vs6 
2vs3 
2vs4 
2vs5 
2vs6 
3vs4 
3vs5 
3vs6 
4vs5 
4vs6 
5vs6 

谢谢我很欣赏它。

+0

好像你只是想intInner比intOuter ... – Joffan

回答

1

看起来你很近!试试这个:

Dim intInner As Integer 
    Dim intOuter As Integer 

    For intOuter = 1 To Options - 1 
     For intInner = intOuter + 1 To Options 
      Debug.Print intOuter & "vs" & intInner 
     Next 
    Next 
+0

谢谢,@BrianMStafford我知道我很接近大我想我是看着这个TO0长,我的脑子在想它。我非常感谢帮助。 – Rico