Saving / Loading List Box Values from specified file

mAtUxAz

Member
Joined
Nov 8, 2012
Messages
12
Programming Experience
1-3
Hello, I am creating my own money tracking program. I am in trouble at the part where save and load code of specific file starts.
I want to load and save my own created *.mmt files.
The files would be loaded and saved through Open / Save As window.
What code should I use to load these files?
What code should I use to save these files?

I'd like to save values of both textboxes into one file. Possible or not? If not - two files is not a problem though.

Also, if I can't use specific file extension (*.mmt), a general *.txt file won't ruin my app :tennis:

There is my code

=============================================================================================================================
Public Class Form1


Private Sub ImportToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ImportToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
End Sub


Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
SaveFileDialog1.ShowDialog()
End Sub


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text & " got on " & TextBox3.Text & "; " & TextBox2.Text)
End Sub


Private Sub Label13_Click(sender As Object, e As EventArgs) Handles Label13.Click


End Sub


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox2.Items.Add(TextBox6.Text & " spent for " & TextBox5.Text & " on " & TextBox4.Text)
End Sub


Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
If MessageBox.Show("Have you saved your work?", "Wait!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Close()
Else
MessageBox.Show("Please save your work!", "Wait!", MessageBoxButtons.OK, MessageBoxIcon.Information)
SaveFileDialog1.ShowDialog()
End If
End Sub


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


End Sub
End Class

=============================================================================================================================

And some photos


The listbox menu. Probably only Exit function is working without problems.
2.jpg

Open file window. Nothing happens even if I select *.mmt file (an empty file with *.mmt extension).
3.jpg

Added entries to both listboxes for a demonstration. Works perfectly.
1.jpg

Save As file window. No file is saved even if I enter file name and click save.
4.jpg


That's it.
Now, repeating again my questions:
What code should I use to load these files?
What code should I use to save these files?

Will be looking forward to answers!
 

mAtUxAz

Member
Joined
Nov 8, 2012
Messages
12
Programming Experience
1-3
Thank you so much for all the help!
Yeah, two datasets, as I can see now can be converted into one and it is really better :)
I even don't know, why I created two (one for one table, second for second table) when I could use one dataset :)
 
Top Bottom