How do I add check box items from one form to a list box on another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DarkMachina295
    New Member
    • Feb 2020
    • 1

    How do I add check box items from one form to a list box on another

    I am having trouble with this Skateboard designer program, and I am not sure how to add items from a separate form to a list box on the main one. Any help at all would be very appreciated.

    Here's my code so far:

    Code:
    Public Class MainForm
        Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
            lblDeck.Text = String.Empty
            lblTrucks.Text = String.Empty
            lblWheels.Text = String.Empty
            lblSubtotal.Text = String.Empty
            lblTax.Text = String.Empty
            lblTotal.Text = String.Empty
        End Sub
    
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
            Me.Close()
        End Sub
    
        Private Sub btnClearMisc_Click(sender As Object, e As EventArgs) Handles btnClearMisc.Click
            lstMisc.Items.Clear()
        End Sub
    
        Private Sub btnViewDecks_Click(sender As Object, e As EventArgs) Handles btnViewDecks.Click
            frmDecks.ShowDialog()
        End Sub
    
        Private Sub btnViewTrucks_Click(sender As Object, e As EventArgs) Handles btnViewTrucks.Click
            frmTrucks.ShowDialog()
        End Sub
    
        Private Sub btnViewWheels_Click(sender As Object, e As EventArgs) Handles btnViewWheels.Click
            frmWheels.ShowDialog()
        End Sub
    
        Private Sub btnViewMisc_Click(sender As Object, e As EventArgs) Handles btnViewMisc.Click
            frmMisc.ShowDialog()
        End Sub
    
        Private Sub MainForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
            lstMisc.Items.Add(intMisc1)
            lstMisc.Items.Add(intMisc2)
            lstMisc.Items.Add(intMisc3)
            lstMisc.Items.Add(intMisc4)
            lstMisc.Items.Add(intMisc5)
        End Sub
    End Class
    Code:
    Module ChargesModule
    
        ' Global constants
        Public frmDecks As New DecksForm
        Public frmMain As New MainForm
        Public frmMisc As New MiscForm
        Public frmTrucks As New TrucksForm
        Public frmWheels As New WheelsForm
        Public dblDeck As Double
        Public dblTrucks As Double
        Public dblWheels As Double
        Public dblMisc As Double
        Public dblSubtotal As Double
        Public dblTax As Double
        Public dblTotal As Double
        Public int51mm As Integer = 0
        Public int55mm As Integer = 1
        Public int58mm As Integer = 2
        Public int61mm As Integer = 3
        Public dbl51mm As Double = 20
        Public dbl55mm As Double = 22
        Public dbl58mm As Double = 24
        Public dbl61mm As Double = 28
        Public intAxle1 As Integer = 0
        Public intAxle2 As Integer = 1
        Public intAxle3 As Integer = 2
        Public dblAxle1 As Double = 35
        Public dblAxle2 As Double = 40
        Public dblAxle3 As Double = 45
        Public intDeck1 As Integer = 0
        Public intDeck2 As Integer = 1
        Public intDeck3 As Integer = 2
        Public dblMasterThrasher As Double = 60
        Public dblDictatorOfGrind As Double = 45
        Public dblStreetKing As Double = 50
        Public dblGripTape As Double = 10
        Public dblBearings As Double = 30
        Public dblRiserPads As Double = 2
        Public dblNutsAndBoltsKit As Double = 3
        Public dblAssembly As Double = 10
        Public intMisc1 As Integer
        Public intMisc2 As Integer
        Public intMisc3 As Integer
        Public intMisc4 As Integer
        Public intMisc5 As Integer
        Public intGripTape As Integer
        Public intBearings As Integer
        Public intRiserPads As Integer
        Public intNutsAndBoltsKit As Integer
        Public intAssembly As Integer
    End Module
    Code:
    Public Class MiscForm
        Private Sub btnAdd_Click(sender As Object, e As EventArgs)
    
            If chkGripTape.Checked = True Then
                dblMisc += dblGripTape
                intMisc1 = CInt(chkGripTape.Text)
            End If
    
            If chkBearings.Checked = True Then
                dblMisc += dblBearings
                intMisc1 = CInt(chkBearings.Text)
            ElseIf intMisc1 = intGripTape Then
                dblMisc += dblBearings
                intMisc2 = CInt(chkBearings.Text)
            End If
    
            If chkRiserPads.Checked = True Then
                dblMisc += dblRiserPads
                intMisc1 = CInt(chkRiserPads.Text)
            ElseIf intMisc1 = intBearings Then
                dblMisc += dblRiserPads
                intMisc2 = CInt(chkRiserPads.Text)
            ElseIf intMisc1 = intGripTape Then
                dblMisc += dblRiserPads
                intMisc2 = CInt(chkRiserPads.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
                dblMisc += dblRiserPads
                intMisc3 = CInt(chkRiserPads.Text)
            End If
    
            If chkNutsAndBoltsKit.Checked = True Then
                dblMisc += dblNutsAndBoltsKit
                intMisc1 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intBearings Then
                dblMisc += dblNutsAndBoltsKit
                intMisc2 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intGripTape Then
                dblMisc += dblNutsAndBoltsKit
                intMisc2 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intRiserPads Then
                dblMisc += dblNutsAndBoltsKit
                intMisc2 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
                dblMisc += dblNutsAndBoltsKit
                intMisc3 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads Then
                dblMisc += dblNutsAndBoltsKit
                intMisc3 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads Then
                dblMisc += dblNutsAndBoltsKit
                intMisc3 = CInt(chkNutsAndBoltsKit.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
                dblMisc += dblNutsAndBoltsKit
                intMisc4 = CInt(chkNutsAndBoltsKit.Text)
            End If
    
            If chkAssembly.Checked = True Then
                dblMisc += dblAssembly
                intMisc1 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intBearings Then
                dblMisc += dblAssembly
                intMisc2 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape Then
                dblMisc += dblAssembly
                intMisc2 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intRiserPads Then
                dblMisc += dblAssembly
                intMisc2 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc2 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intBearings And intMisc2 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intRiserPads And intMisc2 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc3 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
                dblMisc += dblAssembly
                intMisc4 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc4 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads And intMisc3 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc4 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads And intMisc3 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc4 = CInt(chkAssembly.Text)
            ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads And intMisc4 = intNutsAndBoltsKit Then
                dblMisc += dblAssembly
                intMisc5 = CInt(chkAssembly.Text)
            End If
        End Sub
    End Class
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    You just need to explicitly specify the additional form name before the array or variable.
    Code:
    lstMisc.Items.Add(MiscForm.intMisc1)
    Also worth noting is that some of the ElseIf statements on your MiscForm will never be hit because the former criteria will be matched every time. In the example below, the latter should be moved above the former.

    Code:
             ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
                 dblMisc += dblNutsAndBoltsKit
                 intMisc3 = CInt(chkNutsAndBoltsKit.Text)
    
             ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
                 dblMisc += dblNutsAndBoltsKit
                 intMisc4 = CInt(chkNutsAndBoltsKit.Text)

    Comment

    • rollerbladegirl
      New Member
      • Jan 2020
      • 69

      #3
      Is that in .net?

      It has been a while since I programmed in visual basic 4 / 5 / 6, but I do not remember stuff like
      lstMisc.Items.A dd
      except if the lstMisc was a name of a form.

      Shouldn't the post be moved to the .NET forum?

      Comment

      • Otekpo Emmanuel
        New Member
        • Dec 2013
        • 23

        #4
        All you have to do is make reference to the destination form.
        Lets say
        Code:
        Form2.ListBox1.Items.Add(Me.CheckBox1.Text)
        Please give feedback

        Comment

        Working...