.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 4th, 2007, 06:05 PM
mtchatchez mtchatchez is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 1 mtchatchez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 44 sec
Reputation Power: 0
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!

Reply With Quote
  #2  
Old June 10th, 2007, 03:56 PM
Matty Matty is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2007
Posts: 2 Matty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 50 sec
Reputation Power: 0
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!

Reply With Quote
  #3  
Old July 5th, 2007, 01:36 PM
bsboard bsboard is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 1 bsboard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 15 sec
Reputation Power: 0
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.)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > VB.NET Array Keys - Help Please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT