Solved

Help with a VB.NET Dictionnary

Posted on 2015-02-15
4
86 Views
Last Modified: 2015-02-17
Hello EE,

I got a dictionnary(Of Integer, Class1)
the class1 is made of a date and a number.

Lets say my dictionar is as follow :

0 - 2015/2/13, 5
1 - 2015/2/13, 11
2 - 2015/2/13, 30
3 - 2015/2/14, 1
4 - 2015/2/14, 11
5 - 2015/2/14, 44
6 - 2015/2/15, 30


what I would like to accomplish.. is to calculate for each number, what is the number of days that it was not taken.
For example, the number 30 would be 0 because i got that number today. But the number 5 would be 2
for the number 44 it would be 1.

any help?
Thanks!
0
Comment
Question by:PhilippeRenaud
  • 2
4 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40611552
I am not getting the question. Could you please rephrase your question.

If you are looking for the number of days each number was not used then from your example above the number 30 was only only used one day of three and so would return 2. Not sure how it could return 0. If I am on the right track then we would also need to number range being used so we can check for numbers that have not been used at all.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40611608
Hi PhilippeRenaud;

Assuming I made the right assumptions the snippet below should give you what you need.

Dim myList As New Dictionary(Of Integer, Class1)()

' Test data
myList.Add(0, New Class1() With {.MyDate = New DateTime(2015, 2, 13, 0, 0, 0), .MyNum = 5} )
myList.Add(1, New Class1() With {.MyDate = New DateTime(2015, 2, 13, 0, 0, 0), .MyNum = 11} )
myList.Add(2, New Class1() With {.MyDate = New DateTime(2015, 2, 13, 0, 0, 0), .MyNum = 30} )
myList.Add(3, New Class1() With {.MyDate = New DateTime(2015, 2, 14, 0, 0, 0), .MyNum = 1} )
myList.Add(4, New Class1() With {.MyDate = New DateTime(2015, 2, 14, 0, 0, 0), .MyNum = 11} )
myList.Add(5, New Class1() With {.MyDate = New DateTime(2015, 2, 14, 0, 0, 0), .MyNum = 44} )
myList.Add(6, New Class1() With {.MyDate = New DateTime(2015, 2, 15, 0, 0, 0), .MyNum = 30} )

' Calculate the number of days
For Each obj In myList.Values
    Dim days As Timespan = DateTime.Today.Subtract(obj.MyDate)
    Console.WriteLine("Number of Days = {0} Number = {1}", days.TotalDays, obj.MyNum)
Next


' Assuming you class looks like this
Public Class Class1
    Public Property MyDate As DateTime
    Public Property MyNum As Integer
End Class

Open in new window

0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 40614392
thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40614446
Not a problem Philippe, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now