First, vocabulary:
OpenFileDialog: The dialog that comes up when a user presses the open button in your application.
SaveFileDialog: The dialog that comes up when a user presses the open button in your application.
Here is an example of using an OpenFileDialog:
Code: Select all
OpenFileDialog.FileName = "Test"
OpenFileDialog.InitialDirectory = "C:\Program Files\Test Program"
OpenFileDialog.Filter = " Test File (*.test)|.test"
OpenFileDialog.DefaultExt = "test"
OpenFileDialog.ShowDialog()
Code: Select all
SaveFileDialog.Filename = "Test"
SaveFileDialog.InitialDirectory = "C:\Program Files\Test Program"
SaveFileDialog.Filter = " Test File (*.test)|.test"
SaveFileDialog.DefaultExt = "test"
SaveFileDialog.ShowDialog()
all of the commands above showdialog are telling the dialog "what to do",
without these parameters the dialog wouldnt do anything.
for example, if you didnt have .DefaultExt then it would just save the files as "files" with no extension, unless the user specifies one at end of name.
Say you put ShowDialog above everything, it wont work......
why you say, because the way the exe reads your code is from top to bottom, so if your parameters are below, the exe hasnt even recognized them yet.
Example of opening and saving .map files:
Code: Select all
OpenFileDialog.FileName = "*.map"
OpenFileDialog.DefaultExt = "map"
OpenFileDialog.InitialDirectory = "C:\Program Files\Microsoft Games\Halo\Maps"
OpenFileDialog.Filter = "Halo Cache Files (*.map)|.map"
OpenFileDialog.ShowDialog()
Code: Select all
SaveFileDialog.FileName = "*.map"
SaveFileDialog.DefaultExt = "map"
SaveFileDialog.InitialDirectory = "C:\Program Files\Microsoft Games\Halo\Maps"
SaveFileDialog.Filter = "Halo Cache Files (*.map)|.map"
SaveFileDialog.ShowDialog()
Directory Not Found
Solution:
Make sure the folder exists, if it doesnt then create it and try again.
Error:
Blue underline under Open/SaveFileDialog
make sure that your dialogs are created and named OpenFileDialog or SaveFileDialog.
I hope this has helped some of you with your VB programming.
There are many more parameters but these are the most important to get the dialog to work.
.Title is a parameter that will change the title of the dialog box that comes up.
Example of use:
Code: Select all
OpenFileDialog.Title = "Open Halo Cache File"
Code: Select all
SaveFileDialog.Title = "Save Halo Cache File"
Code: Select all
Public Sub OpenFileDialog_FileOk
Dim strFile As String
Dim strFileContents As String
strFile = OpenFileDialog.FileName
strFileContents = My.Computer.FileSystem.ReadAllText(strFile)
MsgBox("Done loading file" + strFile)
txtmain.Text = strFileContents
End Sub
El Fin