|
-
Aug 24th, 2009, 11:11 AM
#1
Thread Starter
Addicted Member
#IF #End If
I'm not real familiar with VB6, and in the program I'm working with, it has some conditional statements that begin with a #
#If myVariable <> 1 Then
do something
#End If
What is the purpose of the # sign? How does it make the conditional different from a conditional without the #?
Thanks
-
Aug 24th, 2009, 11:20 AM
#2
Re: #IF #End If
The #If statements are not compiled into the program unless the argument is True. Look in MyProject|Properties|Make and in Conditional Compilation Arguments you'll probably find myVariable.
-
Aug 24th, 2009, 11:22 AM
#3
Thread Starter
Addicted Member
Re: #IF #End If
 Originally Posted by MartinLiss
The #If statements are not compiled into the program unless the argument is True. Look in MyProject|Properties|Make and in Conditional Compilation Arguments you'll probably find myVariable.
I see. That would make sense because these statements are checking to see if the user is using an outdated operating system.
Thanks
Last edited by rkeslar; Aug 24th, 2009 at 11:22 AM.
Reason: grammatical error
-
Aug 24th, 2009, 11:56 AM
#4
Re: #IF #End If
The statements probably are evaluated upon each run instead of specific compile versions for each OS.
Ps, if you dont have any further questions then dont forget to mark your thread Resolved from the Thread Tools menu.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 24th, 2009, 12:04 PM
#5
Re: #IF #End If
 Originally Posted by RobDog888
The statements probably are evaluated upon each run instead of specific compile versions for each OS.
No, they are included in, or left out of, the program at compile time. If included they behave just like any other If.
Last edited by MartinLiss; Aug 24th, 2009 at 12:30 PM.
Reason: correct spelling mistake
-
Aug 24th, 2009, 12:28 PM
#6
Re: #IF #End If
Here is official msdn documentation if anyone is interested
#If .. Then .. #Else directive
#Const directive
-
Aug 25th, 2009, 03:21 AM
#7
Re: #IF #End If
they are included in, or left out of
Wasnt quite sure which way you were meaning Martin but this quote kinda cleared it up for me.
Code excluded during conditional compilation is completely omitted from the final executable file, so it has no size or performance effect.
Thanks, cleared that up for me 
Now I sure do remember seeing msdn code with os platform conditional directives but it didnt state to complie separate explicit versions of your exe. So then compiling on different OS' is the only way to create OS specific versions of your app? Seems cumbersom and counterproductive.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 25th, 2009, 06:05 AM
#8
Re: #IF #End If
 Originally Posted by RobDog888
So then compiling on different OS' is the only way to create OS specific versions of your app? Seems cumbersom and counterproductive.
It isn't the only way, those particular conditions are just something they have provided for you - which made a lot of sense back in the NT/95 days if you were publishing code on the web etc.
You can create+set your own conditions in the Project Properties (on the Make tab), and use them in exactly the same way.
-
Aug 25th, 2009, 07:32 AM
#9
Re: #IF #End If
Another example of using compilation directives. Let's say I have a commercial ocx that has 2 versions, one is a demo version while the other is a release version. The 2 ocx's are actually one. The conditional [#If DEMO Then] runs and compiles only demo-related code and the [#Else] portion runs and compiles only non-demo related code. One can even condition out entire functions and subroutines, or have yet more fun... Creating functions that have different prototypes depending on the directive.
Code:
#If DEMO Then
Private Function HasTrialExceeded(ByVal TrialPeriod As Long) As Boolean
#Else
Private Function ValidateLicense(ByVal Flags As Long, ByVal hWnd As Long) As Boolean
#End If
.... code
End Function
-
Aug 25th, 2009, 08:58 AM
#10
Re: #IF #End If
When you use conditional arguments there is one danger and that is forgetting to turn the argument off when you compile for prodution. To avoid that situation I always include the following Sub which prevents compilation if the argument is still on.
Code:
Public Sub DoNotAllowTestCodeToCompile()
'***************************************************************************
'Purpose: Don't allow the program to compile if Testing = non-zero is set in
' Project > MessagingWizard Properties > Make
'Inputs: None
'Outputs: None
'***************************************************************************
#If Testing Then
Do not compile
#End If
End Sub
-
Aug 27th, 2009, 06:52 PM
#11
Re: #IF #End If
i place my compilation arguments settings in the Comments property of the Make tab. These are visible in the exe's properties when you right click the exe. As you switch args on and off its not always easy to remember what a particular exe's args was compiled with.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|