Discussion Locked

Relative File Path in VB & Install Prog

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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 D:\MAINFOLDER to D:\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!

8 replies

by sl-campbell

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

by sl-campbell

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.....

by mohammad_m_saggaf

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.

by rrv

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.

This discussion is closed to new replies.