Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Option Strict On
- Option Infer Off
- Public Class frmMain
- 'declare array at class level ?
- Dim inAvailableDvds As IO.StreamReader
- Dim strDVDs As String
- Dim dblPrices() As Double
- Public Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
- 'display availableDVDs.txt on load
- 'assign to array and display first column
- 'if file exists, open file
- If IO.File.Exists("availableDVDs.txt") Then
- inAvailableDvds = IO.File.OpenText("availableDVDs.txt")
- 'add items to listbox from file
- Do Until inAvailableDvds.Peek = -1
- 'read file
- strDVDs = inAvailableDvds.ReadLine
- 'display titles - find and stop at comma
- lstDvds.Items.Add(strDVDs.Substring(0, strDVDs.IndexOf(",")))
- 'find comma, pull remaining string
- Dim strTemp As String = strDVDs.Substring(strDVDs.IndexOf(",") + 1)
- 'convert string to double
- 'assign to array
- Loop
- 'bring selected index to first option and close file
- lstDvds.SelectedIndex = 0
- inAvailableDvds.Close()
- End If
- End Sub
- Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
- 'if no selection made, prompt user to select an item and set index to 0
- 'else add item to cart and remove from dvd list
- If lstDvds.SelectedIndex = -1 Then
- MessageBox.Show("Please select an item to add.")
- lstDvds.SelectedIndex = 0
- Else
- 'add item to cart
- lstCart.Items.Add(lstDvds.SelectedItem)
- 'remove from dvds
- lstDvds.Items.Remove(lstDvds.SelectedItem)
- 'insert calculation method below
- 'CalculateTotals()
- End If
- End Sub
- Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
- 'if no selection is made (or no items in cart) prompt user to select an item
- 'else remove item from the cart and add it back to the dvd list
- If lstCart.Items.Count = 0 Then
- MessageBox.Show("Your cart is currently empty. Please add an item.")
- ElseIf lstCart.SelectedIndex = -1 Then
- MessageBox.Show("Please select an item to remove.")
- lstCart.SelectedIndex = 0
- Else
- 'add item back to dvds
- lstDvds.Items.Add(lstCart.SelectedItem)
- 'remove item from cart
- lstCart.Items.Remove(lstCart.SelectedItem)
- 'insert calculation method below
- End If
- End Sub
- Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
- Dim strCustNumber As String = txtCustNum.Text
- If strCustNumber Like "####" Then
- 'store customer number and write to file
- ElseIf strCustNumber = String.Empty Then 'check if empty
- MessageBox.Show("Please enter a customer number to save this order before creating a new order.")
- ElseIf strCustNumber <> "####" Then 'check for length
- MessageBox.Show("The customer number must contain 4 digits.")
- End If
- End Sub
- Private Sub CalculateTotals()
- Const dblTaxRate As Double = 0.04
- Const intShippingCharge As Integer = 1
- Dim dblSubtotal As Double
- 'temporary display placeholders
- txtSubtotal.Text = dblSubtotal.ToString("C2")
- 'calculate tax amt * subtotal = tax
- txtTax.Text = dblTaxRate.ToString("C2")
- 'calculate shipping - not > $5
- txtShipping.Text = intShippingCharge.ToString("C2")
- End Sub
- Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
- 'exits application
- Me.Close()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement