CompatibilityMode() Function

CompatibilityMode() function controls or queries runtime mode. It affects all code executed after setting or resetting the runtime mode.

warning

Use this feature with caution, limit it to document conversion for example.


Syntax:


      CompatibilityMode(Optional Enable As Boolean) As Boolean
    

Return value:

CompatibilityMode function always returns the mode that is active after its execution. That is, if called with an argument, it returns the new mode; if called without an argument, it returns the active mode without modifying it.

Parameters:

Enable: Sets or unsets new compatibility mode when the argument is present.

note

CompatibilityMode function relates to Option VBASupport 1, in which case it always returns True. It is unrelated to Option Compatible compiler directive.


This function may affect or help in the following situations:

Example:

Given a NOT empty directory at file:///home/me/Test


      Sub RemoveDir
      

MsgBox CompatibilityMode() ' False

CompatibilityMode( True ) RmDir( "file:///home/me/Test" ) CompatibilityMode False

MsgBox CompatibilityMode ' False

End Sub

With CompatibilityMode( True ) the program raises an error, otherwise the Test directory and all its content is deleted.

Example:

Modifying Dir behavior


    Sub VBADirCommand
        CompatibilityMode( Enable := True )   ' Shows also normal files
        Entry$ = Dir( "file:///home/me/Tmp/*.*", 16 )
        Total$ = ""
        While Entry$ <> ""
            Total$ = Total$ + Entry$ + Chr$(13)
            Entry$ = Dir
        Wend
        MsgBox Total$
        CompatibilityMode Enable := False ' Shows only directories
    End Sub
   

Please support us!