Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| vb.net [2018/02/23 09:50] – created lenshand | vb.net [2020/09/18 13:20] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== VB.NET ====== | ====== VB.NET ====== | ||
| - | | + | [[Arrays and Select Case|Arrays and Select Case]] |
| - | < | + | |
| - | 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 | + | |
| + | Arrays allow you to store a range of items of the same datatype. an array is a variable with a single name that represents many different items. When we work with a single item, we only need to use one variable. However, if we have a list of items which are of similar type to deal with, we need to declare an array of variables for each item. | ||
| - | ' | + | An array can be one-dimensional or multidimensional. A one-dimensional array is like a list of items or a table that consists of one row of items or one column of items. |
| - | Dim strMake(12) As String | + | |
| - | strMake(0) = "Alfa Romeo" | + | |
| - | strMake(1) = "Aston Martin" | + | |
| - | strMake(2) = " | + | |
| - | strMake(3) = " | + | |
| - | strMake(4) = " | + | |
| - | strMake(5) = " | + | |
| - | strMake(6) = " | + | |
| - | strMake(7) = " | + | |
| - | strMake(8) = "Land Rover" | + | |
| - | strMake(9) = " | + | |
| - | strMake(10) = " | + | |
| - | strMake(11) = " | + | |
| - | strMake(12) = " | + | |
| - | ' | + | ^Names^ |
| - | Dim strTruck(5) As String | + | |Peter|Paul|James|Suzie| |
| - | | + | |index(0)|index(1)|index(2)|index(3)| |
| - | strTruck(1) = " | + | |
| - | strTruck(2) = " | + | |
| - | strTruck(3) = " | + | |
| - | strTruck(4) = " | + | |
| - | strTruck(5) = " | + | |
| - | 'Add the array to the comboBox | + | Declaring one dimensional Array |
| - | Select Case vehicle | + | |
| - | Case " | + | |
| - | drpModel.DataSource = strMake | + | |
| - | Case " | + | |
| - | drpModel.DataSource = strTruck | + | |
| - | Case Else | + | |
| - | End Select | + | |
| - | End Sub | + | |
| - | Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load | + | The general syntax to declare a one dimensional |
| - | ' | + | |
| - | Dim strVehicleChoice(1) As String | + | |
| - | strVehicleChoice(0) = " | + | |
| - | strVehicleChoice(1) = " | + | |
| - | 'Add the array to the comboBox | + | < |
| - | | + | Dim arrayName(subscript) as dataType |
| - | End Sub | + | </ |
| - | + | ||
| - | Private Sub drpModel_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpModel.SelectedIndexChanged | + | |
| - | ' | + | |
| - | strVehicleModel | + | ==== Week commencing 23 April 2018 ==== |
| + | {{ : | ||
| - | Select Case strVehicleModel | + | {{ : |
| - | Case "Alfa Romeo" | + | |
| - | LowPrice = 11995 | + | |
| - | highPrice = 79999 | + | |
| - | Case "Aston Martin" | ||
| - | LowPrice = 98500 | ||
| - | highPrice = 279999 | ||
| - | Case " | ||
| - | LowPrice = 169995 | ||
| - | highPrice = 229999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 279999 | ||
| - | Case " | ||
| - | LowPrice = 8995 | ||
| - | highPrice = 29999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case "Land Rover" | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | LowPrice = 11995 | ||
| - | highPrice = 79999 | ||
| - | Case " | ||
| - | 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 | ||