title: How to compute quantity times price textbox to listbox
body: <p>I have the following code. I have a quantity textbox and price textbox. I need to multiple the price by the quatity to display total in a listbox of a particular item. the listbox gets totaled at the end. This worked as a static array just fine but I had to allow for user input of different price and quantity. I provided code in the middle that I thought might work but doesn't. What am I ding wrong?  ''''''''''''PriceTextBox.Text = PriceTextBox * QuantityTextBox.Text'''''''''''''</p>
  
  <pre><code> Public Class form1
  
  'Module level declarations
  Structure Product
      Dim ProductIDString As String
      Dim DescriptionString As String
      Dim QuantityInteger As Integer
      Dim PriceDecimal As Decimal
      Dim W As IO.StreamWriter
  End Structure
  
  Private NumberProductsInteger As Integer = 38
  Private InventoryProduct(NumberProductsInteger) As Product
  Private TotalDueDecimal As Decimal 'total due for a customer
  
  'Array to store the total sales for each product
  Private ProductSalesTotalDecimal(NumberProductsInteger) As Decimal
  
  
  
  
  Private Sub Button3_Click(sender As Object, e As EventArgs) Handles PurchaseBtn.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 &amp; "  " &amp; DescriptionTextBox.Text &amp; "    " &amp; QuantityTextBox.Text &amp; "                " &amp; PriceTextBox.Text
          PurchaseListBox.Items.Add(ProductString)
  
          'Accumulate the total value of this customer order
          'and display it to the output textbox
  
  
          ''''''''''''PriceTextBox.Text = PriceTextBox * QuantityTextBox.Text'''''''''''''
  
  
  
          TotalDueDecimal += Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
          TotalDueTextBox.Text = TotalDueDecimal.ToString("C2")
  
          'Accumulate total sales by product to an array
          Dim IndexInteger As Integer = ProductIDComboBox.SelectedIndex
          ProductSalesTotalDecimal(IndexInteger) += Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
  
          'Here you can clear the form of product info if you think
          'that is a good way to do the processing
          ProductIDComboBox.SelectedIndex = -1
          ProductIDTextBox.Clear()
          DescriptionTextBox.Clear()
          PriceTextBox.Clear()
          QuantityTextBox.Clear()
          ProductIDTextBox.Focus()
      End If
  End Sub
  </code></pre>
  
  <p>As you can see the total due adds up the prices but doesn't add in the quantity factor</p>
  
  <p><img src="https://i.stack.imgur.com/utZJ4.png" alt="enter image description here"></p>
  
  <p>Public Class form1
      Structure Product</p>
  
  <pre><code>    'Module level declarations
      Dim ProductIDString As String
      Dim DescriptionString As String
      Dim QuantityInteger As Integer
      Dim PriceDecimal As Double
      Dim Cost As Double
      Dim W As IO.StreamWriter
  
  
      Public Sub New(PID As String, Desc As String, Qty As Integer, Price As Double)
          ProductIDString = PID
          DescriptionString = Desc
          QuantityInteger = Qty
          PriceDecimal = Price
          Cost = Qty * Price
      End Sub
  
  
  
  
  
      Public Overrides Function ToString() As String
          Return ProductIDString &amp; " " &amp; DescriptionString &amp; " " &amp; QuantityInteger.ToString &amp; " " &amp; PriceDecimal.ToString("C2") &amp; " " &amp; Cost.ToString("C2")
      End Function
  End Structure
  
  
  Dim Products As New List(Of Product)
  
  'Products..AddRange(
  ' New Product("test1", "Test1a", 10, 1.5),
  '  NewProduct("test2", "test2a", 20, 2.25)
  
  
  
  
  ' PurchaseListBox.DataSource = Products
  ' TotalDueTextBox.Text = Products.Sum(Function(x) x.Cost).ToString("C2")
  
  Public Sub UpdateLB()
      PurchaseListBox.DataSource = Nothing
      PurchaseListBox.DataSource = Products
      TotalDueTextBox.Text = Products.Sum(Function(x) x.Cost).ToString("C2")
  End Sub
  
  Private NumberProductsInteger As Integer = 38
  Private InventoryProduct(NumberProductsInteger) As Product
  Private TotalDueDecimal As Decimal 'total due for a customer
  Private Property W As IO.StreamWriter
  Private ProductSalesTotalDecimal(NumberProductsInteger) As Decimal  'Array to store the total sales for each product
  
  Private Sub BookStore1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Me.TimeDateLBL.Text = CStr(Date.Now)
  
      'Initialize values - InventoryProduct array
      InventoryProduct(0).ProductIDString = "102-1091" &amp; vbTab
      InventoryProduct(0).DescriptionString = "2x4-92 &amp; Chr(96)  5/8  SPF  STUD" &amp; vbTab &amp; vbTab
      'InventoryProduct(0).QuantityInteger = 
      ' InventoryProduct(0).PriceDecimal = 65.55D
  
      InventoryProduct(1).ProductIDString = "102-1127" &amp; vbTab
      InventoryProduct(1).DescriptionString = "2x4-12'  #2 &amp;BTR  SPF  CONSTR  LUMB" &amp; Space(33)
      'InventoryProduct(1).QuantityInteger = 15
      'InventoryProduct(1).PriceDecimal = 18.99D
  
      InventoryProduct(2).ProductIDString = "102-1130" &amp; vbTab
      InventoryProduct(2).DescriptionString = "2x4-14'  #2&amp;BTR  SPF  CONSTR LUMB" &amp; Space(35)
      ' InventoryProduct(2).QuantityInteger = 25
      ' InventoryProduct(2).PriceDecimal = 25.99D
  
      InventoryProduct(3).ProductIDString = "102-1143" &amp; vbTab
      InventoryProduct(3).DescriptionString = "2x4-16'  5/8  #2&amp;BTR  SPF  CONSTR LUMB" &amp; Space(27)
      ' InventoryProduct(3).QuantityInteger = 8
      'InventoryProduct(3).PriceDecimal = 5.49D
  
      InventoryProduct(4).ProductIDString = "102-1305" &amp; vbTab
      InventoryProduct(4).DescriptionString = "2x4-104  5/8  SPF  STUD" &amp; Space(64)
      ' InventoryProduct(4).QuantityInteger = 15
      ' InventoryProduct(4).PriceDecimal = 35.5D
  
      InventoryProduct(5).ProductIDString = "102-1758" &amp; vbTab
      InventoryProduct(5).DescriptionString = "2x6-8'  STD/#2&amp;BTR  SPF  CONSTR LUMB" &amp; Space(33)
      ' InventoryProduct(5).QuantityInteger = 25
      ' InventoryProduct(5).PriceDecimal = 22.99D
  
      InventoryProduct(6).ProductIDString = "102-1774" &amp; vbTab
      InventoryProduct(6).DescriptionString = "2x6-12' #2&amp;BTR  SPF  CONSTR LUMB" &amp; Space(33)
      ' InventoryProduct(6).QuantityInteger = 50
      ' InventoryProduct(6).PriceDecimal = 85D
  
      InventoryProduct(7).ProductIDString = "102-1923" &amp; vbTab
      InventoryProduct(7).DescriptionString = "2x8-16' #2&amp;BTR  SPF  CONSTR LUMB"
      ' InventoryProduct(7).QuantityInteger = 75
      ' InventoryProduct(7).PriceDecimal = 79.4D
  
      InventoryProduct(8).ProductIDString = "102-2184" &amp; vbTab
      InventoryProduct(8).DescriptionString = "2x12-16'  #2&amp;BTR  SPF  CONSTR LUMB  "
      ' InventoryProduct(8).QuantityInteger = 75
      'InventoryProduct(8).PriceDecimal = 79.4D
  
      InventoryProduct(9).ProductIDString = "106-1501" &amp; vbTab
      InventoryProduct(9).DescriptionString = "1-3/4x11-7/8  10'  LVL"
      'InventoryProduct(9).QuantityInteger = 75
      ' InventoryProduct(9).PriceDecimal = 79.4D
  
      InventoryProduct(10).ProductIDString = "106-2089" &amp; vbTab
      InventoryProduct(10).DescriptionString = "1-3/4x11-7/8  10'  LVL"
      ' InventoryProduct(10).QuantityInteger = 75
      ' InventoryProduct(10).PriceDecimal = 79.4D
  
      InventoryProduct(11).ProductIDString = "106-2115" &amp; vbTab
      InventoryProduct(11).DescriptionString = "1-3/4x14  14'  LVL"
      ' InventoryProduct(11).QuantityInteger = 75
      ' InventoryProduct(11).PriceDecimal = 79.4D
  
      InventoryProduct(12).ProductIDString = "106-2144" &amp; vbTab
      InventoryProduct(12).DescriptionString = "1-3/4x14  18'  LVL"
      ' InventoryProduct(12).QuantityInteger = 75
      ' InventoryProduct(12).PriceDecimal = 79.4D
  
      InventoryProduct(13).ProductIDString = "106-2209" &amp; vbTab
      InventoryProduct(13).DescriptionString = "1-3/4x14  26'  20'  LVL"
      ' InventoryProduct(13).QuantityInteger = 75
      ' InventoryProduct(13).PriceDecimal = 79.4D
  
      InventoryProduct(14).ProductIDString = "106-6742" &amp; vbTab
      InventoryProduct(14).DescriptionString = "2-1/2X14-18' I Joist  NI-60/PRi-60"
      ' InventoryProduct(14).QuantityInteger = 75
      ' InventoryProduct(14).PriceDecimal = 79.4D
  
      InventoryProduct(15).ProductIDString = "106-6768" &amp; vbTab
      InventoryProduct(15).DescriptionString = "2-1/2X14-18' I Joist  NI-60/PRi-60"
      ' InventoryProduct(15).QuantityInteger = 75
      'InventoryProduct(15).PriceDecimal = 79.4D
  
      InventoryProduct(16).ProductIDString = "106-6807" &amp; vbTab
      InventoryProduct(16).DescriptionString = "2-1/2X14-24' I Joist  NI-60/PRi-60"
      ' InventoryProduct(16).QuantityInteger = 75
      ' InventoryProduct(16).PriceDecimal = 79.4D
  
      InventoryProduct(17).ProductIDString = "106-8106" &amp; vbTab
      InventoryProduct(17).DescriptionString = "2-1/2X14-12' I Joist  RIM BOARD"
      ' InventoryProduct(17).QuantityInteger = 75
      'InventoryProduct(17).PriceDecimal = 79.4D
  
      InventoryProduct(18).ProductIDString = "111-0834" &amp; vbTab
      InventoryProduct(18).DescriptionString = "2x4-12'  AC2 TREATED  AG LIFETIME WTY"
      ' InventoryProduct(18).QuantityInteger = 75
      ' InventoryProduct(18).PriceDecimal = 79.4D
  
      InventoryProduct(19).ProductIDString = "111-0847" &amp; vbTab
      InventoryProduct(19).DescriptionString = "2x4-14'  AC2 TREATED  AG LIFETIME WTY"""
      ' InventoryProduct(19).QuantityInteger = 75
      ' InventoryProduct(19).PriceDecimal = 79.4D
  
      InventoryProduct(20).ProductIDString = "124-2728" &amp; vbTab
      InventoryProduct(20).DescriptionString = "7/16  (14/32)-4 XB  OSB 3-WHITE STRIPES"
      'InventoryProduct(20).QuantityInteger = 75
      ' InventoryProduct(20).PriceDecimal = 79.4D
  
      InventoryProduct(21).ProductIDString = "124-2809" &amp; vbTab
      InventoryProduct(21).DescriptionString = "1/2  (16/32)-4 XB  OSB 2-WHITE BLAK  STRIPES" &amp; Space(17)
  
      ' InventoryProduct(21).QuantityInteger = 75
      ' InventoryProduct(21).PriceDecimal = 79.4D
  
      InventoryProduct(22).ProductIDString = "124-2867" &amp; vbTab
      InventoryProduct(22).DescriptionString = "3/4  (23/32)-4 XB  OSB T&amp;G 5-WHITE STRIPES"
      ' InventoryProduct(22).QuantityInteger = 75
      ' InventoryProduct(22).PriceDecimal = 79.4D
  
      InventoryProduct(23).ProductIDString = "131-1248" &amp; vbTab
      InventoryProduct(23).DescriptionString = "1/2x4'-12'  GYPsum  78LBL"
      ' InventoryProduct(23).QuantityInteger = 75
      ' InventoryProduct(23).PriceDecimal = 79.4D
  
      InventoryProduct(24).ProductIDString = "131-1256" &amp; vbTab
      InventoryProduct(24).DescriptionString = "1/2x4'-8'  MOLD/MR  78LBL"
      ' InventoryProduct(24).QuantityInteger = 75
      ' InventoryProduct(24).PriceDecimal = 79.4D
  
      InventoryProduct(25).ProductIDString = "131-1259" &amp; vbTab
      InventoryProduct(25).DescriptionString = "5/8x4'-8'  MOLD/MR TYPR X   105LBL"
      ' InventoryProduct(25).QuantityInteger = 75
      ' InventoryProduct(25).PriceDecimal = 79.4D
  
      InventoryProduct(26).ProductIDString = "131-1303" &amp; vbTab
      InventoryProduct(26).DescriptionString = "5/8X4-12'  GYPS PC TYPE  X 105LBL"
      '  InventoryProduct(26).QuantityInteger = 75
      ' InventoryProduct(26).PriceDecimal = 79.4D
  
      InventoryProduct(27).ProductIDString = "131-2454" &amp; vbTab
      InventoryProduct(27).DescriptionString = "8' METAL 1-1/4 CORNERBEAD"
      '  InventoryProduct(27).QuantityInteger = 75
      ' InventoryProduct(27).PriceDecimal = 79.4D
  
      InventoryProduct(28).ProductIDString = "131-2726" &amp; vbTab
      InventoryProduct(28).DescriptionString = "ALL PURPOSE PALE-BLACK 7GAL"
      ' InventoryProduct(28).QuantityInteger = 75
      ' InventoryProduct(28).PriceDecimal = 79.4D
  
      InventoryProduct(29).ProductIDString = "131-2849" &amp; vbTab
      InventoryProduct(29).DescriptionString = "EZ SAND  90  18#"
      ' InventoryProduct(29).QuantityInteger = 75
      ' InventoryProduct(29).PriceDecimal = 79.4D
  
      InventoryProduct(30).ProductIDString = "131-2881" &amp; vbTab
      InventoryProduct(30).DescriptionString = "SPRAY-TEXTURE MEDIUM  40#"
      ' InventoryProduct(30).QuantityInteger = 75
      ' InventoryProduct(30).PriceDecimal = 79.4D
  
      InventoryProduct(31).ProductIDString = "131-3097" &amp; vbTab
      InventoryProduct(31).DescriptionString = "PROROC JOINT TAPE  250'"
      ' InventoryProduct(31).QuantityInteger = 75
      ' InventoryProduct(31).PriceDecimal = 79.4D
  
      InventoryProduct(32).ProductIDString = "165-0372" &amp; vbTab
      InventoryProduct(32).DescriptionString = "M/H208  ANJ COLUMN 3INCH DIAM -8'4"
      ' InventoryProduct(32).QuantityInteger = 75
      '  InventoryProduct(32).PriceDecimal = 79.4D
  
      InventoryProduct(33).ProductIDString = "227-1442" &amp; vbTab
      InventoryProduct(33).DescriptionString = "NAIL 1-1/2 JOIST HANGER   5LB GALV"
      ' InventoryProduct(33).QuantityInteger = 75
      ' InventoryProduct(33).PriceDecimal = 79.4D
  
      InventoryProduct(34).ProductIDString = "228-3142" &amp; vbTab
      InventoryProduct(34).DescriptionString = "JOIST HNGR  TM 2.5X14  THO54140"
      ' InventoryProduct(34).QuantityInteger = 75
      ' InventoryProduct(34).PriceDecimal = 79.4D
  
      InventoryProduct(35).ProductIDString = "229-1202" &amp; vbTab
      InventoryProduct(35).DescriptionString = "NAIL 8D  V.C.  SINKERS   50LBL BOX"
      ' InventoryProduct(35).QuantityInteger = 75
      ' InventoryProduct(35).PriceDecimal = 79.4D
  
      InventoryProduct(36).ProductIDString = "229-1244" &amp; vbTab
      InventoryProduct(36).DescriptionString = "NAIL 16D  V.C.  SINKERS   50LBL BOX"""
      ' InventoryProduct(36).QuantityInteger = 75
      ' InventoryProduct(36).PriceDecimal = 79.4D
  
      InventoryProduct(37).ProductIDString = "229-1303" &amp; vbTab
      InventoryProduct(37).DescriptionString = "NAIL 16D  GALVANZED BOX  50LBL BOX"""
      ' InventoryProduct(37).QuantityInteger = 75
      ' InventoryProduct(37).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 &gt; NumberProductsInteger
  
          'Compare textBox to array
          If ProductIDTextBox.Text = InventoryProduct(RowInteger).ProductIDString Then
  
              'found a match - display other data to the readonly textboxes
              ProductIDComboBox.SelectedItem = ProductIDTextBox.Text
              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()
          ProductIDComboBox.SelectedIndex = -1
  
          'Display message that the ProductID is not valid
          MessageBox.Show("Reenter a valid SKU 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 &amp; " - " &amp; DescriptionTextBox.Text &amp; " - " &amp; 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")
  
          'Accumulate total sales by product to an array
          Dim IndexInteger As Integer = ProductIDComboBox.SelectedIndex
          ProductSalesTotalDecimal(IndexInteger) += Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
  
          'Here you can clear the form of product info if you think
          'that is a good way to do the processing
          ProductIDComboBox.SelectedIndex = -1
          ProductIDTextBox.Clear()
          DescriptionTextBox.Clear()
          PriceTextBox.Clear()
          QuantityTextBox.Clear()
          ProductIDTextBox.Focus()
      End If
  End Sub
  
  Private Sub ResetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetToolStripMenuItem.Click
      'Clear all text box and combobox controls
      ProductIDComboBox.SelectedIndex = -1
      ProductIDTextBox.Clear()
      DescriptionTextBox.Clear()
      PriceTextBox.Clear()
      QuantityTextBox.Clear()
      ' TotalDueTextBox.Clear()
  
      'Clear the list box control
      PurchaseListBox.Items.Clear()
  
      'Reset the total due module-level variable to zero
      TotalDueDecimal = 0
  
      'Set the focus to the product ID text box
      ProductIDTextBox.Focus()
  End Sub
  
  Private Sub SearchToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchToolStripMenuItem.Click
      'Call the Click event for theSearch button control
      SearchButton.PerformClick()
  End Sub
  
  Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
      Dim MessageString As String = "Version 1 John Burtons Building Cost Estimater" &amp; ControlChars.NewLine &amp; "Today's date/time: " &amp; Date.Now
      Dim TitleString As String = "About Version 1"
  
      MessageBox.Show(MessageString, TitleString, MessageBoxButtons.OK, MessageBoxIcon.Information)
  End Sub
  
  Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  
      'Close the form
      Me.Close()
  End Sub
  
  Private Sub ProductIDComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProductIDComboBox.SelectedIndexChanged
  
      'Test to determine if a product has been selected
      If ProductIDComboBox.SelectedIndex &lt;&gt; -1 Then
  
          'Store the selectedIndex to variable
          Dim RowInteger As Integer = ProductIDComboBox.SelectedIndex
  
          'Based on RowInteger, display values to TextBox controls
          'from the array named inventoryProduct
          ProductIDTextBox.Text = InventoryProduct(RowInteger).ProductIDString
          DescriptionTextBox.Text = InventoryProduct(RowInteger).DescriptionString
          QuantityTextBox.Text = InventoryProduct(RowInteger).QuantityInteger.ToString("N0")
          PriceTextBox.Text = InventoryProduct(RowInteger).PriceDecimal.ToString("C2")
      End If
  End Sub
  
  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
      Dim SalesString As String = "ProductID" &amp; vbTab &amp; "Dollar Sales" &amp; vbCrLf
      For Each ProductItem As Product In InventoryProduct
          'Build string to display
          SalesString &amp;= ProductItem.ProductIDString &amp; vbTab &amp; vbTab &amp; ProductSalesTotalDecimal(RowInteger).ToString("C2") &amp; vbCrLf
  
          'Increment RowInteger
          RowInteger += 1
      Next
      'Display string to a MessageBox
      'Debug.WriteLine(SalesString)
      MessageBox.Show(SalesString, "Sales for all Products", MessageBoxButtons.OK, MessageBoxIcon.Information)
  End Sub
  
  
  
  Private Sub Button3_Click(sender As Object, e As EventArgs) Handles PurchaseBtn.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 &amp; "  " &amp; DescriptionTextBox.Text &amp; "    " &amp; QuantityTextBox.Text &amp; "     " &amp; PriceTextBox.Text
          PurchaseListBox.Items.Add(ProductString)
  
  
          ' Dim Total As Double
          '  For i = 0 To PurchaseListBox.Items.Count
          'Total += Convert.ToDouble(PriceTextBox.Items.Item(i)) * Convert.ToDouble(QuantityTextBox.Items.Item(i))
          ' Next i
          ' Debug.WriteLine(Total)
  
  
          '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 = Products.Sum(Function(x) x.Cost).ToString("C2")
          ' TotalDueTextBox.Text = TotalDueDecimal.ToString("C2")
  
          'Accumulate total sales by product to an array
          Dim IndexInteger As Integer = ProductIDComboBox.SelectedIndex
          ProductSalesTotalDecimal(IndexInteger) += Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
  
          'Here you can clear the form of product info if you think
          'that is a good way to do the processing
          ProductIDComboBox.SelectedIndex = -1
          ProductIDTextBox.Clear()
          DescriptionTextBox.Clear()
          PriceTextBox.Clear()
          QuantityTextBox.Clear()
          ProductIDTextBox.Focus()
      End If
  End Sub
  Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles SaveAsToolStripMenuItem.Click
  
      sFile.InitialDirectory = ("C:\")
      sFile.FileName = ("Save As...")
      sFile.Filter = ("Only Text Files (*.txt)|*.txt")
      sFile.ShowDialog()
  
      Dim W As New IO.StreamWriter(sFile.FileName, True)  ' notes from class need messgbox
      Dim i As Integer
      For i = 0 To PurchaseListBox.Items.Count - 1
          W.WriteLine(PurchaseListBox.Items.Item(i))
  
          Dim L As New IO.StreamWriter(sFile.FileName, True)
          L.WriteLine(TotalDueTextBox)
  
  
          ' Next
          ' Dim L As New IO.StreamWriter(sFile.FileName)
          ' For i = 0 To TotalDueTextBox.Items.Count - 1
          'W.WriteLine(TotalDueTextBox.Items.Item(i))
  
      Next
      W.Close()
  End Sub
  
  Private Sub PriceTextBox_TextChanged(sender As Object, e As EventArgs) Handles PriceTextBox.TextChanged
  
  
  
  End Sub
  
  ' Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  'Dim num1, num2, product As Decimal
  
  '  num1 = PriceTextBox.Text
  '  num2 = QuantityTextBox.Text
  ' product = num1 * num2
  ' TextBox3.Text = product
  ' PriceTextBox.Text = TextBox3.Text
  
  
  '  End Sub
  </code></pre>
  
  <p>End Class</p>