|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Autosave function - Problem
Hi there, I'm making a text editor (like notepad) and I'm trying to include an autosave function. I do however have some trouble with it.
When autosave is turned on: Code:
Private Sub OnToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnToolStripMenuItem1.Click
If filesaved = False Then
MsgBox("You must save the file before turning autosave on")
Dim save As New SaveFileDialog
If save.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(save.FileName, TextBox1.Text, False)
End If
End If
Timer1.Enabled = True
OnToolStripMenuItem1.Checked = True
OffToolStripMenuItem1.Checked = False
End Sub
When the autosave timer runs out thus saving: Code:
Here I want to save the file again, but without the dialog box (I want it to be saved automatically in the path it already is saved in) Now I know my code seems very clumsy and wierd, however this is one of my very first projects. I hope that you can help me out! Kind regards |
|
#2
|
||||
|
||||
|
Hi, and welcome to the forums. What happens when you run this, does it give you the save dialog box each time the timer runs out?
Try storing the filename in a variable, then test to see if this variable contains a value, eg: Code:
'Define a variable at the top of your page so that it is accessible by all functions
Dim strFileName As String
Private Sub OnToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnToolStripMenuItem1.Click
If strFileName = "" Then
MsgBox("You must save the file before turning autosave on")
Dim save As New SaveFileDialog
If save.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(save.FileName, TextBox1.Text, False)
strFileName = save.FileName
End If
Else
My.Computer.FileSystem.WriteAllText(strFileName, TextBox1.Text, False)
End If
Timer1.Enabled = True
OnToolStripMenuItem1.Checked = True
OffToolStripMenuItem1.Checked = False
End Sub
|
|
#3
|
|||
|
|||
|
and perhaps use the .NET forum next time
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Autosave function - Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|