B
Brian
I am very new to VB.NET and I just need some help in a listbox matter. I
don't need suggestions on how to make the overall code better. I will get
there.
I want to move an item from one list box to another should it be selected in
combination with a button click and selected. I've got the code in there but
it just wont work. Below is the entire code but I only need help with the
following items:
getBtn
inventoryList
itemsList
This is a simple text adventure that I am starting. I just need to know why
the item wont appear in inventoryList when the proper item is selected in
itemsList and the getBtn is used.
Thanks!
Public Class Form1
Inherits System.Windows.Forms.Form
Dim currentLocation As String
Dim livingRoomDesc As String
Dim wigwamexists As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(208, 176)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "North"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(136, 200)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 6
Me.Button2.Text = "West"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(208, 224)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 7
Me.Button3.Text = "South"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(280, 200)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 8
Me.Button4.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn,
Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.Button4, Me.Button3,
Me.Button2, Me.Button1, Me.Label3, Me.Label2, Me.itemsList,
Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
Dim lecroneLivingRoom As New room()
lecroneLivingRoom.desc = "You are in the Lecrone Living Room"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwamexists = True
If wigwamexists = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getBtn.Click
If currentLocation = "livingRoom" And wigwamexists = True Then
itemsList.SelectedItem = "wigwam"
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwamexists = False
End If
End Sub
End Class
don't need suggestions on how to make the overall code better. I will get
there.
I want to move an item from one list box to another should it be selected in
combination with a button click and selected. I've got the code in there but
it just wont work. Below is the entire code but I only need help with the
following items:
getBtn
inventoryList
itemsList
This is a simple text adventure that I am starting. I just need to know why
the item wont appear in inventoryList when the proper item is selected in
itemsList and the getBtn is used.
Thanks!
Public Class Form1
Inherits System.Windows.Forms.Form
Dim currentLocation As String
Dim livingRoomDesc As String
Dim wigwamexists As Boolean
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(208, 176)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 5
Me.Button1.Text = "North"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(136, 200)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 6
Me.Button2.Text = "West"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(208, 224)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 7
Me.Button3.Text = "South"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(280, 200)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 8
Me.Button4.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn,
Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.Button4, Me.Button3,
Me.Button2, Me.Button1, Me.Label3, Me.Label2, Me.itemsList,
Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
Dim lecroneLivingRoom As New room()
lecroneLivingRoom.desc = "You are in the Lecrone Living Room"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwamexists = True
If wigwamexists = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getBtn.Click
If currentLocation = "livingRoom" And wigwamexists = True Then
itemsList.SelectedItem = "wigwam"
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwamexists = False
End If
End Sub
End Class