2
votes

Please advice

I compiled the following VB6 code ( as --> file --> make project.exe )

But when I run it I get a very strange thing ( I have WIN XP machine )

In spite I defined to run this line:

  "java  -jar  run.jar" 

under

    C:\Program Files\APP\SW_TOP\Java by chDir

msgBox print diff PATH:

    D:\Documents and Settings\Eytan\Desktop

please advice why?

Why chDir not change the directory in my VB6 Code – what's wrong?

VB6 Code:

  Private Sub Command_Click()
  ChDir ("C:\Program Files\APP\SW_TOP\Java ")
  Shell Environ("COMSPEC") & " /c  java  -jar  run.jar", vbNormalFocus

  MsgBox App.Path

  End Sub

Please advice if there are some other alternative in order to run the "java -jar run.jar" under

  C:\Program Files\APP\SW_TOP\Java
2
Please do not tag VB6 questions with VB.NET. They are very different technologies.Steven Doggart
Shell inherits its own environment, including current directory, apart from whatever your EXE runs under. You might try shelling out to a bat file that CDs to the path you want then runs your file. And by the way, App.Path is always going to return the path to your EXE, not the current directory.Steve Rindsberg
Also, this is not VBA but VB6 as VBA does not allow you to create a standalone executables.user2140173

2 Answers

4
votes

You can have a different "current directory" on each drive. So, while your call to ChDir changes your current directory on the C: drive, it doesn't change your current drive from D: to C:. To switch your current drive, use the ChDrive procedure:

ChDrive "C:"
ChDir "C:\Program Files\APP\SW_TOP\Java "
1
votes

The body of your question asks why MsgBox App.Path does not show C:\Program Files\APP\SW_TOP\Java. The reason is because App.Path has the location of your program, not the current working directory.

From the documentation:

For the App object, Path specifies the path of the project .VBP file when running the application from the development environment or the path of the .exe file when running the application as an executable file.