View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Weird Behaviour of Compiler Directives?

Think you misunderstood slightly. The plan was to use the code as
originally quoted and to have one user change the value of Const
LOCATION - which would mean that all differences between the two
sites could be accommodated within the source, and switching for one
location or the other would be a simple matter of changing
Const LOCATION = "HOME"
to
Const LOCATION = "AWAY"
or vice versa.


That's the understanding I got because I do exactly the same thing (in
concept) but go about it as I explained. It just works!

Try it. Paste the code into a module, run it with each of these
variations and see what you get. If you get the same as me, both will
result in "HOME" and "Home".


Using this procedure...

Sub Run_It()
Debug.Print LOCATION & ":" & GOTIT
End Sub

...gave me the following in the Immediate Window...

LOCATION = "HOME"
HOME:Home

LOCATION = "AWAY"
AWAY:Home

I have other options - I already use an .ini file to control
execution, and could add another parameter in there, for instance
(except that that would mean reworking file locations), or I could
add a command line argument and control it that way (except it gets
ugly because I'd have to pass it from task scheduler to outer macro
workbook to inner macro workbook to inner-inner workbook - crazy
restrictions on where macros can be run from). Or, as you say, a
simple file in the same directory as the workbook that could be
checked for existence.


I also use ini files so my apps are portable, thus not using the
Registry for storage. I use the dummy file approach for setting 'flags'
in my apps so they can evaluate startup status or any other things I
want to use them for. In your scenario you could use the dummy file in
your home folder but not at the away location. Your app will then
automaticially know where it's running.

You could also just use your LOCATION constant as described and
initialize a booean to its value...

bHome = (LOCATION = "HOME")

But I'd just like to know why the code I started from doesn't work.


VB[A] isn't liking it; the reason I don't know the answer to. I even
tried 'ElseIf...Then and still nogo! I did get the following results
from this procedure, though...

Sub Run_It()
Dim bHome As Boolean
bHome = (LOCATION = "HOME") '//initialize
Debug.Print "bHome=" & bHome
End Sub

LOCATION = "HOME"
bHome=True

LOCATION = "AWAY"
bHome=False

...which I understand to be the result you want. In the case of away,
LOCATION can be any value or even an empty string!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion