By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

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

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. Public Class MainForm
  2.     Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
  3.         lblDeck.Text = String.Empty
  4.         lblTrucks.Text = String.Empty
  5.         lblWheels.Text = String.Empty
  6.         lblSubtotal.Text = String.Empty
  7.         lblTax.Text = String.Empty
  8.         lblTotal.Text = String.Empty
  9.     End Sub
  10.  
  11.     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  12.         Me.Close()
  13.     End Sub
  14.  
  15.     Private Sub btnClearMisc_Click(sender As Object, e As EventArgs) Handles btnClearMisc.Click
  16.         lstMisc.Items.Clear()
  17.     End Sub
  18.  
  19.     Private Sub btnViewDecks_Click(sender As Object, e As EventArgs) Handles btnViewDecks.Click
  20.         frmDecks.ShowDialog()
  21.     End Sub
  22.  
  23.     Private Sub btnViewTrucks_Click(sender As Object, e As EventArgs) Handles btnViewTrucks.Click
  24.         frmTrucks.ShowDialog()
  25.     End Sub
  26.  
  27.     Private Sub btnViewWheels_Click(sender As Object, e As EventArgs) Handles btnViewWheels.Click
  28.         frmWheels.ShowDialog()
  29.     End Sub
  30.  
  31.     Private Sub btnViewMisc_Click(sender As Object, e As EventArgs) Handles btnViewMisc.Click
  32.         frmMisc.ShowDialog()
  33.     End Sub
  34.  
  35.     Private Sub MainForm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
  36.         lstMisc.Items.Add(intMisc1)
  37.         lstMisc.Items.Add(intMisc2)
  38.         lstMisc.Items.Add(intMisc3)
  39.         lstMisc.Items.Add(intMisc4)
  40.         lstMisc.Items.Add(intMisc5)
  41.     End Sub
  42. End Class
Expand|Select|Wrap|Line Numbers
  1. Module ChargesModule
  2.  
  3.     ' Global constants
  4.     Public frmDecks As New DecksForm
  5.     Public frmMain As New MainForm
  6.     Public frmMisc As New MiscForm
  7.     Public frmTrucks As New TrucksForm
  8.     Public frmWheels As New WheelsForm
  9.     Public dblDeck As Double
  10.     Public dblTrucks As Double
  11.     Public dblWheels As Double
  12.     Public dblMisc As Double
  13.     Public dblSubtotal As Double
  14.     Public dblTax As Double
  15.     Public dblTotal As Double
  16.     Public int51mm As Integer = 0
  17.     Public int55mm As Integer = 1
  18.     Public int58mm As Integer = 2
  19.     Public int61mm As Integer = 3
  20.     Public dbl51mm As Double = 20
  21.     Public dbl55mm As Double = 22
  22.     Public dbl58mm As Double = 24
  23.     Public dbl61mm As Double = 28
  24.     Public intAxle1 As Integer = 0
  25.     Public intAxle2 As Integer = 1
  26.     Public intAxle3 As Integer = 2
  27.     Public dblAxle1 As Double = 35
  28.     Public dblAxle2 As Double = 40
  29.     Public dblAxle3 As Double = 45
  30.     Public intDeck1 As Integer = 0
  31.     Public intDeck2 As Integer = 1
  32.     Public intDeck3 As Integer = 2
  33.     Public dblMasterThrasher As Double = 60
  34.     Public dblDictatorOfGrind As Double = 45
  35.     Public dblStreetKing As Double = 50
  36.     Public dblGripTape As Double = 10
  37.     Public dblBearings As Double = 30
  38.     Public dblRiserPads As Double = 2
  39.     Public dblNutsAndBoltsKit As Double = 3
  40.     Public dblAssembly As Double = 10
  41.     Public intMisc1 As Integer
  42.     Public intMisc2 As Integer
  43.     Public intMisc3 As Integer
  44.     Public intMisc4 As Integer
  45.     Public intMisc5 As Integer
  46.     Public intGripTape As Integer
  47.     Public intBearings As Integer
  48.     Public intRiserPads As Integer
  49.     Public intNutsAndBoltsKit As Integer
  50.     Public intAssembly As Integer
  51. End Module
Expand|Select|Wrap|Line Numbers
  1. Public Class MiscForm
  2.     Private Sub btnAdd_Click(sender As Object, e As EventArgs)
  3.  
  4.         If chkGripTape.Checked = True Then
  5.             dblMisc += dblGripTape
  6.             intMisc1 = CInt(chkGripTape.Text)
  7.         End If
  8.  
  9.         If chkBearings.Checked = True Then
  10.             dblMisc += dblBearings
  11.             intMisc1 = CInt(chkBearings.Text)
  12.         ElseIf intMisc1 = intGripTape Then
  13.             dblMisc += dblBearings
  14.             intMisc2 = CInt(chkBearings.Text)
  15.         End If
  16.  
  17.         If chkRiserPads.Checked = True Then
  18.             dblMisc += dblRiserPads
  19.             intMisc1 = CInt(chkRiserPads.Text)
  20.         ElseIf intMisc1 = intBearings Then
  21.             dblMisc += dblRiserPads
  22.             intMisc2 = CInt(chkRiserPads.Text)
  23.         ElseIf intMisc1 = intGripTape Then
  24.             dblMisc += dblRiserPads
  25.             intMisc2 = CInt(chkRiserPads.Text)
  26.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
  27.             dblMisc += dblRiserPads
  28.             intMisc3 = CInt(chkRiserPads.Text)
  29.         End If
  30.  
  31.         If chkNutsAndBoltsKit.Checked = True Then
  32.             dblMisc += dblNutsAndBoltsKit
  33.             intMisc1 = CInt(chkNutsAndBoltsKit.Text)
  34.         ElseIf intMisc1 = intBearings Then
  35.             dblMisc += dblNutsAndBoltsKit
  36.             intMisc2 = CInt(chkNutsAndBoltsKit.Text)
  37.         ElseIf intMisc1 = intGripTape Then
  38.             dblMisc += dblNutsAndBoltsKit
  39.             intMisc2 = CInt(chkNutsAndBoltsKit.Text)
  40.         ElseIf intMisc1 = intRiserPads Then
  41.             dblMisc += dblNutsAndBoltsKit
  42.             intMisc2 = CInt(chkNutsAndBoltsKit.Text)
  43.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
  44.             dblMisc += dblNutsAndBoltsKit
  45.             intMisc3 = CInt(chkNutsAndBoltsKit.Text)
  46.         ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads Then
  47.             dblMisc += dblNutsAndBoltsKit
  48.             intMisc3 = CInt(chkNutsAndBoltsKit.Text)
  49.         ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads Then
  50.             dblMisc += dblNutsAndBoltsKit
  51.             intMisc3 = CInt(chkNutsAndBoltsKit.Text)
  52.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
  53.             dblMisc += dblNutsAndBoltsKit
  54.             intMisc4 = CInt(chkNutsAndBoltsKit.Text)
  55.         End If
  56.  
  57.         If chkAssembly.Checked = True Then
  58.             dblMisc += dblAssembly
  59.             intMisc1 = CInt(chkAssembly.Text)
  60.         ElseIf intMisc1 = intBearings Then
  61.             dblMisc += dblAssembly
  62.             intMisc2 = CInt(chkAssembly.Text)
  63.         ElseIf intMisc1 = intGripTape Then
  64.             dblMisc += dblAssembly
  65.             intMisc2 = CInt(chkAssembly.Text)
  66.         ElseIf intMisc1 = intRiserPads Then
  67.             dblMisc += dblAssembly
  68.             intMisc2 = CInt(chkAssembly.Text)
  69.         ElseIf intMisc1 = intNutsAndBoltsKit Then
  70.             dblMisc += dblAssembly
  71.             intMisc2 = CInt(chkAssembly.Text)
  72.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
  73.             dblMisc += dblAssembly
  74.             intMisc3 = CInt(chkAssembly.Text)
  75.         ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads Then
  76.             dblMisc += dblAssembly
  77.             intMisc3 = CInt(chkAssembly.Text)
  78.         ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads Then
  79.             dblMisc += dblAssembly
  80.             intMisc3 = CInt(chkAssembly.Text)
  81.         ElseIf intMisc1 = intGripTape And intMisc2 = intNutsAndBoltsKit Then
  82.             dblMisc += dblAssembly
  83.             intMisc3 = CInt(chkAssembly.Text)
  84.         ElseIf intMisc1 = intBearings And intMisc2 = intNutsAndBoltsKit Then
  85.             dblMisc += dblAssembly
  86.             intMisc3 = CInt(chkAssembly.Text)
  87.         ElseIf intMisc1 = intRiserPads And intMisc2 = intNutsAndBoltsKit Then
  88.             dblMisc += dblAssembly
  89.             intMisc3 = CInt(chkAssembly.Text)
  90.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
  91.             dblMisc += dblAssembly
  92.             intMisc4 = CInt(chkAssembly.Text)
  93.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intNutsAndBoltsKit Then
  94.             dblMisc += dblAssembly
  95.             intMisc4 = CInt(chkAssembly.Text)
  96.         ElseIf intMisc1 = intGripTape And intMisc2 = intRiserPads And intMisc3 = intNutsAndBoltsKit Then
  97.             dblMisc += dblAssembly
  98.             intMisc4 = CInt(chkAssembly.Text)
  99.         ElseIf intMisc1 = intBearings And intMisc2 = intRiserPads And intMisc3 = intNutsAndBoltsKit Then
  100.             dblMisc += dblAssembly
  101.             intMisc4 = CInt(chkAssembly.Text)
  102.         ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads And intMisc4 = intNutsAndBoltsKit Then
  103.             dblMisc += dblAssembly
  104.             intMisc5 = CInt(chkAssembly.Text)
  105.         End If
  106.     End Sub
  107. End Class
2 Weeks Ago #1
Share this Question
Share on Google+
2 Replies


100+
P: 300
You just need to explicitly specify the additional form name before the array or variable.
Expand|Select|Wrap|Line Numbers
  1. 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.

Expand|Select|Wrap|Line Numbers
  1.          ElseIf intMisc1 = intGripTape And intMisc2 = intBearings Then
  2.              dblMisc += dblNutsAndBoltsKit
  3.              intMisc3 = CInt(chkNutsAndBoltsKit.Text)
  4.  
  5.          ElseIf intMisc1 = intGripTape And intMisc2 = intBearings And intMisc3 = intRiserPads Then
  6.              dblMisc += dblNutsAndBoltsKit
  7.              intMisc4 = CInt(chkNutsAndBoltsKit.Text)
  8.  
1 Week Ago #2

rollerbladegirl
P: 69
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.Add
except if the lstMisc was a name of a form.

Shouldn't the post be moved to the .NET forum?
1 Week Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.