Question

Locked

Can someone explain to me the #IF #Else #End If in VB6, Google not helping

By Slayer_ ·
With the # prefix.

I have been finding odd code examples with stuff like

<pre>
#If iVersion > 5 then
Public sub Sample()
Dim iTest as double
#Else
Public sub Sample()
Dim iTest as integer
#End If
'Do stuff
End Sub
</pre>

Even this with declaring constants, changing their value based on a runtime condition.

<pre>
#If iVersion > 5 then
const sTest as string ="VERSION 5"
#Else
const sTest as string ="VERSION (1-4)"
#End If
</pre>

It seems google is filtering out the # in my searches and only telling me about basic if statements, and otherwise, of different languages where it is normally valid.

Can someone explain these to me, or a website explaining them?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Compiler directives, here's a link

by Tony Hopkinson In reply to Can someone explain to me ...

http://visualbasic.freetutes.com/learn-vb6-advanced/lesson20/p19.html.

Sometimes call pre-processor directives.
Basically they execute like a marco over the source before it gets compiled.
So you can say
#ifdef (DEBUG)
WriteToSomeLog(doing this)
#endif

So while you are developing and testing you set debug to true, then when you are happy compile it with false and none of your debugging help gets compiled into the app.

Lots of uses, guess the one you mention is to bea nel to keep and old and new version of some function going for a while.
Don't go mad with them though, they are easy to forget and can make your code unreadable.

Collapse -

Ah, thats what to call em

by Slayer_ In reply to Compiler directives, here ...

Thanks dude.
I do love this tech site.

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Forums