Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SortedList Class

Status
Not open for further replies.

sburden

Programmer
Dec 4, 2002
35
US
Hello,

I'm a newbie to VB .NET and I'm trying to code a SortedList class. The Add method is giving me difficulty. I understand that it's looking for two arguments: the key and the value associated with that key. However, my key consists of two fields (First Name and Last Name). How do I construct the statement to reflect that?

Thanks in advance for your help.
Stevie
 
Concatenate the fields with each field padded to the maximum size that field can be. Assumiong that Last Name is the major field and each field is a maximum of 40 characters then

Dim sKey = LastName.PadRight(40) & Firstname.PadRight(40)

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Another way would be to use the GetHashCode function:
Code:
Dim MyHash As Integer
MyHash = LastName.GetHashCode Xor FirstName.GetHashCode
This would produce a unique value for each uniqe LastName & FirstName pair. If you had two records with the same name, they would hash to the same value.

GetHashCode is inherited from Object, which all classes ultimately inherit from.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top