Solved

Help with a VB.NET Dictionnary

Posted on 2015-02-15
4
100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

734 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