|
-
May 16th, 2000, 11:46 AM
#1
Thread Starter
Member
I use this string to open other files:
Dim x
x = Shell(app.Path & "\File.Exe")
what if i want to put a file in the folder of my main program and have the main program run the file but not do anything if the file isnt there.
because with this string the file has to be there or i get an illegal function call.
Any ideas?
-Jeff
Using VB 6.0 Enterprise
I Still like to program on my TI-85!
-
May 16th, 2000, 12:08 PM
#2
Is that the "This program has performed an illegal operation" error?
-
May 16th, 2000, 12:10 PM
#3
Lively Member
When using Shell it will execute the file in the current directory unless specified. As far as I know, so don't add the path to the filename you execute and you should be fine... See code below
Private Sub CmdRun_Click()
Dim AppName as String
Dim AppProcID as Integer
AppName = "MyApp.exe"
On Error Goto ErrRoutine
AppProcID = Shell(AppName)
Exit Sub
ErrRoutine:
'exe wasn't found or some internal error occured
'you can either, log it to a file, message box it or
'ignore it. if you run this code from the VB IDE without
'making this app an .exe Shell command will assume MyApp.exe
'is in the current dir for VB. example: c:\program files\DevStudio\VisualBasic\MyApp.exe
End Sub
Regards,
 Paul Rivoli 
---------------------
[email protected]
http://members.dingoblue.net.au/~privoli
-
May 16th, 2000, 12:11 PM
#4
Thread Starter
Member
If my program runs a file thats not there it will give me an illegal function call
whats the code i can use in case this happens?
-Jeff
Using VB 6.0 Enterprise
I Still like to program on my TI-85!
-
May 16th, 2000, 12:15 PM
#5
Hyperactive Member
You need to verify the .exe file is there in the first place
So, create a function like this to see if a file exists.
Code:
Public Function Exists(ByVal file_ as String) As Boolean
On Error Goto NO_FILE
'' try to get the length of the file
'' if errors occur we know the file Doesn't Exist
Call FileLen(file_)
Exists = True
Exit Function
NO_FILE:
Exists = False
Exit Function
'' Test Driver Sub
Public Sub RunFile()
Dim x as Long
'' if the file exists shell it!
If Exists(App.Path & "\File.exe") Then
x = Shell(App.Path & "\File.exe")
End if
End Sub
there are other ways of doing this but this one works. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|