Results 1 to 40 of 40

Thread: transferring multiple information from form to form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    transferring multiple information from form to form

    Hello,

    So my question is that I have 2 list boxes in two forms aside from the main one. and I am trying to transfer what I choose in the side form to transfer to the list box.

    several questions:
    Why does the blank list form I have in the main form create a problem when I enter a name for the list box and why does it appear in the box when I put it there? As you can see in my errors. It doesn't seem to recognize the listbox that I wanted to leave empty in the main form.

    Second question is how do I get names to add in the main form list box. I believe I have the right code but I seem to be missing something else as well. I want the names to display in the main list box and the integers to add up together so I can separately figure the tax and shipping myself. Thank you

    Here are some pictures and codes

    Main:

    Print:

    Audio:



    Code:
    Public Class MainForm
    
        Dim frmAudioBooks As New AudioBooks
        Dim frmPrintedBooks As New PrintedBooks
        Const decTaxRate As Decimal = 0.06D ' Tax rate for Books
        Const decShipping As Decimal = 2D ' Shipping Rate per Book
        Const decPrintIDidIt As Decimal = 11.95D 'Price of Print Book "I Did It Your Way"
        Const decPrintHistory As Decimal = 14.5D 'Price of Print Book "The History of Scotland"
        Const decPrintCalculus As Decimal = 29.95D 'Price of Print Book "Learn Calculus in One Day"
        Const decPrintStress As Decimal = 18.5D 'Price of Print Book "Feel the Stress"
        Const decAudioCaluclus As Decimal = 29.95D 'Price of Audio Book "Learn Calculus in One Day"
        Const decAudioHistory As Decimal = 14.5D 'Price of Audio Book "The History of Scotland" 
        Const decAudioScience As Decimal = 12.95D 'Price of Audio Book "The Science of Body Language"
        Const decAudioRelax As Decimal = 11.5D 'Price of Audio Book "Relaxation Techniques
    
    
        Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
            'Close the Form
            Me.Close()
        End Sub
    
        Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
            'Display a short description of the program
            MessageBox.Show("The program executes a shopping menu for the user to choose from many books both audio and printed and let's them pick from multiple books to check and buy. Designed by Justin Guan")
        End Sub
    
        Private Sub mnuProductsPrintedBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsPrintedBooks.Click
            frmPrintedBooks.Show()
        End Sub
    
        Private Sub mnuProductsAudioBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsAudioBooks.Click
            frmAudioBooks.Show()
        End Sub
    
        Private Sub mnuFileReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileReset.Click
            lstProducts.Items.Clear()
        End Sub
    
    End Class
    
    Public Class PrintedBooks
    
        Private Sub btnPrintAddCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintAddCart.Click
            Dim intPrintInput As Integer 'Holds the selected Printed Book
    
            For intPrintInput = 0 To lstPrint.Items.Count = -1
                If lstPrint.SelectedIndex = -1 Then
                    'No book is selected
                    MessageBox.Show("Select a book.")
                ElseIf lstPrint.GetSelected(intPrintInput) Then
                    lstProducts.Items.Add(lstPrint.Items(intPrintInput))
                    'Gets the Selected book
                End If
            Next
    
        End Sub
    End Class
    
    Public Class AudioBooks
        Private Sub btnAudioClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAudioClose.Click
            Me.Close()
        End Sub
    
        Private Sub btnAudioAddCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAudioAddCart.Click
            Dim intAudioInput As Integer 'Holds the selected Printed Book
    
            For intAudioInput = 0 To lstAudio.Items.Count = -1
                If lstAudio.SelectedIndex = -1 Then
                    'No book is selected
                    MessageBox.Show("Select a book.")
                ElseIf lstAudio.GetSelected(intAudioInput) Then
                    lstProducts().Items.Add(lstAudio.Items(intAudioInput))
                    'Gets the Selected book
                End If
            Next
        End Sub
    
    End Class

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    using lstProducts outside of mainform:

    vb Code:
    1. mainform.lstProducts.Items.Add(lstAudio.Items(intAudioInput))

    but you need to be sure mainform is open.

    have a look at this thread, for a better method:

    http://www.vbforums.com/showthread.p...81#post4087181

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    sweet thanks for that. But my issue now is how come when I select from one of the listbox in the side forms, it doesn't display in the main list box. nothing occurs when I press the add to cart button

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: transferring multiple information from form to form

    What did you expect this to do?

    ElseIf lstPrint.GetSelected(intPrintInput) Then

    Since it is an If statement, it has to evaluate to True or False. I would expect that to evaluate to True, but it might not.

    I think you want that to just be an Else. After all, the If checks to see whether anything was selected, so to even reach this line, something must be selected. Presumably, you want to move those items across, regardless of which items was selected, though maybe you wanted to check for whether a certain item was selected....
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    I see, but how do I assign values to each book? no matter which one I select and click add to cart, it chooses the first one

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    and how do I assign the price value to that specific book. my textbook confuses me a lot

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    Quote Originally Posted by redneckrider View Post
    and how do I assign the price value to that specific book. my textbook confuses me a lot
    what are the directions for your assignment?

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: transferring multiple information from form to form

    Well, you follow that ElseIf with this line:

    lstProducts().Items.Add(lstAudio.Items(intAudioInput))

    That will add an item, but it will always add whatever item is at intAudioInput. What you want to be doing is adding the selected item, not the one at intAudioInput. However, there are two ways of doing this, depending on whether you have single select or multiselect. If it is singleselect, then you can probably use:

    lstProducts().Items.Add(lstAudio.SelectedItem)

    For multiselect, you may be able to use AddRange on the SelectedItems collection, but Listbox is a bit archaic, and might not have AddRange. If it doesn't you can iterate through the selected items collection adding each one in turn. It doesn't look like you have multi select on, though.
    My usual boring signature: Nothing

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    Listbox does have multiselect

    edit: i mean Listbox does have addrange

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: transferring multiple information from form to form

    Yeah, I know that, but it is optional, and it rather looks like the OP is using single select.

    What I don't recall is whether the Items collection has AddRange, or if that was one of the features of an interface it doesn't implement. I remember that the Listbox.Items was a really old collection from the dawn of .NET, and it doesn't implement all the interfaces of later collections, so it can be missing some things. I just never remember what it is missing.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    The assignment is to design an app that works as a shopping cart system. the person should be able to add any of the following items to his or her shopping cart.

    I just added the holding values

    Code:
    Dim decTotalBookPrice As Decimal ' Holds the Total Book Price
        Dim intTotalBooks As Integer ' Holds the Total amount of books
        Dim decTotalPrice As Decimal ' The total price after Tax, Shipping and Book price

    problem now is I can get the books to display on the main list box, but I can't seem to figure out how to assign the exact prices to those books. Do the list the code in the separate forms or the main one

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    are you using databinding?
    the listbox has a selecteditem (which would be the text you see) + a selectedvalue (the price of the item) that you could use if you bind a datasource

    @Shaggy. check the edit in post #9

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    not really sure what data binding is. but how would I bind the selected item to the selected value. Do I place that code within the main form where I declared the prices or should I place them in the side form codes to figure it out

    what would be the code to bind them

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    ok. looks like you aren't using databinding then.
    there's a different way you could do this. the listbox items are objects, which means you can add more than just strings.

    here's a custom listItem:

    vb Code:
    1. Public Class listItem
    2.     Public display As String
    3.     Public value As Decimal
    4.     Public Overrides Function ToString() As String
    5.         Return Me.display
    6.     End Function
    7. End Class

    instead of:

    vb Code:
    1. lstPrint.items.add("a string")

    you'd use:

    vb Code:
    1. lstPrint.Items.Add(New listItem With {.display = "Book" & x.ToString, .value = 10})

    here's an example project:
    Attached Files Attached Files

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    so if im correct, for the first vB code, I would put Public Class listPrintCalculus??? what is the .value = 10 mean? I don't follow where that is coming from. where am I declaring the price values?
    Attached Files Attached Files

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    value = 10 is just an example number.
    the value would be the price of the book or item or whatever your list contains

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    vb Code:
    1. Public Class listItem
    2.     Public display As String
    3.     Public value As Decimal
    4.     Public Overrides Function ToString() As String
    5.         Return Me.display
    6.     End Function
    7. End Class


    would this be for each individual book?

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    " & x.ToString, .value = 10})

    also what is the x. doing?

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    When I do that. the display text has WindowsApplication when it comes right after the text

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Code:
    Public Class PrintedBooks
    
        Public Class PrintIDidIt
            Public display As String
            Public value As Decimal
            Public Overrides Function ToString() As String
                Return Me.display
            End Function
        End Class
        Public Class PrintHistory
            Public display As String
            Public value As Decimal
            Public Overrides Function ToString() As String
                Return Me.display
            End Function
        End Class
        Public Class PrintCalculus
            Public display As String
            Public value As Decimal
            Public Overrides Function ToString() As String
                Return Me.display
            End Function
        End Class
        Public Class PrintStress
            Public display As String
            Public value As Decimal
            Public Overrides Function ToString() As String
                Return Me.display
            End Function
        End Class
        Private Sub btnPrintAddCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintAddCart.Click
            Dim intPrintInput As Integer 'Holds the selected Printed Book
    
            For intPrintInput = 0 To lstPrint.Items.Count = -1
                If lstPrint.SelectedIndex = -1 Then
                    'No book is selected
                    MessageBox.Show("Select a book.")
                Else : lstPrint.GetSelected(intPrintInput)
                    MainForm.lstProducts().Items.Add(New PrintIDidIt With {.display = "I Did It Your Way (Print)" & ToString(), .value = 11.95})
                    MainForm.lstProducts().Items.Add(New PrintHistory With {.display = "The History of Scotland" & ToString(), .value = 14.5})
                    MainForm.lstProducts().Items.Add(New PrintIDidIt With {.display = "Learn Calculus in One Day" & ToString(), .value = 29.95})
                    MainForm.lstProducts().Items.Add(New PrintIDidIt With {.display = "Feel the Stress" & ToString(), .value = 18.5})
                    'Gets the Selected book
                End If
            Next
    
        End Sub
    I currently have this, and it still doesn't specific which one i pick. It just simply displays all of them and WindowsApplication text right after it.
    Attached Files Attached Files
    Last edited by redneckrider; Nov 3rd, 2011 at 08:07 PM.

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    i uploaded an example project. it's a working example that should help you understand how the custom listItem works + how to transfer selected items between forms.

    i could finish your project for you, but what will you learn? nothing.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Sorry Didn't mean you to help me complete it. Mere misunderstanding

    Now that I have this

    Code:
    Public Class listItem
        Public display As String
        Public value As Decimal
        Public Overrides Function ToString() As String
            Return Me.display
        End Function
    End Class

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With lstPrint
                lstPrint.Items.Add(New listItem With {.display = "I Did It Your Way (Print)" & ToString(), .value = 11.95})
                lstPrint.Items.Add(New listItem With {.display = "The History of Scotland (Print)" & ToString(), .value = 14.5})
                lstPrint.Items.Add(New listItem With {.display = "Learn Calculus in One Day (Print)" & ToString(), .value = 29.95})
                lstPrint.Items.Add(New listItem With {.display = "Feel the Stress (Audio)" & ToString(), .value = 18.5})
                MainForm.Show()
            End With
        End Sub
    
    
        Private Sub lstPrint_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstPrint.SelectedIndexChanged
            Dim ItemSelected As Decimal
            ItemSelected = CType(lstPrint.SelectedItem,  _
                listItem).value
        End Sub
    How can I compile the values that were added to the main listbox by adding them all together. I'm used to adding them as separate values not all of them stored in one.

    Also is there a way to count the amount of books in the main listbox?

    Thank you for everything so far. It's been so helpful
    Last edited by redneckrider; Nov 4th, 2011 at 03:49 AM.

  23. #23
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    ok try this. the listItem class should be a separate class (Project-->Add Class. + name it listItem, then paste code into class):

    vb Code:
    1. Public Class listItem
    2.     Public display As String
    3.     Public value As Decimal
    4.     Public Overrides Function ToString() As String
    5.         Return Me.display
    6.     End Function
    7. End Class

    vb Code:
    1. Public Class AudioBooks
    2.  
    3.     Private Sub btnAudioClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAudioClose.Click
    4.         Me.Close()
    5.     End Sub
    6.  
    7.     Private Sub btnAudioAddCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAudioAddCart.Click
    8.         MainForm.lstProducts.Items.AddRange(lstAudio.SelectedItems.Cast(Of listItem).ToArray)
    9.         MainForm.lblSubtotal.Text = MainForm.lstProducts.Items.Cast(Of listItem).Sum(Function(li) li.value).ToString("c2")
    10.     End Sub
    11.  
    12.     Private Sub AudioBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         'prices are just used for illustration purposes. change to actual prices if necessary
    14.         lstAudio.Items.Add(New listItem With {.display = "Learn Calculus in One Day (Audio)", .value = 10.99})
    15.         lstAudio.Items.Add(New listItem With {.display = "Relaxation Techniques(Audio)", .value = 7.99})
    16.         lstAudio.Items.Add(New listItem With {.display = "The History of Scotland (Audio)", .value = 9.99})
    17.         lstAudio.Items.Add(New listItem With {.display = "The Science of Body Language (Audio)", .value = 8.99})
    18.     End Sub
    19.  
    20. End Class

    vb Code:
    1. Public Class PrintedBooks
    2.  
    3.     Private Sub btnPrintAddCart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintAddCart.Click
    4.         MainForm.lstProducts.Items.AddRange(lstPrint.SelectedItems.Cast(Of listItem).ToArray)
    5.         MainForm.lblSubtotal.Text = MainForm.lstProducts.Items.Cast(Of listItem).Sum(Function(li) li.value).ToString("c2")
    6.     End Sub
    7.  
    8.     Private Sub btnPrintClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintClose.Click
    9.         Me.Close()
    10.     End Sub
    11.  
    12.     Private Sub PrintedBooks_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         'prices are just used for illustration purposes. change to actual prices if necessary
    14.         lstPrint.Items.Add(New listItem With {.display = "I Did It Your Way (Print)", .value = 10.99})
    15.         lstPrint.Items.Add(New listItem With {.display = "The History of Scotland (Print)", .value = 7.99})
    16.         lstPrint.Items.Add(New listItem With {.display = "Learn Calculus in One Day (Print)", .value = 9.99})
    17.         lstPrint.Items.Add(New listItem With {.display = "Feel the Stress (Print)", .value = 8.99})
    18.     End Sub
    19.  
    20. End Class

  24. #24
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    another suggestion:

    change lstAudio + lstPrint selectionmode property to multisimple + you can then add more than 1 book at a time

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Quote Originally Posted by .paul. View Post
    another suggestion:

    change lstAudio + lstPrint selectionmode property to multisimple + you can then add more than 1 book at a time

    I'm not quite sure how to really do that. Is that done in the design window?


    Also another big question is how do I do a count on the amount of books that will be in the main listbox? I need it to calculate another formula for my project.



    Edit: Also why does it add two books instead of one?
    Last edited by redneckrider; Nov 4th, 2011 at 12:11 PM.

  26. #26
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    Quote Originally Posted by redneckrider View Post
    I'm not quite sure how to really do that. Is that done in the design window?


    Also another big question is how do I do a count on the amount of books that will be in the main listbox? I need it to calculate another formula for my project.



    Edit: Also why does it add two books instead of one?
    in design view select the listbox. to the right of your screen is your properties window. change the selectionmode property there.


    2 books instead of 1??? i downloaded your project from a previous post + with my changes it adds the correct amount of books.


    to calculate the number of books in lstProducts:

    vb Code:
    1. lstProducts.Items.count

    if you need to differentiate between audio + printed books in your calculations, we can add a type property to the listItem

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    I found the double problem. I had for my error message of not selecting a book.
    Code:
    Else : lstAudio.GetSelected(intAudioInput)
                    MainForm.lstProducts().Items.Add(lstAudio.SelectedItem)
    Last edited by redneckrider; Nov 4th, 2011 at 12:30 PM.

  28. #28
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    Quote Originally Posted by .paul. View Post
    2 books instead of 1???
    my mistake. i forgot to tell you i removed the items you'd added at design time, so i could add them as listItems instead of strings

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    For the item count, when I put it in a formula, would it be something like

    Code:
    lstProducts.Items.count * decShipping = intTotalShipping
    Edit: How Do I calculate what is in the label for Subtotal in another equation?

    Would it be

    Code:
    lblSubtotal.Text * decTaxRate = lblTax

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Code:
    lblTax.Text = decTaxCost.ToString("c2")
    
        Function TaxCost() As Decimal
            Dim decTaxCost As Decimal = 0
            Const decTaxRate As Decimal = 0.06D ' Tax rate for Books
    
    
            decTaxCost = CDec(lblSubtotal.Text) * decTaxRate
    
            Return decTaxCost
    
    
        End Function

    Why does my label text require a declaration expected?

  31. #31
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: transferring multiple information from form to form

    If you mean this line:

    lblTax.Text = decTaxCost.ToString("c2")


    that appears to be outside of any method. You won't be able to do that. The line has to be inside a method.
    My usual boring signature: Nothing

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Quote Originally Posted by Shaggy Hiker View Post
    If you mean this line:

    lblTax.Text = decTaxCost.ToString("c2")


    that appears to be outside of any method. You won't be able to do that. The line has to be inside a method.

    So I have this in the function and I can't get it to execute into the label


    Code:
    Function TaxCost() As Decimal
            Dim decTaxCost As Decimal = 0
            Const decTaxRate As Decimal = 0.06D ' Tax rate for Books
    
            decTaxCost = CDec(lblSubtotal.Text) * decTaxRate
    
            Return decTaxCost
    
            decTotalTax = TaxCost()
    
            lblTax.Text = decTotalTax.ToString("c2")
    
        End Function
    Last edited by redneckrider; Nov 4th, 2011 at 12:53 PM.

  33. #33
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: transferring multiple information from form to form

    Once execution hits that Return statement, that's the end of the function. Any lines after that, such as the line that puts the information into the label, won't get executed. You have to move the return to the end of the function.
    My usual boring signature: Nothing

  34. #34

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Ok so far I have this, my tax label still doesn't return a value back to the label

    and for the other labels to display, you said they have to be within a method. where would they go?

    I attached my program. Where did I go wrong?

    Code:
    Public Class MainForm
    
        Dim frmAudioBooks As New AudioBooks
        Dim frmPrintedBooks As New PrintedBooks
    
        Const decShipping As Decimal = 2D ' Shipping Rate per Book
        Const decPrintIDidIt As Decimal = 11.95D 'Price of Print Book "I Did It Your Way"
        Const decPrintHistory As Decimal = 14.5D 'Price of Print Book "The History of Scotland"
        Const decPrintCalculus As Decimal = 29.95D 'Price of Print Book "Learn Calculus in One Day"
        Const decPrintStress As Decimal = 18.5D 'Price of Print Book "Feel the Stress"
        Const decAudioCaluclus As Decimal = 29.95D 'Price of Audio Book "Learn Calculus in One Day"
        Const decAudioHistory As Decimal = 14.5D 'Price of Audio Book "The History of Scotland" 
        Const decAudioScience As Decimal = 12.95D 'Price of Audio Book "The Science of Body Language"
        Const decAudioRelax As Decimal = 11.5D 'Price of Audio Book "Relaxation Techniques
    
        Dim decTotalBookCount As Decimal ' Holds Total Book Count
        Dim decTotalBookPrice As Decimal ' Holds Total Book Price
        Dim decTotalTax As Decimal ' Holds the Total Tax Price
        Dim decTotalShipping As Decimal ' Holds the Total shipping amount of books
        Dim decTotalPrice As Decimal ' The total price after Tax, Shipping and Book price
    
        'Display Labels (Tax, Shipping Rate, Total)
    
    
        lblShipping.Text = decTotalShipping.ToString("c2")
        lblTotal.Text = decTotalPrice.ToString("c2")    
    
    
        'Holds the Functions
    
            decTotalShipping = decShipping * CDbl(lstProducts.Items.count)
            decTotalPrice = decTax + decTotalShipping + CDec(lblSubtotal.Text)
    
    
        Function TaxCost() As Decimal
            Dim decTaxCost As Decimal = 0
            Const decTaxRate As Decimal = 0.06D ' Tax rate for Books
    
            decTaxCost = CDec(lblSubtotal.Text) * decTaxRate
    
    
    
            decTotalTax = TaxCost()
    
            lblTax.Text = decTotalTax.ToString("c2")
            Return decTaxCost
    
        End Function
    
    
    
    
    
        Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
            'Close the Form
            Me.Close()
        End Sub
    
        Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
            'Display a short description of the program
            MessageBox.Show("The program executes a shopping menu for the user to choose from many books both audio and printed and let's them pick from multiple books to check and buy. Designed by Justin G.")
        End Sub
    
        Private Sub mnuProductsPrintedBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsPrintedBooks.Click
            frmPrintedBooks.Show()
        End Sub
    
        Private Sub mnuProductsAudioBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsAudioBooks.Click
            frmAudioBooks.Show()
        End Sub
    
        Private Sub mnuFileReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileReset.Click
            lstProducts.Items.Clear()
        End Sub
    
        Private Sub lstProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged
            MsgBox(DirectCast(lstProducts.SelectedItem, listItem).value)
    
    
    
    
        End Sub
    End Class
    Attached Files Attached Files

  35. #35
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    try this:
    Attached Files Attached Files

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Ok for this part, I am confused to what to put into there, would I put in the Audio or the Print listbox?

    If I put lstAudio in it, it will do what it did before and double to amount of books when I click once

    How would I declare it for the listbox for Print if it allows to choose one source listbox

    Code:
      Public Shared Sub updateMainformLB(ByVal sourceListbox As ListBox, ByVal lstProducts As ListBox, ByVal lblSubtotal As Label, ByVal lblTax As Label, ByVal lblShipping As Label, ByVal lblTotal As Label)
            lstProducts.Items.AddRange(sourceListbox.SelectedItems.Cast(Of listItem).ToArray)
            updateMainformLbls(lstProducts, lblSubtotal, lblTax, lblShipping, lblTotal)
        End Sub
    Last edited by redneckrider; Nov 4th, 2011 at 01:50 PM.

  37. #37
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    did you read the rest of the project?
    that sub procedure has that parameter so it works with either listbox.

    with parameters you pass values: i.e

    vb Code:
    1. private sub showAMsgbox(byval msg as string)
    2.     msgbox(msg)
    3. end sub

    then you'd use it like this:

    vb Code:
    1. showAMsgbox("this is the value you passed")

    + it will show a msgbox with "this is the value you passed" as it's text.

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Sep 2011
    Posts
    69

    Re: transferring multiple information from form to form

    Yes it finally works!!! thank you soo much

    one quick question though

    When I click print or audio to have another form popup and i close it, and when I try to open it again
    it says it cannot access a disposed object

  39. #39
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    at the top of mainForm code, change:

    vb Code:
    1. Dim frmAudioBooks As New AudioBooks
    2. Dim frmPrintedBooks As New PrintedBooks

    to:

    vb Code:
    1. Dim frmAudioBooks As AudioBooks
    2. Dim frmPrintedBooks As PrintedBooks

    then change:

    vb Code:
    1. Private Sub mnuProductsPrintedBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsPrintedBooks.Click
    2.     frmPrintedBooks.Show()
    3. End Sub
    4.  
    5. Private Sub mnuProductsAudioBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsAudioBooks.Click
    6.     frmAudioBooks.Show()
    7. End Sub

    to:

    vb Code:
    1. Private Sub mnuProductsPrintedBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsPrintedBooks.Click
    2.     frmPrintedBooks = New PrintedBooks
    3.     frmPrintedBooks.Show()
    4. End Sub
    5.  
    6. Private Sub mnuProductsAudioBooks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuProductsAudioBooks.Click
    7.     frmAudioBooks = New AudioBooks
    8.     frmAudioBooks.Show()
    9. End Sub

  40. #40
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: transferring multiple information from form to form

    one last recommendation.
    i'd show frmPrintedBooks + frmAudioBooks as dialogs (Form.ShowDialog Method) as i tried to tell you in post #2

Posting Permissions

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



Click Here to Expand Forum to Full Width