Hello!
I want to make a vb.net program that reads from a text file a movie, with the help of a Open Dialog (called openFD in my program) (we don't know how many movie we've got), the actors, the release date, the country, and the rating.
The text file look like this:
Movie1;Actor,Actor,Actor1;Date1;Country1;Rating1
Movie1;Actor,Actor,Actor1;Date2;Country2;Rating2
...
First question: How can I make a 2-dimensional array? line(0,0) - Movie1, ... , line (1,5) - Rating2. Here Is my try, but it's not good:
I want to read the textfile, then I wanna put all 'n' movies in ListBox1, and when I click on a movie, the rest of the details to appear like this: In TextBox1, the Title, in TextBox2 - the actors, TextBox3 - the country, in data(datepicker) - the release date, and in vot (numericupdown) - the rating. After that, I want to make 3 buttons: New Movie (adds a movie to the list, with all the details - i am writing the details in the textboxez), Modify (modifies some movie detail), Delete Movie(deletes a movie with all the details). And after that, with the help of a Save Dialog (saveFD in my program), i want to write the things that I changed in the text file, respecting the template of the file.
I will put you down my code (it is a mess, i know), and if you can't help me with the things that i told you, please help me. Thank you!
This is the code for the open tool (with the openFD file dialog):
Here is the code for the save tool file dialog (saveFD)
Here is the code for the ListBox1. It is working, but I can't manipulate the details of a movie, that's why I need a working code for a 2-dimensional array
And here is the code for the Delete Button. It deletes a movie from the listbox, but the details of the deleted movie remains for the next one, I must delete the details for the deleted movie, too.
I want to make a vb.net program that reads from a text file a movie, with the help of a Open Dialog (called openFD in my program) (we don't know how many movie we've got), the actors, the release date, the country, and the rating.
The text file look like this:
Movie1;Actor,Actor,Actor1;Date1;Country1;Rating1
Movie1;Actor,Actor,Actor1;Date2;Country2;Rating2
...
First question: How can I make a 2-dimensional array? line(0,0) - Movie1, ... , line (1,5) - Rating2. Here Is my try, but it's not good:
VB.NET:
Dim line As ArrayList = New ArrayList()
Dim itm As ArrayList = New ArrayList()
Dim i As Integer = 0
Dim j As Integer = 0
Dim objReader As New System.IO.StreamReader(openFD.FileName)
Do While objReader.Peek <> -1
line(i) = objReader.ReadLine() & vbNewLine
For j = 0 To line(i).ToString.Length()
itm(i, j) = line(i).ToString.Split(";")
Next j
i = i + 1
Loop
I want to read the textfile, then I wanna put all 'n' movies in ListBox1, and when I click on a movie, the rest of the details to appear like this: In TextBox1, the Title, in TextBox2 - the actors, TextBox3 - the country, in data(datepicker) - the release date, and in vot (numericupdown) - the rating. After that, I want to make 3 buttons: New Movie (adds a movie to the list, with all the details - i am writing the details in the textboxez), Modify (modifies some movie detail), Delete Movie(deletes a movie with all the details). And after that, with the help of a Save Dialog (saveFD in my program), i want to write the things that I changed in the text file, respecting the template of the file.
I will put you down my code (it is a mess, i know), and if you can't help me with the things that i told you, please help me. Thank you!
This is the code for the open tool (with the openFD file dialog):
VB.NET:
Private Sub menuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuOpen.Click
openFD.Title = "Open a movie database"
openFD.Filter = "Text Files|*.txt|Database Files|*.dat|All Files|*.*"
openFD.FileName = "filme"
Dim film() As String
Dim TextLine As String
If (openFD.ShowDialog() = Windows.Forms.DialogResult.OK) Then
Dim objReader As New System.IO.StreamReader(openFD.FileName)
ListBox1.Items.Clear()
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine() & vbNewLine
film = TextLine.Split(";")
ListBox1.Items.Add(film(0))
Loop
ListBox1.SetSelected(0, True)
End If
End Sub
Here is the code for the save tool file dialog (saveFD)
VB.NET:
Private Sub toolSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolSave.Click
saveFD.CreatePrompt = True
saveFD.OverwritePrompt = True
saveFD.FileName = "filme"
saveFD.DefaultExt = "txt"
saveFD.InitialDirectory = "\"
saveFD.Filter = "Text File (*.txt)|*.txt|Data (*.dat)|*.dat"
'Dim fileStream As System.IO.Stream
'Dim userInput As New System.IO.MemoryStream
If (saveFD.ShowDialog() = Windows.Forms.DialogResult.OK) Then
'fileStream = saveFD.OpenFile()
'userInput.Position = 0
'userInput.WriteTo(fileStream)
'fileStream.Close()
Dim TargetFile As IO.StreamWriter
TargetFile = New IO.StreamWriter("C:\test.txt", True)
'TargetFile.WriteLine(Now())
TargetFile.Write(TextBox1.Text, ";", TextBox2.Text, ";", data.Value, ";", TextBox3.Text, ";", vot.Value)
End If
Here is the code for the ListBox1. It is working, but I can't manipulate the details of a movie, that's why I need a working code for a 2-dimensional array
VB.NET:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim Item As String
Dim TextLine() As String
Dim camp() As String
Dim i As Integer = 0
For Each Item In ListBox1.SelectedItems
TextBox1.Text = Item.ToString()
'TextBox2.Text = ListBox1.SelectedIndex()
Dim objReader As New System.IO.StreamReader(openFD.FileName)
Do While objReader.Peek() <> -1 'Merge pana nu mai este informatie in text
TextLine = objReader.ReadToEnd.Split(vbNewLine) 'Variabila TextLine ia valoarea unui rand de text
camp = TextLine(ListBox1.SelectedIndex()).Split(";") 'Despartim randul de mai sus in fct de ;
'ListBox1.Items.Add(film(0)) 'Adaugam filmul la ListBox
'i = i + 1
'Dim aux() As String = TextLine(ListBox1.SelectedIndex())
TextBox2.Text = camp(1)
TextBox3.Text = camp(3)
data.Value = camp(2)
vot.Value = camp(4)
Loop
'TextLine(ListBox1.SelectedIndex())
Next
End Sub
And here is the code for the Delete Button. It deletes a movie from the listbox, but the details of the deleted movie remains for the next one, I must delete the details for the deleted movie, too.
VB.NET:
ListBox1.Items.Remove(ListBox1.SelectedItem.ToString)