Arrays and Select Case
<code> Dim strVehicleModel As String
Dim LowPrice, highPrice As Decimal
Private Sub drpVehicle_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpVehicle.SelectedIndexChanged
Dim vehicle As String
vehicle = drpVehicle.SelectedItem
'Declare the carMake array
Dim strMake(12) As String
strMake(0) = "Alfa Romeo"
strMake(1) = "Aston Martin"
strMake(2) = "Bentley"
strMake(3) = "BMW"
strMake(4) = "Citroen"
strMake(5) = "Dacia"
strMake(6) = "Fiat"
strMake(7) = "Ford"
strMake(8) = "Land Rover"
strMake(9) = "Mercedes Benz"
strMake(10) = "Suzuki"
strMake(11) = "Tesla"
strMake(12) = "Volkswagen"
'Declare the trucks array
Dim strTruck(5) As String
strTruck(0) = "Isuzu"
strTruck(1) = "Iveco"
strTruck(2) = "Mann"
strTruck(3) = "Mercedes Benz Truck"
strTruck(4) = "Scania"
strTruck(5) = "Volvo"
'Add the array to the comboBox
Select Case vehicle
Case "Cars"
drpModel.DataSource = strMake
Case "Trucks"
drpModel.DataSource = strTruck
Case Else
End Select
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Declare the vehicle array
Dim strVehicleChoice(1) As String
strVehicleChoice(0) = "Cars"
strVehicleChoice(1) = "Trucks"
'Add the array to the comboBox
drpVehicle.DataSource = strVehicleChoice
End Sub
Private Sub drpModel_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpModel.SelectedIndexChanged
'Get the room or event and set the price and the image if available
strVehicleModel = drpModel.SelectedItem
Select Case strVehicleModel
Case "Alfa Romeo"
LowPrice = 11995
highPrice = 79999
Case "Aston Martin"
LowPrice = 98500
highPrice = 279999
Case "Bentley"
LowPrice = 169995
highPrice = 229999
Case "Volvo"
LowPrice = 11995
highPrice = 79999
Case "BMW"
LowPrice = 11995
highPrice = 279999
Case "Citroen"
LowPrice = 8995
highPrice = 29999
Case "Dacia"
LowPrice = 11995
highPrice = 79999
Case "Fiat"
LowPrice = 11995
highPrice = 79999
Case "Ford"
LowPrice = 11995
highPrice = 79999
Case "Land Rover"
LowPrice = 11995
highPrice = 79999
Case "Mercedes Benz"
LowPrice = 11995
highPrice = 79999
Case "Suzuki"
LowPrice = 11995
highPrice = 79999
Case "Tesla"
LowPrice = 11995
highPrice = 79999
Case "Volkswagen"
LowPrice = 11995
highPrice = 79999
Case "Isuzu"
LowPrice = 11995
highPrice = 79999
Case "Iveco"
LowPrice = 11995
highPrice = 79999
Case "Mann"
LowPrice = 11995
highPrice = 79999
Case "Mercedes Benz Truck"
LowPrice = 11995
highPrice = 79999
Case "Scania"
LowPrice = 11995
highPrice = 79999
Case Else
End Select
Label4.Text = "Low price is " + FormatCurrency(LowPrice.ToString)
Label5.Text = "High price is " + FormatCurrency(highPrice.ToString)
End Sub
</code