Do I need a sortedList?

nick447923

Member
Joined
Nov 10, 2009
Messages
14
Programming Experience
Beginner
I am a beginner VB programmer--I just finished the intro course!

I am writing an auto insurance application. In the application there can be up to five cars and five drivers. Each driver is assigned a driver rate (a decimal factor) and each car is assigned this factor which determines the rate for each car. The highest rated driver needs to be d1Rate and the next highest needs to be d2Rate and so on, no natter the order that each driver is keyed in.

I am trying to get away from using if a bunch of if statements to do this--I know that is not an efficient way. I am suspicious that using a sorted list in some way could solve my problem but I am unable to make it work. I thought if I could make a list of each of the driver rates I could sort by the value of each rate. I am not sure how to do this.

If the user keys in the following:

d1Rate = 1.4D
d2Rate = 1.0D
d3Rate = 3.0D
d4Rate = 1.0D
d5Rate = 2.5D

Then I would need to reassign the values in the program so that the highest rated driver would always be first:

d1Rate = 3.0D
d2Rate = 2.5D
d3Rate = 1.4D
d4Rate = 1.0D
d5Rate = 1.0D




Any suggestions would be greatly appreciated. Thanks!
 
I think I figured it out!!

Dim DriverList As New List(Of Decimal)
DriverList.Add(Dclass1factor)
DriverList.Add(Dclass2factor)
DriverList.Add(Dclass3factor)
DriverList.Add(Dclass4factor)
DriverList.Add(Dclass5factor)
DriverList.Sort()

DriverList(0) = Dclass5factor
DriverList(1) = Dclass4factor
DriverList(2) = Dclass3factor
DriverList(3) = Dclass2factor
DriverList(4) = Dclass1factor
 
Back
Top