Get array From column without duplicates

3 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