April 2006
Intermediate to advanced
32 pages
54m
English
The "Save a File" button displays a Save File dialog window to let users specify a directory as well as a filename. Once you've selected these two items, you will save the current date and time to the specified file:
'===================================================
' Save a File
'===================================================
Private Sub btnSaveFile_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnSaveFile.Click
'---Create a SaveFileDialog to request a path and file
' name to save to---
Dim saveFile1 As New SaveFileDialog()
'---Initialize the SaveFileDialog to specify the txt
' extension for the file---
saveFile1.DefaultExt = "*.txt"
saveFile1.Filter = "Text Files|*.txt"
'---Determine if the user selected a file name from the
' saveFileDialog---
If (saveFile1.ShowDialog() = _
System.Windows.Forms.DialogResult.OK) _
And (saveFile1.FileName.Length) > 0 Then
'---Write the current date and time to file---
My.Computer.FileSystem.WriteAllText( _
saveFile1.FileName, Now.ToString, False)
MsgBox("Content written to text file.")
End If
End SubRead now
Unlock full access