Results 1 to 11 of 11

Thread: #IF #End If

  1. #1

    Thread Starter
    Addicted Member rkeslar's Avatar
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    145

    Question #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

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  3. #3

    Thread Starter
    Addicted Member rkeslar's Avatar
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    145

    Re: #IF #End If

    Quote Originally Posted by MartinLiss View Post
    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

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: #IF #End If

    Quote Originally Posted by RobDog888 View Post
    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.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: #IF #End If

    Here is official msdn documentation if anyone is interested
    #If .. Then .. #Else directive
    #Const directive
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: #IF #End If

    Quote Originally Posted by RobDog888 View Post
    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.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width