On Feb 5, 7:02 pm, "RobinS" <Rob...@NoSpam.yah.none> wrote:
> "Brian Gideon" <briangid...@yahoo.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
>
>
> > On Feb 5, 12:52 pm, "blisspikle" <eklas...@metforming.com> wrote:
> >> Brian,
>
> >> Would Hashtable or IDictionary still work if I had alot of other
> >> properties in my book object like ISBN,NumOfPages,etc? I am not sure
> >> if I understand what a hashtable is. I looked it up and it seems like
> >> it is only good for one value. If I know the name of something, then
> >> the hashtable returns the place where I can find it? I see that
> >> arraylist has a gethashtable method in it, what would that be used
> >> for?
>
> >> Thanks,
>
> > Hi,
>
> > Clarification...a Hashtable is an IDictionary. A dictionary is a data
> > structure that can map a key to a value. There are several different
> > implementations. In the case of a Hashtable (or the generic
> > Dictionary<Of T>) the data structure is implemented as a hash table.
> > A hash table works by hashing the key object to find which internal
> > bucket to store the value object. A single dictionary would not work
> > well for more than one book attribute. It would be best if the
> > Publisher had one dictionary per book attribute (the key). One
> > problem you're going to run into though is that dictionaries require
> > the key object to be unique. Obviously, it's possible for two
> > different books to have the same number of pages. You can handle that
> > scenario by having your BooksByNumOfPages As IDictionary hold an
> > ArrayList as the value object which itself will hold the Book objects.
>
> > Brian
>
> --------------------------------------------------------
>
> You can just use a Generic List to do what I think you're trying to do,
> which is keep a list of books for a publisher.
>
> If there is more than one book per title, I'd use ISBN instead of name (or
> title).
>
> By the way, you should make those public variables Properties.
>
> Public Class Publisher
> Public Name As String 'you should make this a property
>
> Private BookList As List(Of Book)
> Private targetName as String
>
> Public Sub New()
> Name = "default publisher"
> BookList = New List(Of Book)
> End Sub
>
> Public Sub AddBook(ByVal bBook As Book)
> BookList.Add(bBook)
> End Sub
>
> Public Sub RemoveBook(ByVal bBook As Book)
> BookList.Remove(bBook)
> End Sub
>
> 'given a name, return the book object
> Public Function GetBookInfo(byVal bookName As String) as Book
> targetName = bookName
> 'this runs the delegate procedure against each item
> ' in the list; whichever ones returns True gets returned
> Dim bk as Book = bookList.Find(AddressOf FindNameDelegate)
> debug.Print("Book: {0}, Author: {1}", bk.Name, bk.Author)
> Return bk
> End Function
>
> Public Function FindBookNameDelegate(bk As Book) As Boolean
> Return bk.Name = targetBookName
> End Function
>
> End Class
>
> Public Class Book
>
> 'THESE SHOULD BE PROPERTIES, *especially* if you're
> ' making them public. I'm just adding author so I'll
> ' have more than one; add as many as you like.
> Public Name As String
> Public Author As String
>
> Public Sub New()
> Name = "default book" ' tag name
> Author = "default author"
> End Sub
>
> Public Sub New(ByVal pName As String)
> Name = pName ' book name
> Author = "Unknown"
> End Sub
>
> Public Sub New(ByVal pName As String, pAuthor As String)
> Name = pName
> Author = pAuthor
> End Sub
>
> End Class
>
> This should work. Let me know!
>
> Robin S.- Hide quoted text -
>
> - Show quoted text -
I tried out the List(Of Book) and it works great. I am able to get to
all of the methods or properties similar to
Dim Publisher1 as New Publisher
Publisher1.Booklist.Item(0).Name = "bookname"
This diffenently makes it easier on me. There is also another way
that (I think) would take a lot of processor time to achieve.
If Booklist is defined as an arraylist then you can use
Dim Publisher1 as new Publisher
Ctype(publisher1.booklist(0),book).name = "bookname"
Thank you for your help. I like the List(of T) idea
|