I have been asked to buid a VB code which is flexible.Wen i take project from
one place to another,i need not change path in all forms.If i change in one
place,then it gets reflected in all other forms.
ex:In com1,I hav path=e:\proj\a1.MDB which I use in al the forms;
& in com2,I need to change the above path such tat I need to change it only once.
Can I assign the whole path to a variable and declare the whole thing as global??
Is it possible to write
data1.ConnectionString = App.Path + "db1.mdb"
If so where do I define App.Path??
I am new to VB6.pl help

Recommended Answers

All 14 Replies

Hi karthik,
yes you can use app.path ti resolve your connection problem,
we can use it from where ever you need, it takes the application folder path as App.path
that is your Database should placed on the folder where you placed your application.
With addition use can use Subfolder names for example
Quiz is Your application folder name,you placed your Database in the Subfolder "Data"
D:\Quiz\data
in this case
ucan use

App.path & "\Data\Db1.mdb"

unless the palce the Db in Application folder itself and use your code App.path & "\Db1.mdb"

I hope this will help you

With regards
Venkatramasamy SN

OK....but where should I define App.path???

I want to define it only once.so do i need to declare it an any of the forms or do i need
to declare it as public or something.Sorry,I am not familiar with Syntax.

Hi Karthik

Use module
and define it in the module,
yo cann access the module from anywhere

With regards
Venkatramasamy SN

k.thanks.illl try tat...thanx a lot

k.and do i need to connect the module with something???

HI,i tried using a module but it is showing
compile error:invalid outside procedure.

Hi karthik,
In the module write your code in function
the funcation can be accessed from anywhere in the project by using Mudulename.functionname
for example]
Your module name is DBCon
And Functionname is Connection
The code to access the function is

DBCon.Connection

Hope this will help you

With regards
Venkatramasamy SN

hi venkat,
I am really sorry.I dont mean to irritate u.is func syntax something like this??
type def
App.Path = "E:\LATEST"
end type

ok,
then you must place/paste your project in the "E:\LATEST" location in which system you are using ther with, if the problem still exists, kindly send me the details of the sequence details from begining what you do , what you get and what you want

with regards
Venkatramasamy SN

wel i used the following code in al the forms
Data1.DatabaseName = App.Path & "\ATMDB.mdb"
It is working but after unloading it shows some
compilation error

Hi,
Why you failed to notify the error and let me ask you the error details, just directly post all error details getting ok,

then only we can understand your problem in right path,

With regards
Venkatramasamy SN

App.Path is Read Only and is set to the path of the executable file. You shouldn't define this anyway, as a user may chose a different path when installing the program. You can use like App.Path$ & "\Data\MyFile.MDB" and your program will the data directory no matter when the user installed your program.

hi venkat,
I am really sorry.I dont mean to irritate u.is func syntax something like this??
type def
App.Path = "E:\LATEST"
end type

App.Path is a built in value stemming from the prewritten function 'App.'

App.Path should be used on the right hand side of the '=' operator: not on the left hand side like you have it.

Dim strPath as string

strPath = App.Path

Your program should have a default installation path. Microsoft recommends using the 'Program Files' Directory and then the name of your program: e.g. c:\Program Files\My Application\

If you want to change the path your program uses, that type of information should go into your registry:

Option Explicit
Dim strStartUpPath as string
strStartUpPath = APP.path  
' Or
strStartUpPath = strMyChoice

Private Sub Form_Load()
strStartUpPath = GetSetting("MY APP", "Install Defaults", "StartUpPath", "C:\Program FIles\My App")


End sub

hi,
thanx a lot..I got the answer..ill try this also..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.