General discussion

Locked

Relative File Path in VB & Install Prog

By rsp05 ·
Hi, I have a problem I am stuck on. I have developed a VB app, which reads a config/ini file from a specified path. However, I have created an installation program, which lets you choose the location of where to install. Now, when the components (the VB exe and the config file) are installed the the MAINAPP folder (say MAINFOLDER), it executes properly and works!
However, if the path is changed during the installation, say from \MAINFOLDER to \ProgramFiles\MAINFOLDER, it cannot find the path and returns a RUN-TIME path error.
I need a method of automatically knowing what the directory level of the exe and cfg file that is read. It needs to work, regardless of the install path. Is there a way to just reference the folder that they are both in, regardless of the levels? If the path is the mainfolder, it is \MAINFOLDER\EXE. If it is one level it is ..\MAINFOLDER\EXE. But how can I have it for both possibilities. TIA!

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Relative File Path in VB & Install Prog

by sl-campbell In reply to Relative File Path in VB ...

If the INI path IS the application path then you can use the function: App.Path
in order to return the path.
Then, when you are ready to read the ini path, use the App.Path & "\" & myIniFile.ini.
You should set App.Path to a variable and the check if the last character is a "\" or not to be on the safe side. If not then add one:

'=========================
Dim sAppPath As String
Dim sIniFile As String

sAppPath = App.Path

Sp_AddDirSep sAppPath

sIniFile = sAppPath & "\IniFolder\myIniFile.Ini"

'=========================

Public Sub Sp_AddDirSep(ByRef strPathName As String)
If Right(Trim(strPathName), Len(gcSEPDIR$)) <> gcSEPDIR$ Then
strPathName = RTrim$(strPathName) & gcSEPDIR$
End If
End Sub

Collapse -

Relative File Path in VB & Install Prog

by sl-campbell In reply to Relative File Path in VB ...

I do not understand what Answer #2 is trying to imply. The above answer is NOT too complicated for the person who asked the question. It only shows how it should be, or could be, written using better guidlines, and offers even a safeguard proceedureto determine if a dir seperator is present or not.
I am sure that the person who asked the question will know what to do with the code that I posted and how to shorten it if desired.....

Collapse -

Relative File Path in VB & Install Prog

by rsp05 In reply to Relative File Path in VB ...

Poster rated this answer

Collapse -

Relative File Path in VB & Install Prog

by Mohammad_M_Saggaf In reply to Relative File Path in VB ...

Hi,
Answer 1 is correct, but it is complecated.
All you have to do is to use path property of the App object.
Ex:
CF= Open app.path & "\config.ini" For output AS 1

I hope I helped.

Collapse -

Relative File Path in VB & Install Prog

by rsp05 In reply to Relative File Path in VB ...

Poster rated this answer

Collapse -

Relative File Path in VB & Install Prog

by RRV In reply to Relative File Path in VB ...

Redo the installation software. download visual studio installer, create a MSI setup compressed package with windows installer. Forget about ini and config files. Use registry entries instead. In one hour with your VB source code and VS installer you can become a master. it is so simple.

Collapse -

Relative File Path in VB & Install Prog

by rsp05 In reply to Relative File Path in VB ...

Poster rated this answer

Collapse -

Relative File Path in VB & Install Prog

by rsp05 In reply to Relative File Path in VB ...

This question was closed by the author

Back to Web Development Forum
8 total posts (Page 1 of 1)  

Related Discussions

Related Forums