Polar Bear Posted April 7, 2006 Posted April 7, 2006 Hi, I created two classes, MenuItem.vb and MenuItemCollection.vb. The two files are in the same folder but for some reason the MenuItemCollection class cannot find the MenuItem class, and I get this error when I try to add the menu item to the collection. <%@ Assembly Src="MenuItem.vb" %> <%@ Assembly Src="MenuItemCollection.vb" %> <script language="VB" runat="server"> Sub Page_Load If Not IsPostBack Then Dim MenuItems = New MenuItemCollection() MenuItems.Add(New MenuItem(1, "Test")) End If End Sub BC30002: Type 'MenuItem' is not defined. Line 9: Public Sub Add(ByVal MenuItem As MenuItem) Line 10: Me.List.Add(MenuItem) Line 11: End Sub The detailed compiler output shows an error on all references to MenuItem. '=========== MenuItem.vb============== Public Class MenuItem Private m_MenuID As Integer Private m_Title As String Public Sub New() End Sub Public Sub New(ByVal MenuID As Integer, ByVal Title As String) With Me .m_MenuID = MenuID .m_Title = Title End With End Sub Public Property MenuID() As Integer Get Return m_MenuID End Get Set(ByVal Value As Integer) m_MenuID = Value End Set End Property Public Property Title() As String Get Return m_Title End Get Set(ByVal Value As String) m_Title = Value End Set End Property End Class '=========== MenuItemCollection.vb============== Imports System.Collections Public Class MenuItemCollection Inherits CollectionBase Public Sub New() End Sub Public Sub Add(ByVal MenuItem As MenuItem) Me.List.Add(MenuItem) End Sub Public Function Contains(ByVal MenuItem As MenuItem) As Boolean Return Me.List.Contains(MenuItem) End Function Public Function IndexOf(ByVal MenuItem As MenuItem) As Integer Return Me.List.IndexOf(MenuItem) End Function Public Sub Insert(ByVal index As Integer, ByVal MenuItem As MenuItem) Me.List.Insert(index, MenuItem) End Sub Default Public Property Item(ByVal Index As Integer) As MenuItem Get Return CType(Me.List.Item(Index), MenuItem) End Get Set(ByVal Value As MenuItem) Me.List(Index) = Value End Set End Property Public Sub Remove(ByVal MenuItem As MenuItem) Me.List.Remove(MenuItem) End Sub End Class Quote
Diesel Posted April 11, 2006 Posted April 11, 2006 namespaces? By the way, I don't think it's good practice to have a variable the same name as a class. Quote
Polar Bear Posted April 11, 2006 Author Posted April 11, 2006 (edited) OMG! Why didn't anyone ask me if I'm compiling the source files into a dll. I'm using Dreamweaver for god's sake. LOL [:$] Please don't bother replying. I'm drowning in my noobness. Edited April 11, 2006 by Polar Bear Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.