|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
VB.NET Array Keys - Help Please
Can you name array keys in VB.net (or list keys or something)?
In PHP you can say: $Array['bob'] = 'male'; $Array['sally'] = 'female'; etc... ... I need to do something similar in VB.net. Reason being that I have a long list of timestamped objects that I need to keep as a collection and refer to by timestamp - however the values aren't contiguous. Ie, they're something like: Array(615) = "Sunrise" Array(700) = "Get out of bed" Array(730) = "Have a shower" Array(745) = "Eat breakfast" Array(800) = "Go to work" ... And as I scroll through the times in another control I need to be able to pull out the corresponding timestamped object (if there is one). Thanks everybody! |
|
#2
|
|||
|
|||
|
I would create a class containing all the data you need including a the time of day etc...
Public Class Person Public Name as String Public TimeofDay As Data End Class I would then declare People as a list of persons, eg. Public People As New List(Of People) You basically Add people to your new list, eg. People.add(New Person) Once you have a new list of people, you the sort them like this, eg. People.Sort(AddressOf SortByDate) 'addressof is the procedure which compares each person autocically, eg. Public Function SortByDate(ByVal PersonA As Person, ByVal PersonB As Person) As Boolean If PersonA.Date < PersonB.Date return True If PersonA.Date > PersonB.Date return False If PersonA.Date = PersonB.Date return False 'you can add all sorts here including a select case function perhaps to deal with your strings End Function And then just populate your control with the people and each person will be ranked in order of data. I used to use Arrays, the future is Lists! ![]() |
|
#3
|
|||
|
|||
|
Another solution which isn't Object-Oriented, but is a little more similar to PHP is this:
Create a Collection Object. Collections allow you to add items with both a key and value. From there, you can lookup items based on there key using the contains function. For more information and a code example, see: vbnet.codeislogic.com/associative-arrays-in-vbnet/ (Sorry, I am a new user, so not allowed to post links. I believe this is relavent to the post, So I've added it.) |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > VB.NET Array Keys - Help Please |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|