Solved

Help with a VB.NET Dictionnary

Posted on 2015-02-15
4
95 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 63

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 63

Expert Comment

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

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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