Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FILL ARRAY WITH NO DUPLICATE VALUE

Status
Not open for further replies.

sal0003

Programmer
Apr 5, 2010
22
IT
I need to insert into array a unique value based a date

I loop with the for next a value date.
All value are date in this format dd/mm/yyyy hh:mm

for example:
...
03/02/2001 12.14
01/01/2001 12.23
01/01/2001 05.11
03/02/2001 06.11
01/01/2001 03.10
...

i need to fill array only with the value most little from the same date

in this case array:
01/01/2001 03.10
03/02/2001 06.11

i hope understand me...

In effect the only distinguish par is hour and minutes
 

Are the dates in a table? Can you sort them?
If so, you can get them to look like that for a start:
[tt][blue]
01/01/2001 03.10[/blue]
01/01/2001 05.11
01/01/2001 12.23[blue]
03/02/2001 06.11[/blue]
03/02/2001 12.14
[/tt]
Then you can loop down thru the dates and as soon as you pick the date, assgin it to your array, and keep going down untill you will find another date. This way you can ignore the time portion of your Date.

Have fun.

---- Andy
 
Are the records in a table ?

look @ ado.getrows() method
 
You could try this (note I have not tested this):

Code:
Dim DataList As Object
Dim Dict As Object
Dim strItem As Variant

Private Sub Command1_Click()
    ' Create a .NET Framework data list
    Set DataList = CreateObject("System.Collections.ArrayList")
    Set Dict = CreateObject("Scripting.Dictionary")
    DataList.Add "03/02/2001 12.14"
    DataList.Add "01/01/2001 12.23"
    DataList.Add "01/01/2001 05.11"
    DataList.Add "03/02/2001 06.11"
    DataList.Add "01/01/2001 03.10"
    ' Sort the data list
    DataList.Sort
    ' Loop through the data list removing date duplicates
    For Each strItem In DataList
         If Dict.Exists(Split(strItem, " ")(0)) Then
         Else
            Dict.Add Split(strItem, " ")(0), strItem
         End If
    Next
    ' Loop through the de-duped dictionary
    For Each strItem In Dict.Items
        MsgBox strItem
    Next
End Sub

Swi
 
>Are the records in a table ?


Probably not - but there's no reason why they cannot be dropped into a disconected recordset ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top