Getting stuck on this I know it's simple and maybe I'm just over thinking it...Help is much appreciated.
In the CLICK events for the Add buttons on both the Audio Books and Print Books forms, add the selected item to the Shopping Cart listbox on the main form and add its corresponding price to the Costs listbox on the main form.
I've tried multiple things but at a loss...
In the CLICK events for the Add buttons on both the Audio Books and Print Books forms, add the selected item to the Shopping Cart listbox on the main form and add its corresponding price to the Costs listbox on the main form.
I've tried multiple things but at a loss...
Code:
Option Strict On
Public Class Form1
Public Const decSALES_TAX As Decimal = 0.06D
Public Const decSHIPPING_CHARGE As Decimal = 2
Public printBookPrice() As Decimal = {11.95D, 14.5D, 29.95D, 18.5D}
Public printBookName() As String = {"I Did It your Way", "The History of Scotland", "Learn Calculus in One Day", "Feel the Stress"}
Public audioBookPrice() As Decimal = {29.95D, 14.5D, 12.95D, 11.5D}
Public audioBookName() As String = {"Learn Calculus in One Day", "The History of Scotland", "The Science of Body Language", "Relaxation Techniques"}
Private Sub mnuReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuReset.Click
lblSub.Text = String.Empty
lblTax.Text = String.Empty
lblShipp.Text = String.Empty
lblTotal.Text = String.Empty
lstboxCart.Items.Clear()
End Sub
Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click
frmPrintBooks.Show()
End Sub
Private Sub mnuAudio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAudio.Click
frmAudioBooks.Show()
End Sub
Public Sub DisplayCharges()
Dim BookTotal As Decimal = 0
For Each Book As String In lstboxCart.Items
If Book.StartsWith("A") Then
BookTotal += audioBookPrice(CInt(Book.Substring(1, 1)))
Else
BookTotal += printBookPrice(CInt(Book.Substring(1, 1)))
End If
Next
Dim BookCount As Integer = lstboxCart.Items.Count
lblSub.Text = BookTotal.ToString("C2")
lblTax.Text = (BookTotal * decSALES_TAX).ToString("C2")
BookTotal += BookTotal * decSALES_TAX
lblShipp.Text = (BookCount * decSHIPPING_CHARGE).ToString("C2")
BookTotal += BookCount * decSHIPPING_CHARGE
lblTotal.Text = BookTotal.ToString("C2")
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
Me.Close()
End Sub
Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
MessageBox.Show("The Shopping Cart System allows customers to shop for both Print and Audio Books.", "Shopping Cart About")
End Sub
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
If lstboxCart.SelectedIndex <> -1 Then
lstboxCart.Items.RemoveAt(lstboxCart.SelectedIndex)
End If
DisplayCharges()
End Sub
End Class
Code:
Option Strict On
Public Class frmAudioBooks
Private Sub btnCloseaudio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnAddaudio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddprint.Click
Form1.lstboxCart.Items.Add(lstAudiobooks.SelectedIndex & ": " & lstAudiobooks.SelectedItem.ToString)
Form1.DisplayCharges()
End Sub
Private Sub frmAudioBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x = 0 To UBound(Form1.printBookName)
lstAudiobooks.Items.Add(Form1.printBookName(x) & " " & String.Format("{0:C}", Form1.printBookPrice(x)))
Next x
End Sub
End Class
Code:
Option Strict On
Public Class frmPrintBooks
Private Sub btnCloseprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnAddprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Form1.lstboxCart.Items.Add(lstPrintbooks.SelectedIndex & ": " & lstPrintbooks.SelectedItem.ToString)
Form1.DisplayCharges()
End Sub
Private Sub frmPrintbooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For x = 0 To UBound(Form1.printBookName)
lstPrintbooks.Items.Add(Form1.printBookName(x) & " " & String.Format("{0:C}", Form1.printBookPrice(x)))
Next x
End Sub
End Class