Hi.
I'm quite new to Visual Basic so my project isn't that advanced and I don't have too much knowledge of it.
I'm however quite lost of how to solve the problems I now face.
My project is a library where you can enter books. The books take the forms of a struct type
with four variables inside it - Title, Author, Category and Yearofrelease. I save this data in a .txt file and have somehow managed to get a vector, named Books, to use this data when I display the book entries in a picturebox.
What I would want to do though, is to be able to sort the books by year or category and such and it is here that I'm totally lost.
I will show some code examples and a picture in hope to give you a perspective on how my project is.
Here is the show books button which list all the book entries from a file called "books.txt"
where I save the books in.
http://img374.imageshack.us/img374/5496/vb1zo4.jpg
My struct "Book" and vector "Books" look like this:
Public Books(1 To 100) As Book
Public Type Book
Title As String
Author As String
Category As String
Yearofrelease As Integer
End Type
To enter the book data and save it into a file and vector I use this code in a button, which
reads the information you enter (Title, Author) from text boxes. Looks like this:
http://img169.imageshack.us/img169/6494/vb2ga3.jpg
And the Save book buttons code is:
Private Sub cmdAddBook_Click()
Dim intFileNum As Integer
Dim i As Integer
Open "Books.txt" For Append As #1
Write #1, Text1.Text, Text2.Text, Text3.Text, Val(Text4)
Close #1
Open "Books.txt" For Input As #1
i = 0
Do While Not EOF(1)
i = i + 1
Input #1, Books(i).Title, Books(i).Author, Books(i).Category, Books(i).yearofrelease
Loop
Close #1
End Sub
I use this code on any form needed to load the data from .txt file into the vector "Books".
Private Sub Form2_Activate()
Dim i As Integer
Open "Books.txt" For Input As #1
i = 0
Do While Not EOF(1)
i = i + 1
Input #1, Books(i).Title, Books(i).Author, Books(i).Category, Books(i).yearofrelease
Loop
Close #1
End Sub
And the code behind the first picture where I display
the book data in a picturebox is this (after having used the code above to load data into vector):
Private Sub cmdShowPic_Click()
Dim i As Integer
Picture1.Cls
Picture1.Print "Title", " Author", " Category", " Release"
Picture1.Print
For i = 1 To 100
Picture1.Print Books(i).Title, Books(i).Author, Books(i).Category, Books(i).yearofrelease
Next i
Picture1.Print
End Sub
I guess I should use the above code in another button, but add some form of sorting system to sort the results after year or category etc, but I have no idea how to. I can't see where I would possibly enter such code either. So how would I act to sort these results shown after year or category etc?
I am truly grateful that you have taken your time to read this far and I'm overwhelmed if anyone can help out a bit here and please point out if I have been unprecise with anything.