Exclamation[Help] Open a file automatically [VB6] [solved]

Posts 31–39 of 39 · Page 3 of 3
Okay so ...
First you need this function
Code:
Function FileExists(File As String) As Boolean
   On Error Resume Next
   FileExists = False
   FileExists = Dir(File) <> ""
End Function
This will check, if the file specified is existing and, if so, it will return "true".
Lets say you got a Command Button named "Command1" and you want to start the file "hello.bat" in your programs directory.

Code:
Private Sub Command1_Click()
Dim sFile As String 'Dim a new variable called sFile
sFile = App.Path & "\hello.bat" 'Save the file path to the new variable. In this case, the "hello.bat" is in the same directory as your program's .EXE

If FileExists(sFile) = True Then 'Check wether this file exists or not
    Shell sFile, vbWindowState 'If it exists, start it
Else
    MsgBox "File does not exists" 'If it doesnt exist, return an error
End If
End Sub
Doesnt matter. I always add them at the bottom of the code.
What is wrong here?:
Code:
Private Sub Command1_Click()
Dim sFile As String 'Dim a new variable called sFile
sFile = App.Path & "\ini.bat" 'Save the file path to the new variable. In this case, the "hello.bat" is in the same directory as your program's .EXE

If FileExists(sFile) = True Then 'Check wether this file exists or not
    Shell sFile, vbWindowState 'If it exists, start it
Else
    MsgBox ("File does not exists") 'If it doesnt exist, return an error
End If
Function FileExists(File As String) As Boolean
   On Error Resume Next
   FileExists = False
   FileExists = Dir(File) <> ""
End Function

End Sub
Its a "Function" so you cant place it inside a "Sub".
Just paste it right under "End Sub" and it will work.
Thanks THAT WORKED!!!!!!!!!!!!!!!! YOU ARE THE BEST !!!!! I LOVE YOU! DO YOU WANT ANYTHING IN RETURN? SOME CREDITS? SOMETHING ELSE?
No problem
Just press thanks under this thread if you want
*DONE* thanks again! goodnight!
Thread marked as solved.

I strongly recommend you learn VB.NET instead of VB6, aside from finding WAY more support for VB.NET, you'll have a hard time changing from VB6 => VB.NET the longer you stick with VB6, the languages are a lot different, both syntactically and structurally (Managed vs Unmanaged). @ The people saying vb2011 is coming out, that is not a language: that is Microsoft's IDE for developing in VB.NET, unless a new framework is added, there will be NO change in the actual language.
Posts 31–39 of 39 · Page 3 of 3
This thread is closed for replies.

Tags for this Thread

None

Talk with us