2010-11-04 53 views
0
Dim group11_0_count = 0 
     Dim group11_1_count = 0 
     Dim group11_2_count = 0 

     Dim m As Integer = 0 
     Dim n As Integer = 0 
     Dim increment2 As Integer 


     For m = 0 To machings2.Items.Count - 1 
      For n = 0 To 3 
       If machings2.Items(m).ToString.Chars(n) = "1" Then 
        increment2 = increment2 + 1 
       End If 
      Next 
      If (increment2 = 0) Then 
       group11_0_count = group11_0_count + 1 
       group11_1_0.Items.Add(machings2.Items(m)) 
      End If 

      If (increment2 = 1) Then 
       group11_1_count = group1_1_count + 1 
       group11_1_1.Items.Add(machings2.Items(m)) 
      End If 

      If (increment2 = 2) Then 
       group11_2_count = group1_2_count + 1 
       group11_1_2.Items.Add(machings2.Items(m)) 
      End If 
      increment2 = 0 
     Next 

     If (group11_0_count > 0 AndAlso group11_1_count > 0) Then 
      Dim result = "" 
      Dim index As Integer = 0 
      Dim gg As Integer = 0 
      Dim hh As Integer = 0 
      Dim i As Integer = 0 
      For hh = 0 To group11_1_count - 1 
       For gg = 0 To group11_0_count - 1 
        result = "" 
        index = 0 
        For i = 0 To 3 
         If group11_1_0.Items(gg).ToString.Chars(i) <> group11_1_1.Items(hh).ToString.Chars(i) Then 
          result &= "-" 
          index = index + 1 
         Else 
          result &= group11_1_0.Items(gg).ToString.Chars(i) 
         End If 
        Next 

        If (index = 1) Then 
         machings3.Items.Add(result) 
        End If 
       Next 
      Next 
     End If 

我比較兩個組合框項目的項目一樣,InvalidArgument =值是無效的「索引」

combobox1 items 
0000 

combobox items 
0001 
0010 

the result will be like that in machings3 combobox 
000- 
00-0 

Here the differnce between two items indicated by - sign 

But i am getting InvalidArgument=Value of '2' is not valid for 'index'. 
+0

OK - 我已經知道這些行是錯誤的「group11_2_count = group1_2_count + 1」,應該是「group11_2_count = group11_2_count + 1」,也應該是「group11_1_count = group1_1_count + 1」是「group11_1_count = group11_1_count + 1」 – 2010-11-04 19:38:31

回答

0

我不能弄明白你的源代碼,哪裏的IndexOutOfRangeException發生。但是你知道在Combobox中需要3個項目才能訪問索引爲2的項目?每個集合都從0開始。

+0

感謝您的回覆我已經找到了我的自我.....這些行是錯誤的「group11_2_count = group1_2_count + 1」這應該是「group11_2_count = group11_2_count + 1」,也「group11_1_count = group1_1_count + 1「應該是」group11_1_count = group11_1_count + 1「 – 2010-11-04 19:40:01

相關問題