Link to home
Start Free TrialLog in
Avatar of guidway
guidwayFlag for United States of America

asked on

setting result from environ to a constant

How can I do this (or something similar):

Public Const PATHDIRECTORY = environ$("PROJECTPATH")

Basically I want to define the result of an environment variable as a constants so I can just plug in that value anywhere in my code. Any suggestions? thanks in advance,

guidway
Avatar of rspahitz
rspahitz
Flag of United States of America image

This really cannot be done because a constant is just that: a value that remains constant.  Since it can vary based on computer settings, it's not constant.

The way around this is to simply create a global variable then use that:

' define this either in the start-up form, or preferrably a "global" module.
Public PATHDIRECTORY

' In the start-up sequence, do this:
PATHDIRECTORY = environ$("PROJECTPATH")

' This can be done in the start-up form's Load event procedure or in Sub Main.
Oh, and you probably want it as a string:

Public PATHDIRECTORY as String

If yuor convention is to use upper case for constants, this will be consistent with your app: even though the variable is technically not a constant, it is acting as one since the value will never change within the life of the application.
Avatar of guidway

ASKER

The problem is I have about 100 constants declared in this way:

Public Const PATHDIRECTORY = "C:\My directory"

public Const HELPDIRECTORY = PATHDIRECTORY & "\help"

and so forth...

if I go back and change PATHDIRECTORY so it is no longer a constant I will not be able to use it in all of my other constants (since it it no longer a constant). The only thing I can see is I would have to remove all my constants and use all global variables (which probably is considered bad coding). Is this the only way to get it to work? Any other ideas? If worse comes to worse I'll use it. Thanks,

guidway
ASKER CERTIFIED SOLUTION
Avatar of rspahitz
rspahitz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of guidway

ASKER

I see what you mean. That might be the best way to do it. Will give it a try in the morning. here's a little more detail of what I want maybe you will think of something else knowing this:

My overall goal is to be able to create a dynamic program that the user can install on any drive letter (not having the drive letter hard coded into the program) from there my program will create any necessary directories it needs to use under that drive letter. It might be better if I just prompted the user for a Drive when my app first runs. Well, I'll try your's first and see what I think. thanks, again,

guidway
Avatar of nahumd
nahumd

I guess you know that you can get the application path with the command "App.Path".
Avatar of guidway

ASKER

rspahtiz,

Sorry, I haven't had time to look at your info yet. My company has kept me busy since I posted the question. I did not forget about it. As soon as I get a chance I'll let you know if it works,

guidway
That's fine.  The same happens to me all the time.  Take a week or two; if it takes a month or more, just make a decision to accept or reject the idea.
Avatar of guidway

ASKER

thanks rspahitz! I still haven't looked at the code, but I believe it will work and unless I accept an answer now, I'll forget about the question. Thanks again for the help.

guidway