Get array From column without duplicates

4 posts / 0 new
Last post
HdT
Offline
Joined: 04/17/2018 - 00:09
Get array From column without duplicates

Hi!
I want to get all different filelocations from one culumn in an array without duplicates.
 

My Script so far:
 Set LoDB = Client.OpenDatabase(sBelegDatei) Set LoRS = LoDB.RecordSet LoRS.ToFirst Set LoRec = LoRS.ActiveRecord lsBelegVerzeichnis = "" j = 0 For i = 0 To LoDB.Count  LoRS.Next  If LsBelegVerzeichnis <> LoRec.GetCharValue("TEST")  Then   ReDim Preserve asVerzeichnisse(j)   LsBelegVerzeichnis =  LoRec.GetCharValue("TEST")   asVerzeichnisse(j) = LsBelegVerzeichnis   Call LogMsg ("asVerzeichnisse(" & j & ") = " & asVerzeichnisse(j), "Information")   Call LogMsg ("LsBELEGVERZeichnis =" & LsBelegVerzeichnis, "Information")   j = j + 1  End If  'Call LogMsg (LoRec.GetCharValue("BELEGVERZEICHNIS"), "Information")   Next  Set LoRec = Nothing Set LoRS = Nothing Set LoDB = Nothing LoDB.Close
 
Here is my problem:
How do I remove the duplicates from my array?
 Example for the Column:

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Probably the easiest way is to do a summary first, that will remove all the duplciates.  Then pull the items from the summary instead of the main file.

Another way is in IDEAScript everytime you optain a new record you have to check to see if it is in the current arrays (through a loop) and if it isn't then you add it. 

My preference is perfroming the summary first, depending on the file size this will probably be the most efficient.

scotchy33
Offline
Joined: 09/05/2012 - 15:51

I think you were trying to do something similar to the below, which should work.
 
Sub Main
Dim gAccountChr() As String
Dim acctCounter As IntegerDim j As Integer
acctCounter = 0
 Set db = client.currentdatabase
Set rs = db.recordset
 
 x = rs.count 
 rs.AddKey "TEST", "A" 
 rs.ToFirst
 
  rs.getat (1)
  Set rec = rs.activerecord
    FirstRecChr = rec.GetCharValue("TEST")
    ReDim gAccountChr(acctCounter)
    gAccountChr(acctCounter) = FirstRecChr
    For j = 2 To x
   rs.getat (j)
   Set rec = rs.activerecord
 
   CurrentRecordValueChr = rec.GetCharValue("TEST")
       If CurrentRecordValueChr <> FirstRecChr Then
            ReDim Preserve gAccountChr(UBound(gAccountChr) + 1)
          acctCounter = acctCounter + 1
          gAccountChr(acctCounter) = CurrentRecordValueChr
          FirstRecChr = CurrentRecordValueChr
         End If
      Next j
  End Sub
 
 

HdT
Offline
Joined: 04/17/2018 - 00:09

Due to vacation I haven´t worked on my problem, but with your help I used following scirpt:
  Set oDB = Client.OpenDatabase(sFile)
  Set oRS = oDB.RecordSet
  oRS.ToFirst
  For i = 0 To oRS.Count - 1
   oRS.Next
   Set oRec = oRS.ActiveRecord
   bTemp = False
   lsTEST=  oRec.GetCharValue("TEST")
 
   For j = 0 To UBound(asTEST)
    If asTest(j) = lsTest Then
     bTemp = True
     Exit For
    End If
   Next
   If bTemp = False Then
    ReDim Preserve asTest(UBound(asTest)+1)
    asVerzeichnisse(UBound(asTest)) = lsTest
   End If
  Next
  Set oRec = Nothing
  Set oRS = Nothing
  oDB.Close
  Set oDB = Nothing