Home > Archive > Visual Basic Syntax > April 2005 > Problem with public const
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problem with public const
|
|
|
| Hi.
I have taken over a VB6 application, but since I'm no VB6 expert I'm gonna
need a little help here.
The application is creating a directory with some files when it starts up.
It creates 2 files in C:\LT. The path (C:\LT) is defined in a public const
called APP_TEMP_DIR, which is used throughout the application. I've been
asked to change this so that the directory LT is created in program files
instead. But I can't change the value of the constant to "C:\program files"
because sometimes program files is located on the D:\ drive. I've been
asked to use an environment variable called "ProgramFiles" instead.
First I tried to do it like this: Public Const APP_TEMP_DIR =
Environ("ProgramFiles") but that didn't work. So I changed the variable
from being a constant and just declared it as a string instead. Then in the
Main() sub I called upon the environment variable. I then got another
problem. The APP_TEMP_DIR variable was used as a part of an optional
parameter in a function and I got an error saying "Compile error: Constant
expression required" The function looks like this:
Public Function Present_Text_In_Excel(sString$, Optional sFileName$ =
APP_TEMP_DIR & "\tmp.csv") As String
I'm stuck here so I would really appreciate if someone could help me out.
Thanks,
Shawn
| |
| Jan Hyde 2005-04-11, 8:58 am |
| "Shawn" <bossman100@hotmail.com>'s wild thoughts were
released on Mon, 11 Apr 2005 11:21:20 +0200 bearing the
following fruit:
>Hi.
>I have taken over a VB6 application, but since I'm no VB6 expert I'm gonna
>need a little help here.
>
>The application is creating a directory with some files when it starts up.
>It creates 2 files in C:\LT. The path (C:\LT) is defined in a public const
>called APP_TEMP_DIR, which is used throughout the application. I've been
>asked to change this so that the directory LT is created in program files
>instead. But I can't change the value of the constant to "C:\program files"
>because sometimes program files is located on the D:\ drive. I've been
>asked to use an environment variable called "ProgramFiles" instead.
>
>First I tried to do it like this: Public Const APP_TEMP_DIR =
>Environ("ProgramFiles") but that didn't work. So I changed the variable
>from being a constant and just declared it as a string instead. Then in the
>Main() sub I called upon the environment variable. I then got another
>problem. The APP_TEMP_DIR variable was used as a part of an optional
>parameter in a function and I got an error saying "Compile error: Constant
>expression required" The function looks like this:
>Public Function Present_Text_In_Excel(sString$, Optional sFileName$ =
>APP_TEMP_DIR & "\tmp.csv") As String
>
>I'm stuck here so I would really appreciate if someone could help me out.
Change it to something like this
Public Function Present_Text_In_Excel(sString As String,
Optional sFileName As String) As String
If sfFilename = "" Then
sFileName = APP_TEMP_DIR & "\tmp.csv"
End If
End Function
Jan Hyde (VB MVP)
--
A short cut is the longest distance between two points.
[Abolish the TV Licence - http://www.tvlicensing.biz/]
|
|
|
|
|