TODO #1035

    #If #EndIf block was not upgraded because the expression %1 did not evaluate to True or was not evaluated.

    Description 

    The #If #EndIf directives are evaluated by the VBUC preprocessing engine during the preliminary stage of the upgrade process. The current compiler-variable values are taken into consideration to figure out which blocks of code are active and which are inactive. The active blocks are upgraded to .NET while the inactive ones are copied unchanged to the upgraded code and preceded by the 1035 EWI.

    Recommendations

    Often times conditional compilation directives might be missing and not all code paths will be expressed. Conditional compilation constants can be defined in three different ways in VB6:

     

       
    How Set Scope
    Project Properties dialog box Public to all modules in the project
    Command line Public to all modules in the project
    #Const statement in code Private to the module in which they are declared

     

    Knowing the scope of these constants can help when modifying the code to correct this EWI.

    • If the inactive code is small and simple, it can safely be rewritten manually.

    • However, if the conditionally compiled code is extensive, an extra migration might be required. Different values of the conditional constants can be used for all valid permutations. This will convert previously inactive blocks of code. The results can then be manually merged to get a fully converted code block.

    • In some cases, it might be possible to comment out the conditionally compiled code segments completely. This will only work though, if there are no conflicts and the original code the application can be upgraded without the conditional compilation directives. CAUTION: in order to apply this work around the original code should compile.

    • Some inactive blocks of code might no longer be in use. If this is the case then those code segments can be removed.

    Special care should be taken when reviewing conditionally compiled code. Locally declared variables have no effect and are not used for evaluation of conditional compilation directives, such as in Example #2.

    Sample VB6

    #Const ShowMessage = -1 'True

     

    PublicSub ConditionalCompilation()

    'ShowMessage is True

    #If ShowMessage Then

    MsgBox "It will show this message!"

    #Else

    MsgBox "This text will not show!"

    #EndIf

    EndSub

     

    PublicSub ImproperConditionalCompilation()

    Dim show AsBoolean

    Set show = True

    ' show is a local variable, and is not

    ' used for conditional compilation

    #If show Then

    MsgBox "This text will not show!"

    #Else

    'This message box is shown.

    MsgBox "It will show this message!"

    #EndIf

    EndSub

    Target VB.NET

    #Const ShowMessage = -1'True

     

    PublicSub ConditionalCompilation()

    #If ShowMessage Then

    MessageBox.Show("It will show this message!", Application.ProductName)

    #Else

    'UPGRADE_TODO: (1035) #If #EndIf block was not upgraded because the expression Else did not evaluate to True or was not evaluated.

    MsgBox "This text will not show!"

    #EndIf

    EndSub

     

    PublicSub ImproperConditionalCompilation()

    Dim show AsBoolean = True

     

    #If show Then

    'UPGRADE_TODO: (1035) #If #EndIf block was not upgraded because the expression show did not evaluate to True or was not evaluated.

    MsgBox "This text will not show!"

    #Else

    MessageBox.Show("It will show this message!", Application.ProductName)

    #EndIf

    EndSub

    Expected VB.NET

    #Const ShowMessage = -1'True

     

    PublicSub ConditionalCompilation()

    #If ShowMessage Then

    MessageBox.Show("It will show this message!", Application.ProductName)

    #Else

    MessageBox.Show("This text will not show!", Application.ProductName)

    #EndIf

    EndSub

     

    PublicSub ImproperConditionalCompilation()

    Dim show AsBoolean = True

     

    #If show Then

    MessageBox.Show("This text will not show!", Application.ProductName)

    #Else

    MessageBox.Show("It will show this message!", Application.ProductName)

    #EndIf

    EndSub

    Target C#

    #undef ShowMessage

    staticpublicvoid ConditionalCompilation()

    {

    #if ShowMessage

     

    MessageBox.Show("It will show this message!", Application.ProductName);

    #else

     

    //UPGRADE_TODO: (1035) #If #EndIf block was not upgraded because the expression Else did not evaluate to True or was not evaluated.

    MsgBox "This text will not show!"

    #endif

    }

     

    staticpublicvoid ImproperConditionalCompilation()

    {

    bool show = true;

     

    #if show

     

    //UPGRADE_TODO: (1035) #If #EndIf block was not upgraded because the expression show did not evaluate to True or was not evaluated.

    MsgBox "This text will not show!"

    #else

     

    MessageBox.Show("It will show this message!", Application.ProductName);

    #endif

    }

    Expected C#

    #define ShowMessage

    staticpublicvoid ConditionalCompilation()

    {

    #if ShowMessage

    MessageBox.Show("It will show this message!", Application.ProductName);

    #else

    MessageBox.Show("This text will not show!");

    #endif

    }

     

    staticpublicvoid ImproperConditionalCompilation()

    {

    bool show = true;

    #if show

     

    MessageBox.Show("This text will not show!");

    #else

    MessageBox.Show("It will show this message!", Application.ProductName);

    #endif

    }


    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration