dcsimg
Results 1 to 1 of 1

Thread: Shopping cart System Project

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2015
    Posts
    24

    Shopping cart System Project

    Hey guys, doing a Shopping Cart System project and i have all the code for it, no errors or anything but everytime i go to try and run it i get an error message stating the following

    "Exception thrown: 'System.InvalidCastException' in Microsoft.VisualBasic.dll
    An unhandled exception of type 'System.InvalidOperationException' occurred in Shopping Cart.exe
    Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: Conversion from string "Subtotal:" to type 'Double' is not valid."

    I dont know what it is but i really could use some help, insight, something!!

    Here is the code in case you need it

    Thank you in advance!

    Main Form

    Public Class MainForm
    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    lblTax.Text = "0.06%"
    lblShipping.Text = "$2/Book"
    End Sub

    Public Sub lblSubTotal_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblSubtotal.TextChanged
    Const SalesTax As Single = 0.06
    Const Shipping As Single = 2.0
    Dim TotalSale As Single = 0

    lblTax.Text = FormatNumber(lblSubtotal.Text * SalesTax) 'calculate & Display SalesTax

    lblShipping.Text = FormatCurrency((lbBooks.Items.Count) * Shipping) 'calculate & Display Shipping

    TotalSale = FormatNumber(CSng(lblSubtotal.Text) + CSng(lblTax.Text) + CSng(lblShipping.Text))

    lblTotal.Text = FormatCurrency(TotalSale)

    End Sub

    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
    'BtnRemove performs one of two tasks:
    '1.)Clear selected Item from listBox
    '2.)Clear all form Controls
    Dim strItem As String = "empty"
    strItem = lbBooks.SelectedItem 'Sets strItem to selected item

    If strItem = "" Then 'If no Item selected then clear all controls
    lbBooks.Items.Clear()
    lblSubtotal.Text = 0
    lblTax.Text = "0.06%"
    lblShipping.Text = "$2/Book"
    lblTotal.Text = 0
    Else
    ReCal(strItem)

    lbBooks.Items.Remove(strItem) 'Removes Selected Item from ListBox

    'Recalculate the shipping cost after item removal
    lblShipping.Text = FormatCurrency((lbBooks.Items.Count) * 2.0)

    End If
    End Sub

    Private Sub ResetToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetToolStripMenuItem.Click
    'Clear All -- Resets all the form controls to Initial settings
    lbBooks.Items.Clear()
    lblSubtotal.Text = 0
    lblTax.Text = "0.06%"
    lblShipping.Text = "$2/Book"
    lblTotal.Text = 0

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    Me.Close() 'End the program Run
    End Sub

    Private Sub PrintBooksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintBooksToolStripMenuItem.Click
    PrintBooks.Show() 'Display the Print Books Select Form
    End Sub

    Private Sub AudioBooksToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AudioBooksToolStripMenuItem.Click
    AudioBooks.Show() 'Display the Audio Books Select Form
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
    MessageBox.Show(Me, "Shopping Cart System", "About")
    End Sub


    End Class

    AudioBooks

    Public Class AudioBooks
    Private Sub AudioBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Loads list of book titles into Audio list box
    With lbAudioBooks
    .Items.Add("I Did It Your Way " & "(Audio)")
    .Items.Add("History of Scotland " & "(Audio)")
    .Items.Add("Learn Calculus in one Day " & "(Audio)")
    .Items.Add("Relaxation Techniques " & "(Audio)")
    End With
    End Sub
    Private Sub btnClose_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    MainForm.Show()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim strSelect As String = "empty"
    Dim strBook As String = "empty"
    Dim strMsg As String = "empty"
    Dim Price As Single
    Dim intX As Integer = 0


    Try
    strSelect = lbAudioBooks.SelectedItem.ToString
    strSelect = strSelect.Substring(0, intX)
    GetPrice(strSelect, Price)
    MainForm.lbBooks.Items.Add(strSelect & " -- " & Price)

    MainForm.lblSubtotal.Text = FormatNumber(Val(MainForm.lblSubtotal.Text) + Price)

    Catch
    strMsg = "A Book was Not Selected. "
    MessageBox.Show(strMsg, "InValid InPut")

    End Try
    End Sub
    End Class

    Print Books

    Public Class PrintBooks
    Private Sub PrintBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Loads list of book titles into Print list Box
    With lbPrintBooks
    .Items.Add("I Did It Your Way " & "(Print)")
    .Items.Add("History of Scotland " & "(Print)")
    .Items.Add("Learn Calculus in one Day " & "(Print)")
    .Items.Add("Feel the Stress " & "(Print)")
    End With
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
    MainForm.Show() 'Returns to shopping cart form
    Me.Hide() 'Makes PrintBK form invisible
    End Sub

    Public Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim strSelect As String = "empty"
    Dim strBook As String = "empty"
    Dim strMsg As String = "empty"
    Dim Price As Single
    Dim intX As Integer = 0

    'Try ~ Catch code prevents a fault if the Add button is clicked with no book selected.
    Try
    strSelect = lbPrintBooks.SelectedItem.ToString 'Length Book Title + (Print
    strSelect = strSelect.Substring(0, intX)

    GetPrice(strSelect, Price)
    MainForm.lbBooks.Items.Add(strSelect & " -- " & Price)

    MainForm.lblSubtotal.Text = FormatNumber(Val(MainForm.lblSubtotal.Text) + Price)

    Catch
    strMsg = "A Book was Not Selected. "
    MessageBox.Show(strMsg, "InValid InPut")
    End Try
    End Sub
    End Class

    pricing module

    Module PriceSelect
    Public Sub GetPrice(ByRef Book As String, ByRef BPrice As Single)

    Select Case Book
    Case "I Did It Your Way"
    BPrice = 11.5
    Case "History of Scotland"
    BPrice = 14.5
    Case "Learn Calculus in one Day"
    BPrice = 29.95
    Case "Feel the Stress"
    BPrice = 18.5
    Case "Relaxation Techniques"
    BPrice = 14.5
    Case "The Science of Body Language"
    BPrice = 12.95
    Case Else
    MessageBox.Show("Book Not Found", "InValid Selection")
    End Select

    End Sub
    End Module


    recalc module
    Module Recalculate
    Public Sub ReCal(ByRef strX As String)
    Dim sngSubTotal As Single
    Dim SPrice As Single
    Dim intR
    sngSubTotal = MainForm.lblSubtotal.Text
    intR = CInt(strX.Length - 5)
    SPrice = strX.Substring(intR, 5)

    sngSubTotal = sngSubTotal - SPrice


    MainForm.lblSubtotal.Text = FormatNumber(Val(sngSubTotal))

    End Sub
    End Module



    Thats all the code i have please help! Thanks
    Last edited by loummar7; Nov 10th, 2015 at 06:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width