Solved

Help with a VB.NET Dictionnary

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
converto datetime always changes format 9 35
MediaHelp 4 21
Help with preventing downloading a zip file 10 35
vb.net 1 month apart 11 25
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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