By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Am trying to understand #If ... #Then

P: n/a
MLH
I would like to test some of this code in the debug window...

Option Compare Database
Option Explicit

Private Sub Command0_Click()
#If Win32 Then
MsgBox "Hey! It's WIN32."
#End If
End Sub

Private Sub Command1_Click()
#If Win16 Then
MsgBox "Hey! It's WIN16."
#End If
End Sub

I'm not getting very far. A97 Help doesn't break it down, simplifying
the directive for me to grasp it. What, exactly, does #If directive
do? And, where do the values for Win32 and Win16 come from?
Are they intrinsic constants?
May 19 '06 #1
Share this Question
Share on Google+
22 Replies


P: n/a
> I'm not getting very far. A97 Help doesn't break it down, simplifying
the directive for me to grasp it. What, exactly, does #If directive
do? And, where do the values for Win32 and Win16 come from?
Are they intrinsic constants?


Look at this piece of code:

================================
Option Compare Database
Option Explicit

#Const IWantLateBinding = True

#If IWantLateBinding Then
Dim myWord as Object
#Else
Dim myWord as Access.Application
#End If

Private Sub Form_Load()
#If IWantLateBinding Then
Set myWord = CreateObject("Access.Application")
#Else
Set myWord = New Access.Application
#End If
End Sub
================================

The "#If....#Then....#Else....#End If" construct is part of "conditional
compilation".
The "#Const...." declaration is the other part.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
May 19 '06 #2

P: n/a
The #If... #End If construct is a conditional compilation test.

The easiest way to see it's effect is to create your own conditional
compilation constant.

e.g.
' This is the conditional compilation constant.
#Const InDebug = False

Function TestInDebug()
#If InDebug Then
MsgBox "We're debugging"
#Else
MsgBox "We're not debugging"
#End If
End Function

Now, you probably realise that you can get the same effect with a normal
If... End If construct but consider the following as a solution to a common
problem.

Create a reference to Microsoft Word and then use the following code:-

#Const InDebug = True

Function TestInDebug()
#If InDebug Then
Dim oWord As Word.Application

Set oWord = New Word.Application
#Else
Dim oWord As Object

Set oWord = CreateObject("Word.Application")
#End If

' This bit doesn't need to conditionally compile
With oWord
.Visible = True
.Quit False
End With

Set oWord = Nothing
End Function

The first thing to notice is if
#Const InDebug = True

.... then when the line
oWord.Quit False

.... is typed we get context sensitive dropdowns, if on the other hand
#Const InDebug = False

.... then we don't

The second thing to notice is that while we have the reference to Word the
code runs quite happily with the conditional compilation constant set to
True or False. If we remove the reference toWord and the conditional
compilation constant is set to False then the code will run, if on the other
hand we set the conditional compilation constant to True then we get an
error "User-defined type not defined" and "oWord As Word.Application" is
highlighted

Defining a conditional compilation constant in a module makes that constant
have scope only in the module it is defined in, if however you go to the
Tools menu and choose "<Your Application name> Properties" from the menu you
can define conditional compilation constants (as a semi-colon delimited
list) which have application level scope.
--

Terry Kreft
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
I would like to test some of this code in the debug window...

Option Compare Database
Option Explicit

Private Sub Command0_Click()
#If Win32 Then
MsgBox "Hey! It's WIN32."
#End If
End Sub

Private Sub Command1_Click()
#If Win16 Then
MsgBox "Hey! It's WIN16."
#End If
End Sub

I'm not getting very far. A97 Help doesn't break it down, simplifying
the directive for me to grasp it. What, exactly, does #If directive
do? And, where do the values for Win32 and Win16 come from?
Are they intrinsic constants?

May 19 '06 #3

P: n/a
MLH
Thanks, Gabriele, for the explanation and the
example. I have a form with its own class module.
The form has only 2 buttons and the code running
for each button is shown below. What I didn not
understand was that the values of WIN16 and WIN32 'compiler constants'
can be read ONLY within the confines of an #If - #Then
construct - and nowhere else.

Terry Kreft also provided a fine example. Do you know
what specific common problem Terry was referring to
early in his comments on the post?
May 20 '06 #4

P: n/a
MLH
On Fri, 19 May 2006 19:36:47 +0100, "Terry Kreft"
<te*********@mps.co.uk> wrote:
The #If... #End If construct is a conditional compilation test.

The easiest way to see it's effect is to create your own conditional
compilation constant.

e.g.
' This is the conditional compilation constant.
#Const InDebug = False

Function TestInDebug()
#If InDebug Then
MsgBox "We're debugging"
#Else
MsgBox "We're not debugging"
#End If
End Function

Now, you probably realise that you can get the same effect with a normal
If... End If construct but consider the following as a solution to a common
problem.

<snip>
Thx for the example, Terry. I am still struggling to see
the benefits of the #If construct. Your mentioning of
'a common problem' must be the key. I'm not sure I
know what the common problem is or that I've ever
encountered it.
May 20 '06 #5

P: n/a
> Thanks, Gabriele, for the explanation and the
example. I have a form with its own class module.
The form has only 2 buttons and the code running
for each button is shown below. What I didn not
understand was that the values of WIN16 and WIN32 'compiler constants'
can be read ONLY within the confines of an #If - #Then
construct - and nowhere else.
And now do you understand it?
Terry Kreft also provided a fine example. Do you know what specific
common problem Terry was referring to early in his comments on the
post?


The problem that Terry reported is well know as "early-binding problem".
In that case, you are using Office Automation: early-binding can lead you
to unexpected runtime errors, while compiling is always ok; late-binding
let Access Runtime solve the binding problem for you, without need to know
which version of Office Application is installed on client machine.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
May 20 '06 #6

P: n/a
* MLH:
On Fri, 19 May 2006 19:36:47 +0100, "Terry Kreft"
<te*********@mps.co.uk> wrote:
The #If... #End If construct is a conditional compilation test.

The easiest way to see it's effect is to create your own conditional
compilation constant.

e.g.
' This is the conditional compilation constant.
#Const InDebug = False

Function TestInDebug()
#If InDebug Then
MsgBox "We're debugging"
#Else
MsgBox "We're not debugging"
#End If
End Function

Now, you probably realise that you can get the same effect with a normal
If... End If construct but consider the following as a solution to a common
problem.

<snip>
Thx for the example, Terry. I am still struggling to see
the benefits of the #If construct. Your mentioning of
'a common problem' must be the key. I'm not sure I
know what the common problem is or that I've ever
encountered it.


Many developers like to use early binding for automation code,
connecting to Word, Excel, etc, while developing and debugging because
they have the advantage of VBA Intellisense, object browser and so on.
They switch to late binding before compiling and shipping a project, to
make it independent of the versions installed on user systems.

Switching to late binding requires removing the reference and changing
the code declarations, as shown in Kreft's example. The sample that he
provided showed a way to add both types of reference to the code with
the single constant used to select in which mode it would operate. The
only way to accomplish that is with the conditional compile directive.
With a standard If..Then, it would fail on the compile, once the
reference were removed.

Hope that clarifies it.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
May 20 '06 #7

P: n/a
What you've got to remember is that the code you write goes through two
stages in order to run it. The first stage is compilation, the second stage
is the running of that compiled code.

The If... End If construct we all use controls program flow at run-time.
The #If... #End If construct controls compilation flow.

The purpose of the #If... #End If construct is to allow you to select the
code to be included in the compilation process and subsequently in the
run-time.

The classic uses of #If... #End If are:-
1) Change the code to be compiled in the development/debug environment
from that used in the release version
2) Change the code to be compiled when the platform changes (typically
between 16 bit and 32 bit windows)

As others have pointed out the common problem I was talking about was that
of automating MS Word from Access.

Microsoft broke the rules when developing the COM interfaces for Office
products by not making it possible to discover through typing of interfaces
which version you were working with therefore making it impossible to early
bind to those applications unless you knew the version you were targeting
when you wrote the code.

As has been pointed out by others, the way developers normally work to get
round this is, to develop using early binding and then change over to late
binding when they release the application. Conditional compilation allows
you to do this easily by changing a single value instead of editing all of
your code.

To give an idea of how common this problem is I did a search on Google just
in CDMA on "Word Early Binding" and returned 173 results, at least one of
the threads included was started by you <g>.
--

Terry Kreft
"MLH" <CR**@NorthState.net> wrote in message
news:ab********************************@4ax.com...
On Fri, 19 May 2006 19:36:47 +0100, "Terry Kreft"
<te*********@mps.co.uk> wrote:
The #If... #End If construct is a conditional compilation test.

The easiest way to see it's effect is to create your own conditional
compilation constant.

e.g.
' This is the conditional compilation constant.
#Const InDebug = False

Function TestInDebug()
#If InDebug Then
MsgBox "We're debugging"
#Else
MsgBox "We're not debugging"
#End If
End Function

Now, you probably realise that you can get the same effect with a normal
If... End If construct but consider the following as a solution to a commonproblem.

<snip>
Thx for the example, Terry. I am still struggling to see
the benefits of the #If construct. Your mentioning of
'a common problem' must be the key. I'm not sure I
know what the common problem is or that I've ever
encountered it.

May 21 '06 #8

P: n/a
MLH wrote:
the benefits of the #If construct. Your mentioning of
'a common problem' must be the key. I'm not sure I
know what the common problem is or that I've ever
encountered it.


One of my common problems is code alternatives
for optimizations.
Often I write sql from analysis, then optimize
for the db engine(s), maybe JET.
The fragments are all over the project.
A single switch selects all code from one
version. That's pretty convenient for equivalence
testing and performance comparison.
The original sql is kept for documenting
the often confusing optimizations.

Paul
May 21 '06 #9

P: n/a
Noticeably less useful in A2000 than it was in A97,
because in A2000 all of the code must be valid code.

In A97 I could write code like this:

#if False then
this is a bunch of comments and invalid test code
v =
v = dlookup(,,)
v = dcount(,,)
#end if

In A2000, that module fails to compile, because all
the code has to be valid, even inside the conditional
compilation test.

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
I would like to test some of this code in the debug window...

Option Compare Database
Option Explicit

Private Sub Command0_Click()
#If Win32 Then
MsgBox "Hey! It's WIN32."
#End If
End Sub

Private Sub Command1_Click()
#If Win16 Then
MsgBox "Hey! It's WIN16."
#End If
End Sub

I'm not getting very far. A97 Help doesn't break it down, simplifying
the directive for me to grasp it. What, exactly, does #If directive
do? And, where do the values for Win32 and Win16 come from?
Are they intrinsic constants?

May 22 '06 #10

P: n/a
They must have fixed this in later versions as this compiles in A2003.
--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Noticeably less useful in A2000 than it was in A97,
because in A2000 all of the code must be valid code.

In A97 I could write code like this:

#if False then
this is a bunch of comments and invalid test code
v =
v = dlookup(,,)
v = dcount(,,)
#end if

In A2000, that module fails to compile, because all
the code has to be valid, even inside the conditional
compilation test.

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
I would like to test some of this code in the debug window...

Option Compare Database
Option Explicit

Private Sub Command0_Click()
#If Win32 Then
MsgBox "Hey! It's WIN32."
#End If
End Sub

Private Sub Command1_Click()
#If Win16 Then
MsgBox "Hey! It's WIN16."
#End If
End Sub

I'm not getting very far. A97 Help doesn't break it down, simplifying
the directive for me to grasp it. What, exactly, does #If directive
do? And, where do the values for Win32 and Win16 come from?
Are they intrinsic constants?


May 22 '06 #11

P: n/a
Gosh! It's been fixed in A2K also.

In A97, we used conditional compilation to do
block comments. One of the problems in our downgrade
from A97 to A2K was the failure of that coding
practice.

Either that, or we just got very confused, but given
the problems it caused, I think I'm right.

(david)
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:Ls********************@karoo.co.uk...
They must have fixed this in later versions as this compiles in A2003.
--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Noticeably less useful in A2000 than it was in A97,
because in A2000 all of the code must be valid code.

In A97 I could write code like this:

#if False then
this is a bunch of comments and invalid test code
v =
v = dlookup(,,)
v = dcount(,,)
#end if

In A2000, that module fails to compile, because all
the code has to be valid, even inside the conditional
compilation test.

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
>I would like to test some of this code in the debug window...
>
> Option Compare Database
> Option Explicit
>
> Private Sub Command0_Click()
> #If Win32 Then
> MsgBox "Hey! It's WIN32."
> #End If
> End Sub
>
> Private Sub Command1_Click()
> #If Win16 Then
> MsgBox "Hey! It's WIN16."
> #End If
> End Sub
>
> I'm not getting very far. A97 Help doesn't break it down, simplifying
> the directive for me to grasp it. What, exactly, does #If directive
> do? And, where do the values for Win32 and Win16 come from?
> Are they intrinsic constants?



May 23 '06 #12

P: n/a
Well, it says it all that I didn't even consider you might be wrong; I would
believe that they broke any number of things going from A97 to A2k,

--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Gosh! It's been fixed in A2K also.

In A97, we used conditional compilation to do
block comments. One of the problems in our downgrade
from A97 to A2K was the failure of that coding
practice.

Either that, or we just got very confused, but given
the problems it caused, I think I'm right.

(david)
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:Ls********************@karoo.co.uk...
They must have fixed this in later versions as this compiles in A2003.
--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Noticeably less useful in A2000 than it was in A97,
because in A2000 all of the code must be valid code.

In A97 I could write code like this:

#if False then
this is a bunch of comments and invalid test code
v =
v = dlookup(,,)
v = dcount(,,)
#end if

In A2000, that module fails to compile, because all
the code has to be valid, even inside the conditional
compilation test.

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
>I would like to test some of this code in the debug window...
>
> Option Compare Database
> Option Explicit
>
> Private Sub Command0_Click()
> #If Win32 Then
> MsgBox "Hey! It's WIN32."
> #End If
> End Sub
>
> Private Sub Command1_Click()
> #If Win16 Then
> MsgBox "Hey! It's WIN16."
> #End If
> End Sub
>
> I'm not getting very far. A97 Help doesn't break it down, simplifying
> the directive for me to grasp it. What, exactly, does #If directive
> do? And, where do the values for Win32 and Win16 come from?
> Are they intrinsic constants?



May 23 '06 #13

P: n/a
Well, it says it all that I didn't even consider you might be wrong; I would
believe that they broke any number of things going from A97 to A2k,

--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Gosh! It's been fixed in A2K also.

In A97, we used conditional compilation to do
block comments. One of the problems in our downgrade
from A97 to A2K was the failure of that coding
practice.

Either that, or we just got very confused, but given
the problems it caused, I think I'm right.

(david)
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:Ls********************@karoo.co.uk...
They must have fixed this in later versions as this compiles in A2003.
--

Terry Kreft
"david epsom dot com dot au" <david@epsomdotcomdotau> wrote in message
news:44***********************@lon-reader.news.telstra.net...
Noticeably less useful in A2000 than it was in A97,
because in A2000 all of the code must be valid code.

In A97 I could write code like this:

#if False then
this is a bunch of comments and invalid test code
v =
v = dlookup(,,)
v = dcount(,,)
#end if

In A2000, that module fails to compile, because all
the code has to be valid, even inside the conditional
compilation test.

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:5t********************************@4ax.com...
>I would like to test some of this code in the debug window...
>
> Option Compare Database
> Option Explicit
>
> Private Sub Command0_Click()
> #If Win32 Then
> MsgBox "Hey! It's WIN32."
> #End If
> End Sub
>
> Private Sub Command1_Click()
> #If Win16 Then
> MsgBox "Hey! It's WIN16."
> #End If
> End Sub
>
> I'm not getting very far. A97 Help doesn't break it down, simplifying
> the directive for me to grasp it. What, exactly, does #If directive
> do? And, where do the values for Win32 and Win16 come from?
> Are they intrinsic constants?




May 23 '06 #14

P: n/a
Terry Kreft wrote:
Well, it says it all that I didn't even consider you might be wrong; I would
believe that they broke any number of things going from A97 to A2k,


Lotsa peoples' hearts.

May 23 '06 #15

P: n/a
True, too true.

--

Terry Kreft
"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11*********************@j73g2000cwa.googlegro ups.com...
Terry Kreft wrote:
Well, it says it all that I didn't even consider you might be wrong; I would believe that they broke any number of things going from A97 to A2k,


Lotsa peoples' hearts.

May 23 '06 #16

P: n/a
Yikes!! I just did a test of this in Access 2003, and it's still broken.
Let me be sure I'm testing properly. I have a form with one button. This
is the code for the form:

Option Compare Database
Option Explicit

Const whichone As Long = 1

Private Sub Command0_Click()

#If whichone = 0 Then
MsgBox "I am zero"
#Else
MsgBox "I am one"
#End If

End Sub
I fully expected to be able to change the value of whichone and see a
different message when I clicked the button. However, the only message I
ever see is "I am zero". So this STILL does not work?
May 23 '06 #17

P: n/a
MLH
Good explanation. Thx, Terry. I have a
fundamental understanding of the principle
now. Its pretty much outside my box. I don't
do much automation with the microsoft suite
of products - later perhaps.
May 23 '06 #18

P: n/a
> Const whichone As Long = 1

Private Sub Command0_Click()
#If whichone = 0 Then
MsgBox "I am zero"
#Else
MsgBox "I am one"
#End If
End Sub

I fully expected to be able to change the value of whichone and see a
different message when I clicked the button. However, the only
message I ever see is "I am zero". So this STILL does not work?


You made two mistakes.
1) All conditional compilation statement must be preceeded by a "#" sign.
2) As every constant in VBA, you cannot specify a type

So your constant definition become

# Const whichone = 1

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
May 24 '06 #19

P: n/a
Thanks for responding, but this is from the help topic for #IF:

Example:
#If...Then...#Else Directive Example
This example references conditional compiler constants in an
#If...Then...#Else construct to determine whether to compile certain
statements.

' If Mac evaluates as true, do the statements following the #If.
#If Mac Then
'. Place exclusively Mac statements here.
'.
'.
' Otherwise, if it is a 32-bit Windows program, do this:
#ElseIf Win32 Then
'. Place exclusively 32-bit Windows statements here.
'.
'.
' Otherwise, if it is neither, do this:
#Else
'. Place other platform statements here.
'.
'.
#End If
I see no mention of preceding code lines with #. In addition, when I try to
do so in my forms's module, I get an immediate error.Item 2: Constants.
YOu absolutely can identify the type. Here are a few of the scores of such
lines I use in an existing app:Public Const ITEM_CONTEXT As String =
"Context"Public Const ITEM_DOCUMENT As String = "Document"Public Const
ITEM_EMAILLISTNAME As String = "EmailListName"Public Const
ITEM_USEHARVESTEDLIST As String = "UseHarvestedList"Public Const
ITEM_CALLINGFORM As String = "CallingForm"Public Const
ITEM_ALTERNATEEMAILNAME As String = "AlternateEmailName"'User preference
codesPublic Const UPREF_FIRSTMENU As String = "FirstMenu"Public Const
UPREF_SCISRCHFLTR_BU_ORIG As String = "SciSrchFltr_BU_Orig"Public Const
UPREF_SCISRCHFLTR_BU_RCV As String = "SciSrchFltr_BU_Rcv"Public Const
UPREF_SPARSRCHFLTR_BU_ORIG As String = "SPARSrchFltr_BU_Orig"Public Const
UPREF_SPARSRCHFLTR_BU_RCV As String = "SPARSrchFltr_BU_Rcv"'Item name
strings used to work with values in control tags with adhGetItem et al'The
count in the comment refers to the number of controls found containing the
value on the date shownPublic Const TAGELEMENT_Field As String = "Field"
'3/29/2006 count=687Public Const TAGELEMENT_NullOK As String = "NullOK"
'3/29/2006 count=221Public Const TAGELEMENT_UserRole As String = "UserRole"
'3/29/2006 count=185Public Const TAGELEMENT_SignatureGroup As String =
"SignatureGroup" '3/29/2006 count=161Public Const
TAGELEMENT_Function As String = "Function"
'3/29/2006 count=160Public Const TAGELEMENT_PrimaryKey As String =
"PrimaryKey" '3/29/2006 count=77Public Const
TAGELEMENT_OKToRestoreColumnWidth As String = "OKToRestoreColumnWidth"
'3/29/2006 count=69Public Const TAGELEMENT_DefaultWidth As String =
"DefaultWidth" '3/29/2006 count=69Public Const
TAGELEMENT_StandardUserDropdown As String = "StandardUserDropdown"
'3/29/2006 count=33Works just fine. And, it appears, so does conditional
compilation. Here's what I was doing wrong:For conditional compilation, if
you want to test against a constant, then THAT constant, and only that
constant in addition to the #IF/#ELSE/#END IF must be preceded by a "#".
And (I guess this is what you had in mind) you CANNOT specify a type for
THAT constant. Fine for any others, just not that one.Thanks for the reply.
It sent me off in the right direction to find my answer.Glad to see
conditional compilation working perfectly. Now if I could just remember
what it was I used to want to use it for. Probably not relevant any more
anyway."PBsoft" <in**@REMOVEpbsoft.it> wrote in message
news:87**************************@news.tin.it...
Const whichone As Long = 1

Private Sub Command0_Click()
#If whichone = 0 Then
MsgBox "I am zero"
#Else
MsgBox "I am one"
#End If
End Sub

I fully expected to be able to change the value of whichone and see a
different message when I clicked the button. However, the only
message I ever see is "I am zero". So this STILL does not work?


You made two mistakes.
1) All conditional compilation statement must be preceeded by a "#" sign.
2) As every constant in VBA, you cannot specify a type

So your constant definition become

# Const whichone = 1

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution

May 24 '06 #20

P: n/a
Yikes. My copy/paste did not turn out as I expected. Here is the same
post, formatted so that a human being could read it:

Thanks for responding, but this is from the help topic for #IF:

Example:
#If...Then...#Else Directive Example
This example references conditional compiler constants in an
#If...Then...#Else construct to determine whether to compile certain
statements.

' If Mac evaluates as true, do the statements following the #If.
#If Mac Then
'. Place exclusively Mac statements here.
'.
'.
' Otherwise, if it is a 32-bit Windows program, do this:
#ElseIf Win32 Then
'. Place exclusively 32-bit Windows statements here.
'.
'.
' Otherwise, if it is neither, do this:
#Else
'. Place other platform statements here.
'.
'.
#End If
I see no mention of preceding code lines with #. In addition, when I try to
do so in my forms's module, I get an immediate error.

Item 2: Constants. YOu absolutely can identify the type. Here are a few of
the scores of such
lines I use in an existing app:

Public Const ITEM_CONTEXT As String = "Context"Public Const ITEM_DOCUMENT As
String = "Document"
Public Const ITEM_EMAILLISTNAME As String = "EmailListName"
Public Const ITEM_USEHARVESTEDLIST As String = "UseHarvestedList"
Public Const ITEM_CALLINGFORM As String = "CallingForm"
Public Const ITEM_ALTERNATEEMAILNAME As String = "AlternateEmailName"
'User preference codes
Public Const UPREF_FIRSTMENU As String = "FirstMenu"
Public Const UPREF_SCISRCHFLTR_BU_ORIG As String = "SciSrchFltr_BU_Orig"
Public Const UPREF_SCISRCHFLTR_BU_RCV As String = "SciSrchFltr_BU_Rcv"
Public Const UPREF_SPARSRCHFLTR_BU_ORIG As String = "SPARSrchFltr_BU_Orig"
Public Const UPREF_SPARSRCHFLTR_BU_RCV As String = "SPARSrchFltr_BU_Rcv"
'Item name strings used to work with values in control tags with adhGetItem
et al
'The count in the comment refers to the number of controls found containing
the value on the date shown
Public Const TAGELEMENT_Field As String = "Field" '3/29/2006 count=687
Public Const TAGELEMENT_NullOK As String = "NullOK" '3/29/2006 count=221
Public Const TAGELEMENT_UserRole As String = "UserRole" '3/29/2006 count=185
Public Const TAGELEMENT_SignatureGroup As String = "SignatureGroup"
'3/29/2006 count=161

(remainder deleted because the point is made)
Works just fine. And, it appears, so does conditional compilation. Here's
what I was doing wrong:For conditional compilation, if
you want to test against a constant, then THAT constant, and only that
constant in addition to the #IF/#ELSE/#END IF must be preceded by a "#".
And (I guess this is what you had in mind) you CANNOT specify a type for
THAT constant. Fine for any others, just not that one.Thanks for the reply.
It sent me off in the right direction to find my answer.Glad to see
conditional compilation working perfectly. Now if I could just remember
what it was I used to want to use it for. Probably not relevant any more
anyway.

"PBsoft" <in**@REMOVEpbsoft.it> wrote in message
news:87**************************@news.tin.it...
Const whichone As Long = 1

Private Sub Command0_Click()
#If whichone = 0 Then
MsgBox "I am zero"
#Else
MsgBox "I am one"
#End If
End Sub

I fully expected to be able to change the value of whichone and see a
different message when I clicked the button. However, the only
message I ever see is "I am zero". So this STILL does not work?


You made two mistakes.
1) All conditional compilation statement must be preceeded by a "#" sign.
2) As every constant in VBA, you cannot specify a type

So your constant definition become

# Const whichone = 1

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution


May 25 '06 #21

P: n/a
PBsoft wrote:
2) As every constant in VBA, you cannot specify a type


I specify constant types regularly. Please, review your basis for this
assertion.

May 25 '06 #22

P: n/a
>> 2) As every constant in VBA, you cannot specify a type
I specify constant types regularly. Please, review your basis for this
assertion.


Sorry, I was wrong.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
May 25 '06 #23

This discussion thread is closed

Replies have been disabled for this discussion.