Page 1 of 1
How to open and save files in VB 6
Posted: Thu Nov 24, 2005 6:56 am
by marcmarteleira
Exactly what the title says. I want the code though so that when you click save it will let you browse directorys and then save under any file name and same with open except txt files only please.
Posted: Thu Nov 24, 2005 9:57 am
by scubakobe
For VB 6, I am not sure...but for VB .NET I know.
This may or may not work for VB 6.
Code: Select all
Dim dlg As SaveFileDialog = New SaveFileDialog
dlg.Filter = "Text Files (*.txt) |*.txt"
dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ' This sets the intial path to 'My Documents'
If DialogResult.OK = dlg.ShowDialog Then
Dim sr As System.IO.StreamWriter = New System.IO.StreamWriter(dlg.FileName)
sr.Write(RichTextBox1.Text)
sr.Flush() ' Probably not needed, but will make sure that everything that's been streamed is written
sr.Close()
End If
Posted: Thu Nov 24, 2005 11:02 am
by Patrickssj6
I think for vb6 you just have to fix the dim statement