Results 1 to 5 of 5

Thread: Error on run?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Location
    USA-TEXAS-DALLAS
    Posts
    34

    Unhappy

    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!

  2. #2
    Guest
    Is that the "This program has performed an illegal operation" error?

  3. #3
    Lively Member
    Join Date
    Nov 1999
    Location
    Melbourne, Victoria, Australia
    Posts
    126

    Thumbs up

    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

  4. #4

    Thread Starter
    Member
    Join Date
    May 2000
    Location
    USA-TEXAS-DALLAS
    Posts
    34
    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!

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    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.

    -Shickadance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width