Lets say you made a command button that when pressed would open some type of file. How do you do that?
Printable View
Lets say you made a command button that when pressed would open some type of file. How do you do that?
If you want to just open a text file, for example, just use the open statement.
If your file is located at C:\MytextFile.txt then your statement would be as simple as:
Open "C:\MytextFile.txt" for input as #1
Then to get the first line of the text, if you had dimensioned MyLine as a string, you'd simply have:
Input #1, MyLine
Everytime you repeat that, you'll read the next line. When you're done, have the command:
Close #1
In Visual Basic just run help and look at OPEN. There are different ways you can open something, such as for input, for append, for output, etc. Data can be sequential or random. And so on.
also you may not want to hard code in the file path so using a CommonDialog control will allow the user to browsae for the desired file to open.
File Open FAQ:
http://www.vbforums.com/showthread.php?t=342619
http://www.vbforums.com/showthread.php?t=405051
CommonDialog ex:
Code:Option Explicit
'Add a CommonDialog control to your form.
'Project > Components > Controls tab > "Microsoft Common Dialog control" > OK
Private Sub Command1_Click()
On Error GoTo MyError
With CommonDialog1
.CancelError = True
.DialogTitle = "Common Dialog Example"
.Filter = "Text files only (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.Flags = cdlOFNHideReadOnly Or cdlOFNOverwritePrompt Or cdlOFNPathMustExist
.InitDir = App.Path
.ShowSave 'or .ShowOpen
End With
'Do your save/open stuff here
'Use the CommonDialog1.FileName property to get the full path and file name selected
'
Exit Sub
MyError:
If Err.Number <> cdlCancel Then
MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation, "Save"
End If
End Sub
I think, exe files can be opened using shell function...
:)Code:Shell App.path & "\game.exe", vbnormalfocus
is the complete path of the exe file.Quote:
App.path & "\game.exe"
is the type of display (for maximized, minimize, normal, etc...)Quote:
vbnormalfocus