2014-01-19 2 views
1

특정 레코드가 이미 있는지 확인하기 위해 테스트 할 배열 (또는 다른 임시 저장 방법)을 만들려고합니다. 그렇다면 단지 배열에 레코드를 추가하고 싶습니다.지도에 노드를 만드는 함수가 없다면 레코드를 배열에 추가하고 싶을 것입니다.함수를 적용하기 전에 이전 레코드 확인

개념은 각 유닛에 대한 맵에 노드를 한 번만 추가하는 것입니다. 데이터베이스에는 unitnumb, lat, long 및 time (날짜/시간 형식) 만 포함됩니다. 이미 데이터베이스를 쿼리했으며 마지막 1000 개의 레코드까지 끌어 올렸습니다.

현재 나는 이전에 데이터베이스에 존재하고 한 경우에만 addmarker 스크립트를 실행하는 경우

  Dim mapcontains() As String = {""} 


       For pop As Integer = 0 To filltab.Rows.Count - 1 
        current = filltab.Rows(pop)("unitnumb") 
        If Array.FindIndex(mapcontains, Function(s) s.Contains(current)) = 0 Then 
         WebBrowser1.Document.InvokeScript("AddMarker", New Object() {"Unit: " & filltab.Rows(pop)("unitnumb") & " at " & filltab.Rows(pop)("time"), filltab.Rows(pop)("lat"), filltab.Rows(pop)("long")}) 

        End If 
        mapcontains(pop) = current 
       Next 

현재 내가 볼 수있는 경우 문을 완료하고 배열을 비교 한 후 배열에 각 항목을 추가하는 시도가 아니.

현재이 기능이 작동하지 않습니다. 어떻게 작동합니까?

답변

2

Dictionary (키와 관련된 별도의 데이터가 필요한 경우) 또는 Hashset (사용하지 않는 경우)을 사용하면 훨씬 편리합니다. 예를 들어

:

Dim mapcontains As New System.Collections.Generic.HashSet(Of String) 

    For pop As Integer = 0 To filltab.Rows.Count - 1 
     current = filltab.Rows(pop)("unitnumb") 
     If Not mapcontains.Contains(current) Then 
      WebBrowser1.Document.InvokeScript("AddMarker", New Object() {"Unit: " & filltab.Rows(pop)("unitnumb") & " at " & filltab.Rows(pop)("time"), filltab.Rows(pop)("lat"), filltab.Rows(pop)("long")}) 
      mapcontains.Add(current) 
     End If 
    Next 
관련 문제