Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Error with Dynamic Coding in VB

mattneedmattneed Posts: 1Member
Ok so this is whats going on. Ive created several buttons by code because im making a program that has buttons that change when you select a menu item. I was having a handles error but finally figured out how to fix it :D. So now my issue is, is when i try to put code into my dynamic button the code wont work. Can you please tell me what im doing wrong :D[code]Public Class Form1
Public WithEvents barb As System.Windows.Forms.Button
' Pirate Bosses Menu Tab
Dim piratebosseslbl As New Label()
Dim emanuel As New Button()
Dim caterina As New Button()
Dim dampier As New Button()
Dim rajah As New Button()
Dim stutebaker As New Button()
Dim drake As New Button()
Dim tew As New Button()
Dim toan As New Button()
Dim laces As New Button()
Dim teach As New Button()
Dim oji As New Button()
Dim kidd As New Button()
Dim shiro As New Button()
Dim shariwa As New Button()
Dim gotheborg As New Button()
Dim roberts As New Button()
Dim hawkins As New Button()
Dim will As New Button()
Dim cruz As New Button()

' Ship Info Tab

' Merchant Ship

Dim Level1MS As New Button()
Dim Level2MS As New Button()
Dim Level3MS As New Button()
Dim Level4MS As New Button()
Dim Level5MS As New Button()
Dim Level6MS As New Button()
Dim Level7MS As New Button()
Dim Level8MS As New Button()
Dim Level9MS As New Button()
Dim Level10MS As New Button()
Dim Level10halfMS As New Button()
Dim Level11MS As New Button()

' Battle Ships

Dim Level1BS As New Button()
Dim Level2BS As New Button()
Dim Level3BS As New Button()
Dim Level4BS As New Button()
Dim Level5BS As New Button()
Dim Level6BS As New Button()
Dim Level7BS As New Button()
Dim Level8BS As New Button()
Dim Level9BS As New Button()
Dim Level10BS As New Button()
Dim Level10halfBS As New Button()
Dim Level11BS As New Button()

'Raiding Ships

Dim Level1AS As New Button()
Dim Level2AS As New Button()
Dim Level3AS As New Button()
Dim Level4AS As New Button()
Dim Level5AS As New Button()
Dim Level6AS As New Button()
Dim Level7AS As New Button()
Dim Level8AS As New Button()
Dim Level9AS As New Button()
Dim Level10AS As New Button()
Dim Level10halfAS As New Button()
Dim Level11AS As New Button()
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
AboutBox1.Show()
End Sub

Private Sub ShipRebuildingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShipRebuildingToolStripMenuItem.Click
Level1MS.Text = "Level 1 Merchant"
Level2MS.Text = "Level 2 Merchant"
Level3MS.Text = "Level 3 Merchant"
Level4MS.Text = "Level 4 Merchant"
Level5MS.Text = "Level 5 Merchant"
Level6MS.Text = "Level 6 Merchant"
Level7MS.Text = "Level 7 Merchant"
Level8MS.Text = "Level 8 Merchant"
Level9MS.Text = "Level 9 Merchant"
Level10MS.Text = "Level 10 Merchant"
Level10halfMS.Text = "Level 10.5 Merchant"
Level11MS.Text = "Level 11 Merchant"
Level1BS.Text = "Level 1 Battleship"
Level2BS.Text = "Level 2 Battleship"
Level3BS.Text = "Level 3 Battleship"
Level4BS.Text = "Level 4 Battleship"
Level5BS.Text = "Level 5 Battleship"
Level6BS.Text = "Level 6 Battleship"
Level7BS.Text = "Level 7 Battleship"
Level8BS.Text = "Level 8 Battleship"
Level9BS.Text = "Level 9 Battleship"
Level10BS.Text = "Level 10 Battleship"
Level10halfBS.Text = "Level 10.5 Battleship"
Level11BS.Text = "Level 11 Battleship"
Level1AS.Text = "Level 1 Raider"
Level2AS.Text = "Level 2 Raider"
Level3AS.Text = "Level 3 Raider"
Level4AS.Text = "Level 4 Raider"
Level5AS.Text = "Level 5 Raider"
Level6AS.Text = "Level 6 Raider"
Level7AS.Text = "Level 7 Raider"
Level8AS.Text = "Level 8 Raider"
Level9AS.Text = "Level 9 Raider"
Level10AS.Text = "Level 10 Raider"
Level10halfAS.Text = "Level 10.5 Raider"
Level11AS.Text = "Level 11 Raider"
Level1MS.Location = New Point(50, 75)
Level2MS.Location = New Point(50, 100)
Level3MS.Location = New Point(50, 125)
Level4MS.Location = New Point(50, 150)
Level5MS.Location = New Point(50, 175)
Level6MS.Location = New Point(50, 200)
Level7MS.Location = New Point(50, 225)
Level8MS.Location = New Point(50, 250)
Level9MS.Location = New Point(50, 275)
Level10MS.Location = New Point(50, 300)
Level10halfMS.Location = New Point(50, 325)
Level11MS.Location = New Point(50, 350)
Level1BS.Location = New Point(200, 75)
Level2BS.Location = New Point(200, 100)
Level3BS.Location = New Point(200, 125)
Level4BS.Location = New Point(200, 150)
Level5BS.Location = New Point(200, 175)
Level6BS.Location = New Point(200, 200)
Level7BS.Location = New Point(200, 225)
Level8BS.Location = New Point(200, 250)
Level9BS.Location = New Point(200, 275)
Level10BS.Location = New Point(200, 300)
Level10halfBS.Location = New Point(200, 325)
Level11BS.Location = New Point(200, 350)
Level1AS.Location = New Point(350, 75)
Level2AS.Location = New Point(350, 100)
Level3AS.Location = New Point(350, 125)
Level4AS.Location = New Point(350, 150)
Level5AS.Location = New Point(350, 175)
Level6AS.Location = New Point(350, 200)
Level7AS.Location = New Point(350, 225)
Level8AS.Location = New Point(350, 250)
Level9AS.Location = New Point(350, 275)
Level10AS.Location = New Point(350, 300)
Level10halfAS.Location = New Point(350, 325)
Level11AS.Location = New Point(350, 350)
Level1MS.Size = New Size(120, 23)
Level2MS.Size = New Size(120, 23)
Level3MS.Size = New Size(120, 23)
Level4MS.Size = New Size(120, 23)
Level5MS.Size = New Size(120, 23)
Level6MS.Size = New Size(120, 23)
Level7MS.Size = New Size(120, 23)
Level8MS.Size = New Size(120, 23)
Level9MS.Size = New Size(120, 23)
Level10MS.Size = New Size(120, 23)
Level10halfMS.Size = New Size(120, 23)
Level11MS.Size = New Size(120, 23)
Level1BS.Size = New Size(120, 23)
Level2BS.Size = New Size(120, 23)
Level3BS.Size = New Size(120, 23)
Level4BS.Size = New Size(120, 23)
Level5BS.Size = New Size(120, 23)
Level6BS.Size = New Size(120, 23)
Level7BS.Size = New Size(120, 23)
Level8BS.Size = New Size(120, 23)
Level9BS.Size = New Size(120, 23)
Level10BS.Size = New Size(120, 23)
Level10halfBS.Size = New Size(120, 23)
Level11BS.Size = New Size(120, 23)
Level1AS.Size = New Size(120, 23)
Level2AS.Size = New Size(120, 23)
Level3AS.Size = New Size(120, 23)
Level4AS.Size = New Size(120, 23)
Level5AS.Size = New Size(120, 23)
Level6AS.Size = New Size(120, 23)
Level7AS.Size = New Size(120, 23)
Level8AS.Size = New Size(120, 23)
Level9AS.Size = New Size(120, 23)
Level10AS.Size = New Size(120, 23)
Level10halfAS.Size = New Size(120, 23)
Level11AS.Size = New Size(120, 23)
Me.Controls.Add(Level1MS)
Me.Controls.Add(Level2MS)
Me.Controls.Add(Level3MS)
Me.Controls.Add(Level4MS)
Me.Controls.Add(Level5MS)
Me.Controls.Add(Level6MS)
Me.Controls.Add(Level7MS)
Me.Controls.Add(Level8MS)
Me.Controls.Add(Level9MS)
Me.Controls.Add(Level10MS)
Me.Controls.Add(Level10halfMS)
Me.Controls.Add(Level11MS)
Me.Controls.Add(Level1BS)
Me.Controls.Add(Level2BS)
Me.Controls.Add(Level3BS)
Me.Controls.Add(Level4BS)
Me.Controls.Add(Level5BS)
Me.Controls.Add(Level6BS)
Me.Controls.Add(Level7BS)
Me.Controls.Add(Level8BS)
Me.Controls.Add(Level9BS)
Me.Controls.Add(Level10BS)
Me.Controls.Add(Level10halfBS)
Me.Controls.Add(Level11BS)
Me.Controls.Add(Level1AS)
Me.Controls.Add(Level2AS)
Me.Controls.Add(Level3AS)
Me.Controls.Add(Level4AS)
Me.Controls.Add(Level5AS)
Me.Controls.Add(Level6AS)
Me.Controls.Add(Level7AS)
Me.Controls.Add(Level8AS)
Me.Controls.Add(Level9AS)
Me.Controls.Add(Level10AS)
Me.Controls.Add(Level10halfAS)
Me.Controls.Add(Level11AS)
End Sub

Private Sub PirateBossesInfoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PirateBossesInfoToolStripMenuItem.Click

Dim barb As New Button()
' Label for the Tab

piratebosseslbl.Text = "Pirate Bosses Info"
piratebosseslbl.Location = New Point(50, 50)
piratebosseslbl.Size = New Size(100, 18)
Me.Controls.Add(piratebosseslbl)

' Stating the Text on the buttons

barb.Text = "Barbarossa II"
emanuel.Text = "Emanuel Wynne"
caterina.Text = "Don Esteba Caterina"
dampier.Text = "William Dampier"
rajah.Text = "Ali Rajah"
stutebaker.Text = "Klaus Stortebeker"
drake.Text = "Francis Drake"
tew.Text = "Thomas Tew"
toan.Text = "Murayama Toan"
laces.Text = "Hilton Laces"
teach.Text = "Edward Teach"
oji.Text = "Oji"
kidd.Text = "William Kidd"
shiro.Text = "Tokisada Amakusa Shiro"
shariwa.Text = "Kanyi Shariwa"
gotheborg.Text = "Gotheborg"
roberts.Text = "Bartholomew Roberts"
hawkins.Text = "John Hawkins"
will.Text = "General Charlie Will"
cruz.Text = "General Cruz"

' Declaring where the button needs to be places

barb.Location = New Point(50, 75)
emanuel.Location = New Point(50, 100)
caterina.Location = New Point(50, 125)
dampier.Location = New Point(50, 150)
rajah.Location = New Point(50, 175)
stutebaker.Location = New Point(50, 200)
drake.Location = New Point(50, 225)
tew.Location = New Point(50, 250)
toan.Location = New Point(50, 275)
laces.Location = New Point(50, 300)
teach.Location = New Point(50, 325)
oji.Location = New Point(50, 350)
kidd.Location = New Point(50, 375)
shiro.Location = New Point(50, 400)
shariwa.Location = New Point(50, 425)
gotheborg.Location = New Point(50, 450)
roberts.Location = New Point(50, 475)
hawkins.Location = New Point(50, 500)
will.Location = New Point(50, 525)
cruz.Location = New Point(50, 550)

'Declaring The size of the Buttons

barb.Size = New Size(120, 23)
emanuel.Size = New Size(120, 23)
caterina.Size = New Size(120, 23)
dampier.Size = New Size(120, 23)
rajah.Size = New Size(120, 23)
stutebaker.Size = New Size(120, 23)
drake.Size = New Size(120, 23)
tew.Size = New Size(120, 23)
toan.Size = New Size(120, 23)
laces.Size = New Size(120, 23)
teach.Size = New Size(120, 23)
oji.Size = New Size(120, 23)
kidd.Size = New Size(120, 23)
shiro.Size = New Size(120, 23)
shariwa.Size = New Size(120, 23)
gotheborg.Size = New Size(120, 23)
roberts.Size = New Size(120, 23)
hawkins.Size = New Size(120, 23)
will.Size = New Size(120, 23)
cruz.Size = New Size(120, 23)

' Declaring the buttons to make them show on the form

Me.Controls.Add(barb)
Me.Controls.Add(emanuel)
Me.Controls.Add(caterina)
Me.Controls.Add(dampier)
Me.Controls.Add(rajah)
Me.Controls.Add(stutebaker)
Me.Controls.Add(drake)
Me.Controls.Add(tew)
Me.Controls.Add(toan)
Me.Controls.Add(laces)
Me.Controls.Add(teach)
Me.Controls.Add(oji)
Me.Controls.Add(kidd)
Me.Controls.Add(shiro)
Me.Controls.Add(shariwa)
Me.Controls.Add(gotheborg)
Me.Controls.Add(roberts)
Me.Controls.Add(hawkins)
Me.Controls.Add(will)
Me.Controls.Add(cruz)

End Sub
Private Sub barb_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles barb.Click
barb.Text = "test"
Dim test As New Button()
test.Text = "test"
test.Location = New Point(150, 200)
test.Size = New Size(200, 200)
Me.Controls.Add(test)

End Sub
End Class
[/code]
Sign In or Register to comment.