|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom collectionsI have a class Box. It has 3 properties(Boxtype,BoxTare,BoxDescription) I also want to make a BoxCollection object. I have tried using collectionbase and arraylist, but I can't figure out how to "make it work" the way I think it should. Public Class BoxCollection Inherits ArrayList Public Sub New() End Sub Private mBoxNames As ArrayList Public ReadOnly Property BoxNames() As ArrayList Get Return mBoxNames End Get End Property Public Function getBoxNames(ByVal location As String) As BoxCollection Dim db As dal.Database = Nothing db = dal.DatabaseFactory.CreateDatabase(location) Dim reader As IDataReader Dim commandtext As String = "Select Boxtype from boxes" reader = db.ExecuteReader(CommandType.Text, commandtext) While reader.Read mBoxNames.Add(reader(0)) End While End Function This is one of my attempts. I feel like I have failed miserably.Can anyone point me to good tutorials on collections and building them? Or should I take another avenue since its attached to a database? -- --Eric Cathell, MCSA If you already have the class called Box, to make a collection of Box's you need this sort of setup
Friend Class Boxes Inherits System.Collections.CollectionBase Public Sub Add(ByVal oBox As Box) list.Add(oBox) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then 'Not found so do nothing Else list.RemoveAt(index) End If End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As Box Get Return CType(List.Item(index), Box) End Get End Property Public Sub Dispose() list.Clear() End Sub End Class In the code that makes use of the Boxes, you do this sort of thing. Dim myBoxes as Boxes myBoxes.Add (myBox) etc. Hope this helps "ECathell" <ecathell@nospam.mountaire.com> wrote in message news:O7TPK4OQFHA.1472@TK2MSFTNGP10.phx.gbl... Collections are really kicking me hard. I have a class Box. It has 3 properties(Boxtype,BoxTare,BoxDescription) I also want to make a BoxCollection object. I have tried using collectionbase and arraylist, but I can't figure out how to "make it work" the way I think it should. Public Class BoxCollection Inherits ArrayList Public Sub New() End Sub Private mBoxNames As ArrayList Public ReadOnly Property BoxNames() As ArrayList Get Return mBoxNames End Get End Property Public Function getBoxNames(ByVal location As String) As BoxCollection Dim db As dal.Database = Nothing db = dal.DatabaseFactory.CreateDatabase(location) Dim reader As IDataReader Dim commandtext As String = "Select Boxtype from boxes" reader = db.ExecuteReader(CommandType.Text, commandtext) While reader.Read mBoxNames.Add(reader(0)) End While End Function This is one of my attempts. I feel like I have failed miserably.Can anyone point me to good tutorials on collections and building them? Or should I take another avenue since its attached to a database? -- --Eric Cathell, MCSA One suggestion is to use CodeSmith which is a code generator. It comes
with templates to create different type of code. There are several templates that create collection classes. You just specify the type of object to make the collection from and it generates a complete class. Best of all, its free. yep got codesmith, I am still working through figuring it out..Thanks for
the tip... -- Show quoteHide quote--Eric Cathell, MCSA "Chris Dunaway" <dunaw***@gmail.com> wrote in message news:1113483914.326447.189280@o13g2000cwo.googlegroups.com... > One suggestion is to use CodeSmith which is a code generator. It comes > with templates to create different type of code. > > There are several templates that create collection classes. You just > specify the type of object to make the collection from and it generates > a complete class. Best of all, its free. >
Only 2 Days left to get REALbasic 5.5 for FREE!
Execption Handling disection [Datable] change column datatype File Path (Application Path) Dependency Error: The dependency <dll> in project <project> cannot be coppied to the run directory b Re: THE GREATEST NEWS EVER! °º·._._.·º°`°º·._._.·º°`°º·._._.·º°`°º·._._.·º°`°º·._._.·º°`°º·._._.·º°` No one Find Directory created by me... Update Command with Parameter.... Crystal Report Database Change DataGrid LostFocus does not seem right |
|||||||||||||||||||||||