Why don't you just open it like this:
Quoted
I'd like to know the path to open a configuration file in the same directory.
|
|
Jabaco Source |
1 |
Dim file as vbfilehandler = open "yourfile" |
Just open "yourfile" and it's okay. No need of EXEName.
And App.Path works
To open it (second way) do this:
|
|
Jabaco Source |
1 |
Dim file2 as vbfilehandler = open app.path + "\" + "yourfile" |
Hi,
App.Path points to the current working directory which was true when starting the application.
This is not necessarily the directory of the executable.
Example: I start my Jabaco IDE via a desktop icon. This determines the current working directory to be somewhere on my desktop.
Far away from the Jabaco project directory.
But you are right: When you compile an exe file and start it using the exe's directory, App.Path works as expected.
Opening a file without specifying the path, leads to the same situation:
The file is assumed to be in the current working directory.
One workaround would be to start the exe in the directory of the configuration file.
But this is not really flexible for using Jabaco executables from CMD skripts.
Greetings!
A1880
App.Path points to the current working directory which was true when starting the application.
This is not necessarily the directory of the executable.
Example: I start my Jabaco IDE via a desktop icon. This determines the current working directory to be somewhere on my desktop.
Far away from the Jabaco project directory.
But you are right: When you compile an exe file and start it using the exe's directory, App.Path works as expected.
Opening a file without specifying the path, leads to the same situation:
The file is assumed to be in the current working directory.
One workaround would be to start the exe in the directory of the configuration file.
But this is not really flexible for using Jabaco executables from CMD skripts.
Greetings!
A1880
Hi,
i found something - maybe it's interesting:
in fact it returns the folder that jabaco creates in the temp-directory.
greetings
OlimilO
i found something - maybe it's interesting:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 |
Public AppPath As String Public Sub Form_Load() AppPath = GetAppPath MsgBox AppPath End Sub Public Function GetAppPath() As String Dim appURL As URL appURL = getClass.getResource(".") Dim s As String = appURL.getPath GetAppPath = Replace(s, "%20", " ") End Function |
in fact it returns the folder that jabaco creates in the temp-directory.
greetings
OlimilO
works onlu in IDE for me
I tested this code and it works perfectly here (though changing "URL" with "url" in line 8 ) when i launch the app in jabaco IDE.
But, if i compile the program, it gives the error reported below.
Any ideas about why?
Java.lang.NullPointerException
at Master.GetAppPath(Master.jsrc:12)
at Master.Form_Load(Master.jsrc:6)
at VB.AbstractForm.fireLoaded(AbstractForm.jsrc)
at VB.LoadAdapter.run(LoadAdapter.jsrc)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
But, if i compile the program, it gives the error reported below.
Any ideas about why?
Java.lang.NullPointerException
at Master.GetAppPath(Master.jsrc:12)
at Master.Form_Load(Master.jsrc:6)
at VB.AbstractForm.fireLoaded(AbstractForm.jsrc)
at VB.LoadAdapter.run(LoadAdapter.jsrc)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Try the following:
Greetings
A1880
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
Option Explicit Public AppPath As String Public Sub Form_Load() AppPath = GetAppPath() MsgBox AppPath End Sub Public Function GetAppPath() As String Dim classPath As String = System.getProperty("java.class.path") Dim pathSeparator As String = System.getProperty("path.separator") Dim fileSeparator As String = System.getProperty("file.separator") Dim cp() As String Dim s As String cp = Split(classPath, pathSeparator) s = cp(0) If Right(s, 8) = ".exe.jar" Then cp = Split(s, fileSeparator) s = Left(s, Len(s) - Len(cp(UBound(cp))) - 1) End If GetAppPath = s End Function |
Greetings
A1880
App.EXEName does not return paths in VB6, just a simple name. For "C:\blahblah\Project1.exe" for example it returns "Project1" alone.
App.Path is supposed to return the path to the compiled EXE w/o the "\" as in "C:\blahlah" alone. However it is broken in Jabaco and returns the current directory. This is very sad.
Speaking of that, the ChDir statement is completely missing in Jabaco.
App.Path is supposed to return the path to the compiled EXE w/o the "\" as in "C:\blahlah" alone. However it is broken in Jabaco and returns the current directory. This is very sad.
Speaking of that, the ChDir statement is completely missing in Jabaco.
Similar threads
-
Tips, Tricks, Samples & Tutorials »-
Open any file associated to a program by its file extension
(Aug 6th 2009, 7:21pm)
-
Visual Basic 6 Compatibility »-
Current Directory
(Jul 26th 2009, 1:59pm)
-
General topics, questions and discussions »-
Could not find the main class: Module1. Program will exit
(Jul 2nd 2009, 12:48pm)
-
General topics, questions and discussions »-
Executable for Microsoft and Mac, as I do?
(Apr 27th 2009, 10:18pm)
