Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - New Collection() Error.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

New Collection() Error.

 Post Reply Post Reply
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: New Collection() Error.
    Posted: 20 August 2004 at 2:55pm
Grrr...Just got redirected off this page and have to run to my other job, so everything I typed got wiped out. But basically, if anyone sees an error in this I'd appreciate your help, for some reason its finding Collection() as undefined.

Code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb

Public Class DataList
  Inherits Page

Private Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Dim colFruit As New Collection()
  colFruit.Add("Kiwi")
  colFruit.Add("Pear")
  colFruit.Add("Mango")
  colFruit.Add("Blueberry")
  colFruit.Add("Apricot")
  colFruit.Add("Banana")
  colFruit.Add("Peach")
  colFruit.Add("Plum")
  lstItems.DataSource=colFruit
  Me.DataBind()
  ' Could use lstItems.DataBind() to bind just the list box.
End Sub

End Class

Error:
Compiler Error Message:
BC30002: Type 'Collection' is not defined.

Source Error:


Line 11: 
Line 12: Private Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Line 13: Dim colFruit As New Collection()
Line 14: colFruit.Add("Kiwi")
Line 15: colFruit.Add("Pear")
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 20 August 2004 at 3:10pm

Just put Imports System.Collections at the top with the other Imports statements

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 20 August 2004 at 4:02pm

But you don't need parenthesis, adding parenthesis makes it an array of collections, from the look of your code you only want 1 collection so it should be:

Dim colFruit As New Collection

 

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2004 at 1:25pm
Thanks for the advice...and I think that helped, but I am still receiving the same error.
David.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2004 at 4:42pm
The code is fine,  you must have the problem somewhere else, that it's throwing it there
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2004 at 5:10pm

Try Importing these namespaces:

System.ComponentModel
System.ComponentModel.Design
System.ComponentModel.Design.Serialization

Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2004 at 11:09am
Well, it ended up there were a number of errors in my code. Here is the code after repair for anyone who is interested. There were also two errors in the call for the code-behind. :-P Thanks for your help.
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb

Public Class Database
    Inherits Page
    Protected lstUser As ListBox ' Was not set previously.
Private Sub Page_Load (sender As Object, e as EventArgs) Handles MyBase.Load ' Was mistitled Private Class.
    ' Define a DataSet with a single DataTable.
    Dim dsInternal as New DataSet()
    dsInternal.Tables.Add("Users")

    ' Define two columns for this table.
    dsInternal.Tables("Users").Columns.Add("Name")
    dsInternal.Tables("Users").Columns.Add("Country")

    ' Add some actual information into the table.
    Dim rowNew as DataRow
    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "John"
    rowNew("Country") = "Uganda"
    dsInternal.Tables("Users").Rows.Add(rowNew)

    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "Samantha"
    rowNew("Country") = "Belgium"
    dsInternal.Tables("Users").Rows.Add(rowNew)

    rowNew = dsInternal.Tables("Users").NewRow()
    rowNew("Name") = "Rico"
    rowNew("Country") = "Japan"
    dsInternal.Tables("Users").Rows.Add(rowNew) ' Was missing closing ' quotation mark.

    ' Define the binding.
    lstUser.DataSource = dsInternal.Tables("Users")
    lstUser.DataTextField = "Name"

    Me.DataBind()
End Sub

End Class

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.