CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    run-time error 0 on shell

    I have this piece of code:
    code:
    ' Gaan updaten
    If FileExist(App.Path & "\hatasalupdate2014.exe") Then
    MsgBox "start updateprogram" ' just to check that the program is here
    Shell (App.Path & "\hatasalupdate2014.exe"), vbNormalFocus
    MsgBox "updateprogram started" '' to check if the program is so far
    CmdHatasalSluiten_Click
    End
    End If
    code:

    on the shell command i get run-time error 0
    What is wrong here?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: run-time error 0 on shell

    There is no run time error o

    An error number of 0 means no error occurred
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: run-time error 0 on shell

    DataMiser,
    That's right.
    But i get a message 'run-time error 0' and the program stops.
    With error trapping there is nothing.

    Name:  error0.jpg
Views: 1323
Size:  6.7 KB

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: run-time error 0 on shell

    Does this happen when you run from the IDE? If so where does it stop and what message do you get there? Is it in the code posted or is it coming from what you are shelling?

    Just as a test I tried to get VB to throw a err 0 and of course it would not do it

    Err.Raise 0 throws and error as 0 is an invalid error number, trying to throw it will throw error 5 Invaild procedure call or argument
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: run-time error 0 on shell

    DataMiser,
    I am a little further.
    The problem is maybe not the shell command.
    Executing the shell command the program hatasalupdate2014.exe starts
    and stops direct with error number 5.
    When i start the hatasalupdate2014.exe directly there is no problem.
    Also when running from vb6 there is no problem.
    Do you have any idea where the problem can be?

  6. #6
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: run-time error 0 on shell

    When i change the code above in:
    [code]
    Temp = App.Path & "\hatasalupdate2014.exe"
    ShellExecute Me.hwnd, vbNullString, Temp, vbNullString, "C:\", SW_SHOWNORMAL
    CmdHatasalSluiten_Click
    End
    [code]

    it all works fine.
    But i absolute have no idea why and that is something i cannot stand.

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: run-time error 0 on shell

    Code:
    Shell (App.Path & "\hatasalupdate2014.exe"), vbNormalFocus
    There should not be any () on that line as you are not getting a return value
    If you were to use () then they need to be in a different spot.

    I would be surprised if that would even compile
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: run-time error 0 on shell

    I removed the () on the shell line, but is does not make any difference.
    Compiling is no problem with or without ().

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: run-time error 0 on shell

    Quote Originally Posted by HermanTabbert View Post
    I removed the () on the shell line, but is does not make any difference.
    Compiling is no problem with or without ().
    Really?
    Code:
    shell (MyProgram),vbnormalfocus
    I really have no idea how that would behave but it is most definitely wrong and I would expect an error to be generated by it.

    This gives a compile error
    Code:
    shell (MyProgram,vbnormalfocus)
    The correct way is either
    Code:
    MyResult=shell (MyProgram,vbnormalfocus)
    or
    Code:
    shell MyProgram,vbnormalfocus
    Depending on if you need to capture the result value

    or if you use the out dated call keyword you can
    Code:
    Call shell (MyProgram,vbnormalfocus)
    Last edited by DataMiser; March 14th, 2014 at 01:05 PM.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: run-time error 0 on shell

    I am confused.
    When i use:
    Code:
               Dim MyResult
               MyResult = Shell(App.Path & "\hatasalupdate2014.exe", vbNormalFocus)
                MsgBox "MyResult =" & MyResult
    gives a run-time error 5

    In hatasalupdate2014.exe i use the command to start the main program again:
    Code:
    Shell App.Path & "\hatasal2014.exe", vbNormalFocus
    and that works ok.

    I have no idea what is happening and why.
    I stick to ShellExecute what works ok and go on to what i have to do.
    DataMiser, if you have any solution why this happens, i would like tyo hear from you,.
    For my own piece i would like this problem be solved.

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: run-time error 0 on shell

    I just tried this
    Code:
    Private Sub Command1_Click()
        Dim MyResult
        MyResult = Shell("c:\project1.exe", vbNormalFocus)
        MsgBox "MyResult =" & MyResult
    End Sub
    Works as expected, no errors
    Always use [code][/code] tags when posting code.

Tags for this Thread

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

Featured