How to open and save files in VB 6

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
marcmarteleira





Posts: 137
Joined: Sun Jan 30, 2005 7:32 am
Location: Mississauga

How to open and save files in VB 6

Post 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.
Signature exceeded 500x120 pixels.
scubakobe





Posts: 188
Joined: Sat Sep 17, 2005 7:58 am

Post 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
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

I think for vb6 you just have to fix the dim statement
...left for good
Post Reply