Fake filesave system... need help

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
Ok i am making a game (based on windows95)....

i have it going good so far.

I have it so you can open notepad (this is in a panel and its not the real system notepad)
You can click save document and it saves the text it in a hidden textbox with a random filename (defined by user) and it saves it in a listveiw (windows explorer type thing)

The idea is i want it to be so that if you double click the listveiw item it will open the textfile (text stored in a hidden textbox)

Heres my code which is attempting to do this but i just can't think how to link them.
Private Sub btnsaveassave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveassave.Click
Dim savedfile As New TextBox
mycomputerfiles.Items.Add(txtfilename.Text & ".txt")
usersave = txtfilename.Text
Me.Controls.Add(savedfile)
txtcount = txtcount + 1
savedfile.Text = notepadtextbox.Text
savedfile.Name = (txtcount)
program2.Hide()
End Sub

Anyone know a betterway of doing this?

Just for the record here is the code for my whole project:

Public Class windows95
Dim txtcount As Integer
Dim usersave As String

Private Sub startbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startbutton.Click
startmenu.Show()
End Sub

Private Sub windows95_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
startmenu.Hide()
End Sub

Private Sub windows95_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
startmenu.Hide()
program.Hide()
program2.Hide()
notepad.Hide()
windowshelp.Hide()
taskbarprogram.Hide()
windowsexplorer.Hide()
notepadopenfile.Hide()
End Sub

Private Sub NotePadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotePadToolStripMenuItem.Click
program.Show()
programname.Text = "Notepad"
taskbarprogram.Show()
taskbarprogram.Text = "Notepad"
notepad.Show()
notepad.Dock = DockStyle.Fill
startmenu.Hide()
End Sub

Private Sub Closebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Closebutton.Click
program.Hide()
notepad.Hide()
taskbarprogram.Hide()
windowshelp.Hide()
windowsexplorer.Hide()
programname.Text = ""
End Sub

Private Sub fullscreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles maximize.Click
program.Dock = DockStyle.Fill
End Sub

Private Sub minimize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minimize.Click

program.Dock = DockStyle.None
End Sub


Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click
programname.Text = "Help Topics: Windows Help"
taskbarprogram.Show()
taskbarprogram.Text = "Help Topics"
program.Show()
windowshelp.Show()
windowshelp.Dock = DockStyle.Fill
startmenu.Hide()
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
program.Hide()
notepad.Hide()
taskbarprogram.Hide()
End Sub

Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
program2.Show()
programname2.Text = "Save As"
saveas.Dock = DockStyle.Fill
End Sub

Private Sub Closebutton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Closebutton2.Click
program2.Hide()
End Sub

Private Sub btnsaveassave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveassave.Click
Dim savedfile As New TextBox
mycomputerfiles.Items.Add(txtfilename.Text & ".txt")
usersave = txtfilename.Text
Me.Controls.Add(savedfile)
txtcount = txtcount + 1
savedfile.Text = notepadtextbox.Text
savedfile.Name = (txtcount)
program2.Hide()
End Sub

Private Sub WindowsExplorerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WindowsExplorerToolStripMenuItem.Click
programname.Text = "Windows Explorer"
program.Show()
windowsexplorer.Show()
windowsexplorer.Dock = DockStyle.Fill
startmenu.Hide()
End Sub

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
notepadopenfile.Show()
End Sub

Private Sub btnnotepadopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnotepadopen.Click

notepadopenfile.Hide()
End Sub
End Class
 
You don't need a hidden TextBox. All a TextBox does is display a String and allow the user to edit it. If you don't want to display it and you don't want the user to edit it then all you need is a String, not a TextBox.

I would suggest that you use a Dictionary(Of String, String). That will allow you to store contents of multiple "files" keyed on "file name".
VB.NET:
Private files As New Dictionary(Of String, String)

Private Sub SaveFile(ByVal name As String, ByVal contents As String)
    files.Add(name, contents)
End Sub

Private Function OpenFile(ByVal name As String) As String
    Return files(name)
End Sub
 
Ok now i have decided to use the dictionary method...

now the only problem i got now is how do i open the file...

I want the user to open it by selecting it from the listveiw then pressing open which will make it display the text of that string (listveiw item) that they choose..


Heres some of the new code using your method.

Private Sub btnsaveassave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveassave.Click
Dim filename As String
Dim txtcontents As String
filename = txtfilename.Text
txtcontents = notepadtextbox.Text
SaveFile(filename, txtcontents)
mycomputerfiles.Items.Add(filename & ".txt")
mycomputerfiles2.Items.Add(filename & ".txt")
program2.Hide()
End Sub


Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
notepadopenfile.Show()
notepadopenfile.Dock = DockStyle.Fill
program2.Show()
End Sub

Private Sub btnnotepadopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnotepadopen.Click
Dim chosenopen As String
chosenopen = txtnotepadopen.Text
OpenFile(chosenopen)
notepadopenfile.Hide()
End Sub
Private files As New Dictionary(Of String, String)

Private Sub SaveFile(ByVal name As String, ByVal contents As String)
files.Add(name, contents)
End Sub

Private Function OpenFile(ByVal name As String) As String
Return files(name)
End Function
End Class
 
Back
Top