473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Am trying to understand #If ... #Then

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
22 6263
> 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
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
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
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
> 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
* 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
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
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
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
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
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
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
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
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
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
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
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
> 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
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
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
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
>> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Chad Lupkes | last post by:
Here is the code I found: <script language="JavaScript"> <!-- if (parent.frames.length > 0) { parent.location.href = location.href; } --> </script>
10
by: Anon Email | last post by:
In the code below, what does this mean? mine = (short *)0; -------------- #include <iostream> int main() {
51
by: Richard Hengeveld | last post by:
Hi all, I'm trying to understand how pointers for function parameters work. As I understand it, if you got a function like: void f(int *i) { *i = 0; }
13
by: cj | last post by:
Stephany Young provided me with the following code to count threads created by my program. Public Class MyThreadCount Private Shared m_lock As New Object Private Shared m_threadcount As Int32...
17
by: Sam Malone | last post by:
I am trying to get details from a database. I really want to use only native VS.NET managed code "stuff" (just cuz I want to) and avoid any interop stuff. So, I'm trying to do this without using...
3
by: skosmicki | last post by:
I need to create an function similar to the "MATCH" function in Excel that evaluates a number within a set of numbers and returns whether there is a match. I have put the example of what I see in...
5
by: Alan Silver | last post by:
Hello, Server configuration: Windows 2003 Server SP2 SQL Server 2000 SP4 ..NET v2.0.50727 just built up a new server using the same configuration as my current one. I even used the same CDs...
12
by: thegman | last post by:
Hi all, I'm trying to get list of JavaScript methods/functions in a script file in much the same a good text editor will, the difference being that I need to output it to a file or stdout, or some...
6
by: CD1 | last post by:
#include <string> This code won't compile. There is no variable called "foo2". :)
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.