Vbu 7
Vbu 7
Vbu 7
Arrays
Coverage:
This chapter teaches you to use arrays and structures to process data through the
use of various loop and table lookup procedures. Single and multi-dimensional
arrays are covered. For EachNext loops are used to process arrays. ListBox
controls are also used to process arrays.
INTRODUCTION
In this chapter you will develop a project for the VB University Bookstore that
enables students to find information about products that are for sale in the bookstore.
The initial appearance of the form for the project is shown below.
You will create three versions of this form while studying the concepts taught in this
module.
The menu strip control has the following menu items with hot keys and shortcut keys
indicated.
File
Total Sales by Product
Exit
Ctrl-X
Product
Search
Ctrl-S
Purchase Ctrl-U
------------------------Reset
Ctrl-R
Help
About
Single-Dimension Arrays
An Array is a list of values all values in an array are referenced by using the
same name.
An array is like a ListBox without the box where the list of values are all stored
in memory.
Arrays are also called tables.
Arrays are based on the System.Array object a type of collection object.
Arrays can store almost any type of data such as integer, string, decimal, etc.
Element this is the term used to refer to an individual part of an array.
Each element is numbered beginning with the number zero. Example, 0, 1,
2, 3, etc.
The number referring to an array element is placed inside parentheses and is
called a subscript or index. This is the general format for an array reference.
ArrayName(ElementNumber)
Declaring an Array
Arrays are created in memory by declaring them as you would a variable.
Generally you declare local arrays with the keyword Dim and module-level
arrays with the keyword Private in order to specify the array scope.
The number inside parentheses that specifies the number of elements should
be an integer if a floating point number is used, VB will round the number to
an integer value automatically.
Numeric array elements default to a value of zero; string array elements
default to a value of the empty string.
There are several different correct syntax variations for declaring arrays. The
general formats are:
Dim ArrayName(UpperSubscript) As DataType
Example declarations:
'A String array with 26 elements numbered 0 through 25
Dim NameString(25) As String
'A decimal array of 11 elements numbered 0 through 10
Private BalanceDecimal(10) As Decimal
This example declares a module-level array and stores values to the array
immediately. When storing values immediately to the array, you cannot
specify the number of elements within the parenthesesVB will determine the
number of elements automatically.
'A private string array with 6 elements numbered 0
through 5
Private SchoolString() As String = {"Arts and Sciences",
_
"Business", "Nursing", "Engineering", _
"Education", "Pharmacy"}
Element Number
0
1
2
3
4
5
School Name
Arts and Sciences
Business
Nursing
Engineering
Education
Pharmacy
Arrays are often processed in loops. The power of arrays comes with using a
variable as the subscript.
A For...Next loop can process an entire array with a few lines of code as
shown here, but the code requires you to manipulate the array index.
This example writes the array contents to the Output window, one school
name per line:
For RowInteger = 0 To NumberOfSchoolsInteger
Debug.WriteLine(SchoolString(RowInteger))
Next RowInteger
Another type of count-controlled loop is the For Each...Next loop the advantage of
this coding construct is that you don't have to manipulate the index.
The loop code shown here is equivalent to the one shown above.
For Each SchoolNameString As String In SchoolString
Debug.WriteLine(SchoolNameString )
Next SchoolNameString
Learn these rules about For Each...Next loops:
The index data type must match the array data type, i.e., for a string array
the index should be a string index, for an integer array the index should be an
integer, etc.
This above example declares SchoolNameString as a string variable index
and then immediately uses it to search the SchoolString array.
An array can be used to accumulate values where you would otherwise need to
declare many accumulating variables. Sometimes a numeric accumulating array
needs to be re-initialized to zero. This loop sets all elements of an integer array
named TotalInteger to zero. Remember a numeric array starts out with each
element equal to zero, but if the array is used over and over within a program, it may
need to be reinitialized.
For Each IndividualElementInteger As Integer In TotalInteger
IndividualElementInteger = 0
Next IndividualElementInteger
Structures
A structure object allows you to combine fields of related data into a single object
you can combine data of type integer, decimal, string, color, radio button, and other
data types. This allows you to create your own, unique data types.
Structures are public by default, but you can also declare private structures.
This example defines a Product structure that might be used to track
products sold by retail stores.
Each product has a product identifier, product description, quantity on hand,
and price. The ProductIDString, DescriptionString, QuantityInteger, and
PriceDecimal variables become properties of the Product data type.
Structure Product
Dim ProductIDString As String
Dim DescriptionString As String
Dim QuantityInteger As Integer
Dim PriceDecimal As Decimal
End Structure
Declare variables and arrays as a structure data type just as you would any
other data type.
Dim TextBookProduct As Product
Dim InventoryProduct(450000) As Product
InventoryProduct(0).ProductIDString = "A402"
InventoryProduct(0).DescriptionString = "History of
America Textbook"
InventoryProduct(0).QuantityInteger = 10
InventoryProduct(0).PriceDecimal = 65.55D
InventoryProduct(1).ProductIDString = "A804"
InventoryProduct(1).DescriptionString = "College Logo
Tshirt"
InventoryProduct(1).QuantityInteger = 15
InventoryProduct(1).PriceDecimal = 18.99D
This example defines a Sale structure with three properties the SaleDecimal
property is an array.
'Module-level declaration
Structure Sale
Dim SaleIDString As String
Dim SaleDate As Date
Dim SaleDecimal() As Decimal
End Structure
Table Lookup
Table Lookup a programming technique to search an array (table).
Objective: find a key value in order to use some other non-key value that is
associated with the key for some type of processing.
Analogous Example: Consider how you look up information in a telephone book.
The telephone book is actually a very large table with the Name, Address, and
Telephone Number columns.
The key value in the telephone book is the Name.
The value you actually want to use is the Telephone Number.
Consider the array shown below with four columns: (1) ProductIDString stores each
product's identifier, (2) DescriptionString stores each items corresponding
description, (3) QuantityInteger stores the quantity on hand for each product, and
(4) PriceDecimal stores the price of the item
Tasks:
Declare a Product structure.
Declare an array of type Product and store data to the array.
Write a search proceduresearch for a product ID value in order to display
the corresponding description, quantity, and price.
QuantityIntege
r
PriceDecimal
History of America
Textbook
10
65.55
15
18.99
ProductIDString
DescriptionString
A402
A804
C344
25
25.99
F554
Drinking Mug
5.49
G302
15
35.50
M302
25
22.99
S499
Intro to Philosophy
Textbook
50
85.00
X599
75
79.40
Load Event
A form's Load event can be used to perform initialization tasks that you need to
complete whenever a form loads from disk into memory. Example tasks include
connecting to a database or storing initial values to an array. The Load event fires
whenever the form loads the first time.
Task 2: Create a Load event for the form as shown below.
Load initial values into the array elements by coding the form's Load
procedure event. When you study Chapter 10, you will learn how to access
Product data values from a database table.
Private Sub BookStore1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
InventoryProduct(0).ProductIDString = "A402"
InventoryProduct(0).DescriptionString = "History of
America Textbook"
InventoryProduct(0).QuantityInteger = 10
InventoryProduct(0).PriceDecimal = 65.55D
InventoryProduct(1).ProductIDString = "A804"
InventoryProduct(1).DescriptionString = "College Logo
Tshirt"
InventoryProduct(1).QuantityInteger = 15
InventoryProduct(1).PriceDecimal = 18.99D
InventoryProduct(2).ProductIDString = "C344"
InventoryProduct(2).DescriptionString = "College Logo
Sweat Pants"
InventoryProduct(2).QuantityInteger = 25
InventoryProduct(2).PriceDecimal = 25.99D
InventoryProduct(3).ProductIDString = "F554"
InventoryProduct(3).DescriptionString = "Drinking Mug"
InventoryProduct(3).QuantityInteger = 8
InventoryProduct(3).PriceDecimal = 5.49D
InventoryProduct(4).ProductIDString = "G302"
InventoryProduct(4).DescriptionString = "Pencil and
Pen Set"
InventoryProduct(4).QuantityInteger = 15
InventoryProduct(4).PriceDecimal = 35.5D
InventoryProduct(5).ProductIDString = "M302"
InventoryProduct(5).DescriptionString = "College Logo
Sweat Shirt"
InventoryProduct(5).QuantityInteger = 25
InventoryProduct(5).PriceDecimal = 22.99D
InventoryProduct(6).ProductIDString = "S499"
InventoryProduct(6).DescriptionString = "Intro to
Philosophy Textbook"
InventoryProduct(6).QuantityInteger = 50
InventoryProduct(6).PriceDecimal = 85D
InventoryProduct(7).ProductIDString = "X599"
InventoryProduct(7).DescriptionString = "Intro to CMIS
Textbook"
InventoryProduct(7).QuantityInteger = 75
InventoryProduct(7).PriceDecimal = 79.4D
End Sub
QuantityTextBox.Text =
InventoryProduct(RowInteger).QuantityInteger.ToString
PriceTextBox.Text =
InventoryProduct(RowInteger).PriceDecimal.ToString("C2")
'change variable to indicate we have a match
FoundBoolean = True
Else
'no match yet
RowInteger += 1
End If
Loop
'After the search determine if the ProductID was found
If FoundBoolean = False Then 'no match was found
'Clear the textbox controls that display product
information
'except for the ProductID textbox
DescriptionTextBox.Clear()
QuantityTextBox.Clear()
PriceTextBox.Clear()
'Display message that the ProductID is not valid
MessageBox.Show("Reenter a valid product ID.",
"Invalid Identifier", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
End If
End Sub
Test the program.
Enter a valid product ID and confirm the correct description, quantity on hand
and price values display.
Enter an invalid product ID and confirm the Invalid Product ID message box
displays, the text boxes for description, quantity on hand, and price are
cleared, and the product ID text box value is selected and highlighted.
Purchasing a Product
Values from arrays can be displayed to ListBox controls as part of on-line order
processing.
In the Bookstore application, application users will first search for a product of
interest, then click the Product-Purchase menu item.
Display the product purchased to the PurchaseListBox.
Default to the purchase of a quantity of one of the products.
Accumulate the total value of the order and display this value to the
TotalDueTextBox control.
Task 4: Add a module-level variable to store the total due for an individual
bookstore customer (highlighted in yellow).
'Module-level variables/constants/arrays
Private NumberProductsInteger As Integer = 7
Private InventoryProduct(NumberProductsInteger) As Product
Private TotalDueDecimal As Decimal 'total due for a
customer
Task 5: Code the Click event procedure for the Product-Purchase menu item.
o The If statement tests for the DescriptionTextBox equal to the empty
string this means a valid bookstore product was NOT found by a
search.
o When a match has been found, the information to be stored to the
ListBox is stored to the ProductString variable.
o The TotalDueDecimal variable accumulates the value currently
displayed in the PriceTextBox control use of the Decimal.Parse
Globalization.NumberStyles.Currency enumerated value to convert
a formatted product price back to decimal for addition to
TotalDueDecimal.
o The TotalDueTextBox control displayed the updated value of the total
amount due.
o The form can be cleared to prepare for the next item to be purchased.
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If DescriptionTextBox.Text = String.Empty Then
'Cannot purchase, product was not found
MessageBox.Show("You must select a valid product
before purchasing.", "Cannot Purchase", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
Else
'Can purchase the product
'Build a string to display in the listbox control
Dim ProductString As String =
ProductIDTextBox.Text & " - " & DescriptionTextBox.Text & " " & PriceTextBox.Text
PurchaseListBox.Items.Add(ProductString)
'Accumulate the total value of this customer order
'and display it to the output textbox
TotalDueDecimal +=
Decimal.Parse(PriceTextBox.Text,
Globalization.NumberStyles.Currency)
TotalDueTextBox.Text =
TotalDueDecimal.ToString("C2")
'Here you can clear the form of product info if
you think
'that is a good way to do the processing
ProductIDTextBox.Clear()
DescriptionTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Clear()
ProductIDTextBox.Focus()
End If
End Sub
Test the project to determine:
If the item purchased displays in the ListBox control.
The total due value accumulates and displays correctly.
The remaining menus for the project are coded when you develop Version 2 of the
project.
Redesign Interface
Task 2: Redesign the interface.
'ProductIDTextBox.SelectAll()
Else
'Can purchase the product
'Build a string to display in the listbox control
Dim ProductString As String =
ProductIDComboBox.Text & " - " & DescriptionTextBox.Text & " " & PriceTextBox.Text
PurchaseListBox.Items.Add(ProductString)
'Accumulate the total value of this customer order
'and display it to the output textbox
TotalDueDecimal +=
Decimal.Parse(PriceTextBox.Text,
Globalization.NumberStyles.Currency)
TotalDueTextBox.Text =
TotalDueDecimal.ToString("C2")
'Here you can clear the form of product info if
you think
'that is a good way to do the processing
ProductIDComboBox.Text = String.Empty
DescriptionTextBox.Clear()
PriceTextBox.Clear()
QuantityTextBox.Clear()
ProductIDComboBox.Focus()
End If
End Sub
Test the system as before. Ensure that the total due for the purchase of bookstore
products accumulates properly. The figure shown below illustrates execution of the
revised application.
Task 7 Add code to the Product-Purchase menu item Click event sub procedure.
Task 8: Code the FileTotal Sales by Product menu Click event sub procedure.
Display the total sales by product to the Visual Basic immediate output
window as a simple means of producing a report.
Private Sub
TotalSalesByProductToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TotalSalesByProductToolStripMenuItem.Click
'Display output to immediate window
Dim RowInteger As Integer
For RowInteger = 0 To NumberProductsInteger
'Build string to display
Dim SalesString As String = "Product ID: " &
InventoryProduct(RowInteger).ProductIDString & "
Dollar
Sales: " & ProductSalesTotalDecimal(RowInteger).ToString("C2")
'Display string to immediate window
Debug.WriteLine(SalesString)
Next
End Sub
Test the project:
Add several products and ensure the total for an individual is correct.
Display output to the Immediate window to check that the accumulated total
sales by product is correct for each product.
Multidimensional Arrays
A multidimensional array has more than one dimension we will work with arrays
that have both rows and columns to produce a two-dimensional table.
An example of an application that uses a two-dimensional table is the use of tax
tables for computing personal income taxes to be paid to the U.S. government.
This declaration statement allocates memory for TaxTableDecimal as a modulelevel array assuming there are 150 different income level brackets:
Private TaxTableDecimal(150,3) As Decimal
One limitation of the two-dimensional table is that you can only store one type of
data in the array you can work around this to a certain extent by storing data as
String that would otherwise be numeric and using Convert methods to convert data
from string to Decimal or Integer or another numeric data type to support processing.
The StatesString table is declared as a two-dimensional table and filled with state
names as follows:
Dim StatesString(,) As String = { _
{"Alaska", "Indiana", "R. Island"}, _
{"Texas", "Maryland", "Delaware"}, _
{"California", "Idaho", "Vermont"}, _
{"Florida", "Iowa", "Hawaii"}}
Note the use of braces, commas, and line-continuation characters.
The first left brace marks the beginning of the table.
The next left brace marks the beginning of the first row of data.
Each element is stored as string within double-quote marks.
The first right brace marks the end of the first row of data.
The last right brace marks the end of the table.
Each element within a row is separated by a comma.
Each row is separated by a comma from the next row.
The line-continuation characters make it easier to read the table as each row
is on a single line. The table data could be typed as one continuous line of
code, but it would be very difficult and messy to read.
If the value RowInteger = 2 and ColumnInteger = 1, the state "Idaho" is displayed
to the text box named StateTextBox.
StateTextBox.Text = StatesString(RowInteger,
ColumnInteger)
This sub procedure illustrates printing the StatesString table to the immediate
output window for purposes to debugging code with nested For...Next loops. Each
state will display on a single line.
Private Sub StatesButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles statesButton.Click
Dim StatesString(,) As String = { _
With this approach, the application system user enters a value in a TextBox,
then a code search procedure searches a specific column in an array to try to
find the value that was typed into the TextBox. If the search succeeds, the
code returns a value from a different column of the same array or from column
in a different array.
The number of ways that arrays are used is practically limitless, and your ability to
manipulate them will improve with practice over time.
Redesign Interface
Task 2: Redesign the application interface.
Delete the declarations of the Product structure and InventoryProduct array.
Delete the Load event.
'Module-level declarations
Private NumberProductsInteger As Integer = 7 'number of
products
Private TotalDueDecimal As Decimal 'total due for a customer
'Array to store the total sales for each product
Private ProductSalesTotalDecimal(NumberProductsInteger) As
Decimal
'Module-level variable to store row and column values
Private RowInteger, ColumnInteger As Integer
'Declare two-dimensional inventory array
Private InventoryString(,) As String = { _
{"A402", "History of America Textbook", "2", "$65.55"}, _
{"A804", "College Logo Tshirt", "15", "$18.99"}, _
{"C344", "College Logo Sweat Pants", "25", "$25.99"}, _
{"F554", "Drinking Mug", "8", "$5.49"}, _
{"G302", "Pencil and Pen Set", "15", "$35.50"}, _
{"M302", "College Logo Sweat Shirt", "25", "$22.99"}, _
{"S499", "Intro to Philosophy Textbook", "50", "$85.00"},
_
Loop
'After the search determine if the ProductID was found
If FoundBoolean = False Then 'no match was found
'Clear the textbox controls that display product
information
'except for the ProductIDTextBox
DescriptionTextBox.Clear()
QuantityTextBox.Clear()
PriceTextBox.Clear()
'Display message that the ProductID is not valid
MessageBox.Show("Reenter a valid product ID.",
"Invalid Identifier", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
Else
If Convert.ToInt32(QuantityTextBox.Text) = 0 Then
PurchaseToolStripMenuItem.Enabled = False
Else
PurchaseToolStripMenuItem.Enabled = True
End If
End If
End Sub
Task 5: Modify the Product-Purchase menu item's Click event sub procedure.
The procedure must accumulate the total sales by referencing the RowInteger
variable that stores the current row from the search procedure. Modifications are
highlighted in yellow.
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If DescriptionTextBox.Text = String.Empty Then
'Cannot purchase, product was not found
MessageBox.Show("You must select a valid product
before purchasing.", "Cannot Purchase", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
Else
'Can purchase the product
'Build a string to display in the ListBox control
Dim ProductString As String =
ProductIDTextBox.Text & " - " & DescriptionTextBox.Text & " " & PriceTextBox.Text
PurchaseListBox.Items.Add(ProductString)
The product ID value is now referenced from the InventoryString twodimensional array by using RowInteger to be the row subscript and zero (0)
to be the column subscript. Modifications are highlighted in yellow.
Private Sub
TotalSalesByProductToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TotalSalesByProductToolStripMenuItem.Click
'Use For Next loop to process array and structure
Dim RowInteger As Integer
For RowInteger = 0 To NumberProductsInteger
'Store values to string variable to be added
'to the ListBox control
Dim SalesString As String = "Product ID: " &
InventoryString(RowInteger, 0) & "
Dollar Sales: " &
ProductSalesTotalDecimal(RowInteger).ToString("C")
'Display report to the Immediate Window
Debug.WriteLine(SalesString)
Next
End Sub
InventoryProduct(4).ProductIDString = "G302"
InventoryProduct(4).DescriptionString = "Pencil and
Pen Set"
InventoryProduct(4).QuantityInteger = 15
InventoryProduct(4).PriceDecimal = 35.5D
InventoryProduct(5).ProductIDString = "M302"
InventoryProduct(5).DescriptionString = "College Logo
Sweat Shirt"
InventoryProduct(5).QuantityInteger = 25
InventoryProduct(5).PriceDecimal = 22.99D
InventoryProduct(6).ProductIDString = "S499"
InventoryProduct(6).DescriptionString = "Intro to
Philosophy Textbook"
InventoryProduct(6).QuantityInteger = 50
InventoryProduct(6).PriceDecimal = 85D
InventoryProduct(7).ProductIDString = "X599"
InventoryProduct(7).DescriptionString = "Intro to CMIS
Textbook"
InventoryProduct(7).QuantityInteger = 75
InventoryProduct(7).PriceDecimal = 79.4D
End Sub
Private Sub SearchButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SearchButton.Click
'Search the ProductIDString property of the
inventoryProduct
'array to see if the value of ProductIDTextBox matches
an ID
'in the array
'Start variables to control the search
Dim FoundBoolean As Boolean = False 'Control how long
to search
Dim RowInteger As Integer = 0
'Current row in
the search
'Loop to do the search
Do Until FoundBoolean = True Or RowInteger >
NumberProductsInteger
'Compare textBox to array
If ProductIDTextBox.Text =
InventoryProduct(RowInteger).ProductIDString Then
'found a match - display other data to the
readonly textboxes
DescriptionTextBox.Text =
InventoryProduct(RowInteger).DescriptionString
QuantityTextBox.Text =
InventoryProduct(RowInteger).QuantityInteger.ToString
PriceTextBox.Text =
InventoryProduct(RowInteger).PriceDecimal.ToString("C2")
'change variable to indicate we have a match
FoundBoolean = True
Else
'no match yet
RowInteger += 1
End If
Loop
'After the search determine if the ProductID was found
If FoundBoolean = False Then 'no match was found
'Clear the textbox controls that display product
information
'except for the ProductID textbox
DescriptionTextBox.Clear()
QuantityTextBox.Clear()
PriceTextBox.Clear()
'Display message that the ProductID is not valid
MessageBox.Show("Reenter a valid product ID.",
"Invalid Identifier", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
End If
End Sub
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If DescriptionTextBox.Text = String.Empty Then
'Cannot purchase, product was not found
MessageBox.Show("You must select a valid product
before purchasing.", "Cannot Purchase", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
ProductIDTextBox.Focus()
ProductIDTextBox.SelectAll()
Else
'Can purchase the product
'Build a string to display in the listbox control
Dim ProductString As String =
ProductIDTextBox.Text & " - " & DescriptionTextBox.Text & " " & PriceTextBox.Text
PurchaseListBox.Items.Add(ProductString)
'Accumulate the total value of this customer order
InventoryProduct(0).PriceDecimal = 65.55D
InventoryProduct(1).ProductIDString = "A804"
InventoryProduct(1).DescriptionString = "College Logo
Tshirt"
InventoryProduct(1).QuantityInteger = 15
InventoryProduct(1).PriceDecimal = 18.99D
InventoryProduct(2).ProductIDString = "C344"
InventoryProduct(2).DescriptionString = "College Logo
Sweat Pants"
InventoryProduct(2).QuantityInteger = 25
InventoryProduct(2).PriceDecimal = 25.99D
InventoryProduct(3).ProductIDString = "F554"
InventoryProduct(3).DescriptionString = "Drinking Mug"
InventoryProduct(3).QuantityInteger = 8
InventoryProduct(3).PriceDecimal = 5.49D
InventoryProduct(4).ProductIDString = "G302"
InventoryProduct(4).DescriptionString = "Pencil and
Pen Set"
InventoryProduct(4).QuantityInteger = 15
InventoryProduct(4).PriceDecimal = 35.5D
InventoryProduct(5).ProductIDString = "M302"
InventoryProduct(5).DescriptionString = "College Logo
Sweat Shirt"
InventoryProduct(5).QuantityInteger = 25
InventoryProduct(5).PriceDecimal = 22.99D
InventoryProduct(6).ProductIDString = "S499"
InventoryProduct(6).DescriptionString = "Intro to
Philosophy Textbook"
InventoryProduct(6).QuantityInteger = 50
InventoryProduct(6).PriceDecimal = 85D
InventoryProduct(7).ProductIDString = "X599"
InventoryProduct(7).DescriptionString = "Intro to CMIS
Textbook"
InventoryProduct(7).QuantityInteger = 75
InventoryProduct(7).PriceDecimal = 79.4D
End Sub
Private Sub PurchaseToolStripMenuItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
PurchaseToolStripMenuItem.Click
'Test to determine if a product was found.
If DescriptionTextBox.Text = String.Empty Then
'Cannot purchase, product was not found