2014-07-18 159 views
0

我有一個逐行填充的二維數組。我有約200個參賽作品。這是可變的,但重複也被填充。如何從VBS中的二維陣列中刪除重複項

我該如何刪除這些重複項?或者甚至檢查數組中是否已經存在條目並跳過該重複條目?

for each oSingleNode in oNodeList 
    if oSingleNode.xml <> "" Then 
      Set oNode = oSingleNode.selectSingleNode("j.8:entity-reference") 
      if not oNode is nothing then 
       s = oNode.getAttribute("rdf:resource") 
       a = Split(s, "/") 
       attribute = a(ubound (a)-1) 
       Set oNodeTwo = oSingleNode.selectSingleNode("j.8:entity-label") 
       if not oNodeTwo is nothing then 
       label = oNodeTwo.text 
       array(rowIndex,index) = attribute 
       array(rowIndex,constClm)= label 
       debug2File array(rowIndex,index) & " " & array (rowIndex, constClm)       
      End if    
    End if 
End If 
+0

用於在VBScript唯一性的工具是字典插入(參見http://stackoverflow.com/a/6592801/603855) 。對於你的問題的具體解決方案,你應該定義/例證唯一/重複,並決定是否要清理'髒'數組或建立一個乾淨的。 –

+0

在您的方案中哪些被認爲是重複的?單個字段或整行? –

+0

我有解決方案,但不是在VB腳本。 – Suji

回答

0

問題是非常有趣的,這就是爲什麼一個做試穿it.sorry違反了標記,因爲它們要求潔具在VB腳本支持,希望這會讓你想起我的概念中,使試同樣在VB腳本中,我的結果如下。

Dim a(10, 10), i, j As Integer 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
j += 1 
If j > 10 Then 
i += 1 
j = 0 
End If 
check_val(CInt(TextBox1.Text), i, j) 
End Sub 

函數將檢查重複,並且如果不存在

 Public Sub check_val(ByVal x As Integer, ByVal i As Integer, ByVal j As Integer) 
     Dim t As Integer = 0 
     For k As Integer = 0 To 10 
     For l As Integer = 0 To 10 
     If x = a(k, l) Then 
     t = 1 
     End If 
     Next 
     Next 
     If t = 0 Then 
     a(i, j) = x 
     Else 
     MsgBox("Repeting value") 
     j = j - 1 
     End If 
     End Sub