listbox undeclared.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glam rose
    New Member
    • Dec 2011
    • 2

    listbox undeclared.

    I KEEP GETTING THIS ERROR
    ListBox1 clear undeclared

    please kindly look through my coding.


    Private Sub Button6_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button6.Click
    Dim X As Integer
    Dim Y As Integer
    Dim multiplication As Integer


    X = CInt(TextBox1.T ext)
    Y = CInt(TextBox2.T ext)

    For X = 1 To 12
    multiplication = X * Y
    ListBox1.Items. Add(X & "X" & Y & "=" & multiplication)

    Next
    End Sub
    End Class
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It means that you don't have an object with the name ListBox1

    Comment

    • glam rose
      New Member
      • Dec 2011
      • 2

      #3
      Please teach me how can i declared it.
      here is my full command.


      <Global.Microso ft.VisualBasic. CompilerService s.DesignerGener ated()> _
      Partial Class Form1
      Inherits System.Windows. Forms.Form

      'Form overrides dispose to clean up the component list.
      <System.Diagnos tics.DebuggerNo nUserCode()> _
      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
      Try
      If disposing AndAlso components IsNot Nothing Then
      components.Disp ose()
      End If
      Finally
      MyBase.Dispose( disposing)
      End Try
      End Sub

      'Required by the Windows Form Designer
      Private components As System.Componen tModel.IContain er

      '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.
      <System.Diagnos tics.DebuggerSt epThrough()> _
      Private Sub InitializeCompo nent()
      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.TextBox1 = New System.Windows. Forms.TextBox
      Me.TextBox2 = New System.Windows. Forms.TextBox
      Me.Label1 = New System.Windows. Forms.Label
      Me.Label2 = New System.Windows. Forms.Label
      Me.TextBox3 = New System.Windows. Forms.TextBox
      Me.Button5 = New System.Windows. Forms.Button
      Me.Button6 = New System.Windows. Forms.Button
      Me.Button7 = New System.Windows. Forms.Button
      Me.Button8 = New System.Windows. Forms.Button
      Me.Button9 = New System.Windows. Forms.Button
      Me.Button10 = New System.Windows. Forms.Button
      Me.SuspendLayou t()
      '
      'Button1
      '
      Me.Button1.Loca tion = New System.Drawing. Point(214, 32)
      Me.Button1.Name = "Button1"
      Me.Button1.Size = New System.Drawing. Size(45, 22)
      Me.Button1.TabI ndex = 0
      Me.Button1.Text = "<<"
      Me.Button1.UseV isualStyleBackC olor = True
      '
      'Button2
      '
      Me.Button2.Loca tion = New System.Drawing. Point(214, 68)
      Me.Button2.Name = "Button2"
      Me.Button2.Size = New System.Drawing. Size(45, 23)
      Me.Button2.TabI ndex = 1
      Me.Button2.Text = "<<"
      Me.Button2.UseV isualStyleBackC olor = True
      '
      'Button3
      '
      Me.Button3.Loca tion = New System.Drawing. Point(265, 31)
      Me.Button3.Name = "Button3"
      Me.Button3.Size = New System.Drawing. Size(42, 24)
      Me.Button3.TabI ndex = 2
      Me.Button3.Text = ">>"
      Me.Button3.UseV isualStyleBackC olor = True
      '
      'Button4
      '
      Me.Button4.Loca tion = New System.Drawing. Point(265, 68)
      Me.Button4.Name = "Button4"
      Me.Button4.Size = New System.Drawing. Size(42, 23)
      Me.Button4.TabI ndex = 3
      Me.Button4.Text = ">>"
      Me.Button4.UseV isualStyleBackC olor = True
      '
      'TextBox1
      '
      Me.TextBox1.Loc ation = New System.Drawing. Point(90, 31)
      Me.TextBox1.Nam e = "TextBox1"
      Me.TextBox1.Siz e = New System.Drawing. Size(100, 20)
      Me.TextBox1.Tab Index = 4
      '
      'TextBox2
      '
      Me.TextBox2.Loc ation = New System.Drawing. Point(90, 66)
      Me.TextBox2.Nam e = "TextBox2"
      Me.TextBox2.Siz e = New System.Drawing. Size(100, 20)
      Me.TextBox2.Tab Index = 5
      '
      'Label1
      '
      Me.Label1.AutoS ize = True
      Me.Label1.Locat ion = New System.Drawing. Point(30, 32)
      Me.Label1.Name = "Label1"
      Me.Label1.Size = New System.Drawing. Size(14, 13)
      Me.Label1.TabIn dex = 6
      Me.Label1.Text = "X"
      '
      'Label2
      '
      Me.Label2.AutoS ize = True
      Me.Label2.Locat ion = New System.Drawing. Point(30, 73)
      Me.Label2.Name = "Label2"
      Me.Label2.Size = New System.Drawing. Size(14, 13)
      Me.Label2.TabIn dex = 7
      Me.Label2.Text = "Y"
      '
      'TextBox3
      '
      Me.TextBox3.Fon t = New System.Drawing. Font("Lucida Fax", 8.25!, System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.TextBox3.For eColor = System.Drawing. Color.DarkSlate Gray
      Me.TextBox3.Loc ation = New System.Drawing. Point(33, 122)
      Me.TextBox3.Mul tiline = True
      Me.TextBox3.Nam e = "TextBox3"
      Me.TextBox3.Siz e = New System.Drawing. Size(154, 247)
      Me.TextBox3.Tab Index = 8
      '
      'Button5
      '
      Me.Button5.Font = New System.Drawing. Font("Microsoft Sans Serif", 8.25!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button5.Fore Color = System.Drawing. Color.DarkRed
      Me.Button5.Loca tion = New System.Drawing. Point(193, 122)
      Me.Button5.Name = "Button5"
      Me.Button5.Size = New System.Drawing. Size(127, 23)
      Me.Button5.TabI ndex = 9
      Me.Button5.Text = "Clear All"
      Me.Button5.UseV isualStyleBackC olor = True
      '
      'Button6
      '
      Me.Button6.Font = New System.Drawing. Font("Microsoft Sans Serif", 8.25!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button6.Fore Color = System.Drawing. Color.Crimson
      Me.Button6.Loca tion = New System.Drawing. Point(193, 151)
      Me.Button6.Name = "Button6"
      Me.Button6.Size = New System.Drawing. Size(127, 23)
      Me.Button6.TabI ndex = 10
      Me.Button6.Text = "Get multiplication"
      Me.Button6.UseV isualStyleBackC olor = True
      '
      'Button7
      '
      Me.Button7.Font = New System.Drawing. Font("Microsoft Sans Serif", 8.25!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button7.Fore Color = System.Drawing. SystemColors.Ho tTrack
      Me.Button7.Loca tion = New System.Drawing. Point(193, 180)
      Me.Button7.Name = "Button7"
      Me.Button7.Size = New System.Drawing. Size(127, 23)
      Me.Button7.TabI ndex = 11
      Me.Button7.Text = "Total from X to Y"
      Me.Button7.UseV isualStyleBackC olor = True
      '
      'Button8
      '
      Me.Button8.Font = New System.Drawing. Font("Microsoft Sans Serif", 8.25!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button8.Fore Color = System.Drawing. Color.DarkSlate Blue
      Me.Button8.Loca tion = New System.Drawing. Point(193, 209)
      Me.Button8.Name = "Button8"
      Me.Button8.Size = New System.Drawing. Size(127, 23)
      Me.Button8.TabI ndex = 12
      Me.Button8.Text = "Show odd Number"
      Me.Button8.UseV isualStyleBackC olor = True
      '
      'Button9
      '
      Me.Button9.Font = New System.Drawing. Font("Microsoft Sans Serif", 8.25!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button9.Fore Color = System.Drawing. Color.SeaGreen
      Me.Button9.Loca tion = New System.Drawing. Point(193, 238)
      Me.Button9.Name = "Button9"
      Me.Button9.Size = New System.Drawing. Size(125, 23)
      Me.Button9.TabI ndex = 13
      Me.Button9.Text = "Show even Number"
      Me.Button9.UseV isualStyleBackC olor = True
      '
      'Button10
      '
      Me.Button10.Fon t = New System.Drawing. Font("Microsoft Sans Serif", 15.75!, System.Drawing. FontStyle.Bold, System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
      Me.Button10.For eColor = System.Drawing. Color.Red
      Me.Button10.Loc ation = New System.Drawing. Point(193, 327)
      Me.Button10.Nam e = "Button10"
      Me.Button10.Siz e = New System.Drawing. Size(121, 42)
      Me.Button10.Tab Index = 14
      Me.Button10.Tex t = "Exit"
      Me.Button10.Use VisualStyleBack Color = True
      '
      'Form1
      '
      Me.AutoScaleDim ensions = New System.Drawing. SizeF(6.0!, 13.0!)
      Me.AutoScaleMod e = System.Windows. Forms.AutoScale Mode.Font
      Me.ClientSize = New System.Drawing. Size(338, 397)
      Me.Controls.Add (Me.Button10)
      Me.Controls.Add (Me.Button9)
      Me.Controls.Add (Me.Button8)
      Me.Controls.Add (Me.Button7)
      Me.Controls.Add (Me.Button6)
      Me.Controls.Add (Me.Button5)
      Me.Controls.Add (Me.TextBox3)
      Me.Controls.Add (Me.Label2)
      Me.Controls.Add (Me.Label1)
      Me.Controls.Add (Me.TextBox2)
      Me.Controls.Add (Me.TextBox1)
      Me.Controls.Add (Me.Button4)
      Me.Controls.Add (Me.Button3)
      Me.Controls.Add (Me.Button2)
      Me.Controls.Add (Me.Button1)
      Me.Name = "Form1"
      Me.Text = "Multiplication "
      Me.ResumeLayout (False)
      Me.PerformLayou t()

      End Sub
      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 TextBox1 As System.Windows. Forms.TextBox
      Friend WithEvents TextBox2 As System.Windows. Forms.TextBox
      Friend WithEvents Label1 As System.Windows. Forms.Label
      Friend WithEvents Label2 As System.Windows. Forms.Label
      Friend WithEvents TextBox3 As System.Windows. Forms.TextBox
      Friend WithEvents Button5 As System.Windows. Forms.Button
      Friend WithEvents Button6 As System.Windows. Forms.Button
      Friend WithEvents Button7 As System.Windows. Forms.Button
      Friend WithEvents Button8 As System.Windows. Forms.Button
      Friend WithEvents Button9 As System.Windows. Forms.Button
      Friend WithEvents Button10 As System.Windows. Forms.Button

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
      Dim X As Integer


      X = CInt(TextBox1.T ext)

      X = X - 1
      TextBox1.Text = X
      End Sub




      Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
      Dim X As Integer


      X = CInt(TextBox1.T ext)

      X = X + 1
      TextBox1.Text = X
      End Sub

      Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
      Dim Y As Integer

      Y = CInt(TextBox2.T ext)
      Y = Y - 1
      TextBox2.Text = Y

      End Sub


      Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button4.Click
      Dim Y As Integer

      Y = CInt(TextBox2.T ext)
      Y = Y + 1
      TextBox2.Text = Y

      End Sub




      Private Sub Button10_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button10.Click
      Me.Close()
      End Sub

      Private Sub Button6_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button6.Click
      Dim X As Integer
      Dim Y As Integer
      Dim multiplication As Integer


      X = CInt(TextBox1.T ext)
      Y = CInt(TextBox2.T ext)

      For X = 1 To 12
      multiplication = X * Y
      ListBox1.Items. Add(X & "X" & Y & "=" & multiplication)

      Next

      End Sub

      Private Sub Button5_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button5.Click
      ListBox1.Items. Clear()
      TextBox1.Text = ""
      TextBox2.Text = ""
      End Sub

      Private Sub Button7_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button7.Click
      Dim X As Integer
      Dim Y As Integer
      Dim total As Integer


      X = CInt(TextBox1.T ext)
      Y = CInt(TextBox2.T ext)

      For i = X To Y
      total = total + i
      Next
      ListBox1.Items. Add(total)
      End Sub

      Private Sub Button8_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button8.Click
      Dim num, X, Y As Integer


      X = CInt(TextBox1.T ext)
      Y = CInt(TextBox2.T ext)


      For num = X To Y
      If num Mod 2 <> 0 Then
      ListBox1.Items. Add(num)
      num = num + 1
      End If

      Next

      End Sub

      Private Sub Button9_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button9.Click
      Dim num, X, Y As Integer


      X = CInt(TextBox1.T ext)
      Y = CInt(TextBox2.T ext)


      For num = X To Y
      If num Mod 2 <> 1 Then
      ListBox1.Items. Add(num)
      num = num + 1
      End If
      Next

      End Sub
      End Class




      it started from button 5 .which includes clear list, get multiplication, get odd and even number and get total from X and Y.

      these all it said error of listbox undeclared. how can i declared it. please show me. thank you very much

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Im just getting back to coding after 2 years (less than 1 hour atm) so forgive me if this is wrong and im rusty.

        drag a listbox onto your form.
        Or add the code:

        Code:
         Dim listbox1 As ListBox

        Comment

        Working...