M
me
Hi All,
I am new to Classes and learniing the ropes with VB.NET express
Here's my question - say I have a want to manage a list of books.
Each book has an Author, Title and ISBN
Now, I am used to using Arrays so I would normally do something like this:
Set an array up during the init routine (called from form_load) say of
Books(100) of type Book (which is setup with Author as string, Title as
string etc.)
Allow the user to add/delete/edit a new book (with a simple VB form)
When it comes to saving the file, just cycle through the array and dump each
line to a CSV text file.
Opening - again cycle through the CSV file and fill the array.
Now - here's my question:
How can I do this using classes? I have set up a class (called Book) with
properties such as Title, Author, ISBN and can get/set them
I create a new instance, i.e. myBook = New Book.Book
However, I now dont understand.... This creates one instance, which i can
fill with information. However, if i want another book, I have to create
myBook2 = New Book.Book
So how does one then cycle through these items when saving? How do we create
all the instances when first loading the CSV file?
I tried myBook(1000) = New Book.Book but got an error.
I tried using
myBookGroup as Collections
but still... I dont understand - how can I refer to each individual book in
a loop for example when reading/writing the file?
Am I misunderstanding the point? Should I just stick with arrays?
Thanks
now I can create a collection
I am new to Classes and learniing the ropes with VB.NET express
Here's my question - say I have a want to manage a list of books.
Each book has an Author, Title and ISBN
Now, I am used to using Arrays so I would normally do something like this:
Set an array up during the init routine (called from form_load) say of
Books(100) of type Book (which is setup with Author as string, Title as
string etc.)
Allow the user to add/delete/edit a new book (with a simple VB form)
When it comes to saving the file, just cycle through the array and dump each
line to a CSV text file.
Opening - again cycle through the CSV file and fill the array.
Now - here's my question:
How can I do this using classes? I have set up a class (called Book) with
properties such as Title, Author, ISBN and can get/set them
I create a new instance, i.e. myBook = New Book.Book
However, I now dont understand.... This creates one instance, which i can
fill with information. However, if i want another book, I have to create
myBook2 = New Book.Book
So how does one then cycle through these items when saving? How do we create
all the instances when first loading the CSV file?
I tried myBook(1000) = New Book.Book but got an error.
I tried using
myBookGroup as Collections
but still... I dont understand - how can I refer to each individual book in
a loop for example when reading/writing the file?
Am I misunderstanding the point? Should I just stick with arrays?
Thanks
now I can create a collection