2017-09-22 37 views
0

我不明白爲什麼我不能在VBA比較的數組。我創建了一個數組,開始0 1 2 3.我添加了一個比較,因爲下標錯誤試圖比較0到0 - 1,所以它只能在1開始比較並繼續。現在我收到一個類型不匹配13,我不知道爲什麼數據類型不同/不工作。我猜我在for循環不被認爲是一個int或東西? 它未能在CoordinatesArray(ⅰ)= CoordinatesArray(I-1)類型不匹配陣列位置比較VBA的

代碼:

For i = 0 To NumLines - 1 
     coordx1 = (vLines(12 * i + 6)) 
     coordy1 = (vLines(12 * i + 7)) 
     coordz1 = (vLines(12 * i + 8)) 
     CoordinatesArray(i) = Array(coordx1, coordy1, coordz1) 
     If i > 0 Then 
      If CoordinatesArray(i) = CoordinatesArray(i - 1) Then 
       coordx1 = (vLines(7)) 
+3

甲小評:我注意到你使用TimWilliams的答案,但沒有將其標記爲正確。請回答您的問題,並通過點擊答案中的複選標記來標記那些正確的答案。如果您未能提供反饋,其他用戶將不再回答您的問題。 –

回答

2

你將需要每個值分別交錯數組中比較:

For i = 0 To NumLines - 1 
    coordx1 = (vLines(12 * i + 6)) 
    coordy1 = (vLines(12 * i + 7)) 
    coordz1 = (vLines(12 * i + 8)) 
    CoordinatesArray(i) = Array(coordx1, coordy1, coordz1) 
    If i > 0 Then 
     If CoordinatesArray(i)(1) = CoordinatesArray(i - 1)(1) And _ 
      CoordinatesArray(i)(2) = CoordinatesArray(i - 1)(2) And _ 
      CoordinatesArray(i)(3) = CoordinatesArray(i - 1)(3) Then 
      coordx1 = (vLines(7))