Solved

VB6 Run-time error '5' when calling shell

Posted on 2014-02-14
14
1,052 Views
Last Modified: 2014-02-17
I get this error from VB6 when calling this line:

Run-time error '5'

GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)

I do not see any setfocus in my code that I usually see through this error. This code does work by the way in a clean project with noting else.

Any suggestions?
0
Comment
Question by:mossmis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
14 Comments
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859646
What do you mean by:
This code does work by the way in a clean project with noting else.
How is your current setup not clean?
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39859714
Does your App.Path contain spaces?

--
Chris
0
 

Author Comment

by:mossmis
ID: 39859840
Chris, the app.path does contain spaces. But this works when I isolate the code in a new project with just that command. I'm not sure what else might be causing the error.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39859847
Can you post the code (at least the full subroutine which has the offending line in it)?
0
 

Author Comment

by:mossmis
ID: 39859923
Public Sub UpdateCurrentApp()
'If the App version doesn't match automatically update the app

Dim fso As New FileSystemObject
    If Not fso.FileExists(App.Path & "\updateapp.bat") Then
        fso.CreateTextFile "updateapp.bat"
    End If

    Open App.Path & "\errors.txt" For Output As #1
    Print #1, "ECHO Please Wait.....Automatically Updating to New Version"
    Print #1, "Timeout 5"
    Print #1, "%~d1"
    Print #1, "cd ""%~p1"""
    Print #1, "copy /y """; UpdateAppFolder; UpdateAppEXE; """"; " "; UpdateAppEXE
    Print #1, "Timeout 1"
    Print #1, "start "; UpdateAppEXE
    Print #1, "exit"
    Close #1
    
    GetApp = Shell(App.Path & "\updateapp.bat", vbNormalNoFocus)
    
    End

End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 39859943
Quote-delimit the path/filename:
GetApp = Shell(Chr(34) & App.Path & "\updateapp.bat" & Chr(34), vbNormalNoFocus)

Open in new window

0
 
LVL 12

Accepted Solution

by:
jkaios earned 500 total points
ID: 39862167
@author (mossmis)
  should line 9 in your code reference "updateapp.bat" instead of "errors.txt" ?

  line 6: fso.CreateTextFile "updateapp.bat" does NOT match
  line 20: App.Path & "\updateapp.bat"

============ edited by aikimark
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39862770

@aikmark
  actually, it should be Chr(32), which is the character code for a SPACE and not Chr(34), which is the character code for a double quote (")
No.  You should use a quote delimiter.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39863303
No.  You should use a quote delimiter.

Yes, that's right.  My bad.  I forgot that referencing a directory that has space in it must be enclosed by double quotes.
0
 

Author Comment

by:mossmis
ID: 39864837
Son of a........... line 9 had a bad file name (I copied code from another project of mine). That little thing fixed it. I didn't need to add extra quotes; I took care of it in line 14.

Thanks for catching that mistake.
0
 

Author Comment

by:mossmis
ID: 39864881
jkaios caught my mistake. Why isn't he getting the points?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question