badgerboy
Member
Hello, I have found the following code for an Save and Open file dialogs but Both JUST CRASH the program when executed heres the code
Please help thanking in advanced BadgerBoy
Code:
Public fmainform As Form1
Public Sub open()
Dim FileName As String
Dim odlgtextfile As Object
Dim txthtml As Object
Dim statusbarpanel4 As Object
Dim ts As StreamReader
Dim form1 As New Form1()
Try
With fmainform.odlgtextfile
.DefaultExt = "html"
.DereferenceLinks = True
.Filter = _
"Web files (*.html)|*.html|" & _
"All files|*.*"
.Multiselect = False
.RestoreDirectory = True
.ShowHelp = True
.ShowReadOnly = False
.Title = "Select a file to open"
If .ShowDialog() = DialogResult.OK Then
FileName = .FileName
ts = New StreamReader(.OpenFile)
fmainform.txthtml.Text = ts.ReadToEnd()
fmainform.StatusBarPanel4.Text = System.IO.Path.GetDirectoryName(fmainform.odlgtextfile.FileName) + "\" + System.IO.Path.GetFileName(fmainform.odlgtextfile.FileName)
fmainform.Text = "HTML 2K3" + " " + System.IO.Path.GetDirectoryName(fmainform.odlgtextfile.FileName) + "\" + System.IO.Path.GetFileName(fmainform.odlgtextfile.FileName)
End If
End With
Catch exp As Exception
MessageBox.Show(exp.Message, fmainform.Text)
Finally
If Not (ts Is Nothing) Then
ts.Close()
End If
End Try
End Sub
This is for the save dialog
Public Sub save()
Dim sw As StreamWriter
Dim filename As String
Dim statusbarpanel4 As Object
Try
With fmainform.sfd1
.AddExtension = True
The default is True.
.CheckPathExists = True
The default is False.
.CreatePrompt = False
The default is True.
.OverwritePrompt = True
The default is True.
.ValidateNames = True
The default is False.
.ShowHelp = True
If the user doesnt supply an extension,
and if the AddExtension property is
True, use this extension.
The default is "".
.DefaultExt = "txt"
Prompt with the current file name
if youve specified it.
The default is "".
.FileName = filename
The default is "".
.Filter = _
"Html files (*.html)|*.html|" & _
"All files|*.*"
.FilterIndex = 1
If .ShowDialog() = DialogResult.OK Then
filename = .FileName
sw = New StreamWriter(filename)
sw.Write(fmainform.txthtml.Text)
End If
End With
Catch exp As Exception
MessageBox.Show(exp.Message, fmainform.Text)
Finally
If Not (sw Is Nothing) Then
sw.Close()
End If
End Try
fmainform.StatusBarPanel3.Text = "Current work is saved"
End Sub
Please help thanking in advanced BadgerBoy
Last edited by a moderator: