2014-07-18 160 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