CompatibilityMode() function is controlling runtime mode and affects all code executed after setting or resetting the mode. Use this feature with caution, limit it to document conversion for example.Option Compatible turns on VBA compatibility at module level for the %PRODUCTNAME Basic interpreter.This function may affect or help in the following situations:Creating enumerations with Enum statementRunning RmDir command in VBA mode. In VBA only empty directories are removed by RmDir while %PRODUCTNAME Basic removes a directory recursively.Changing behaviour of Basic Dir command. The directory flag (16) for the Dir command means that only directories are returned in %PRODUCTNAME Basic, while in VBA normal files and directories are returned.CompatibilityMode() function may be necessary when resorting to Option Compatible or Option VBASupport compiler modes.CompatibilityMode(True | False)Given a NOT empty directory at file:///home/me/TestSub RemoveDir CompatibilityMode( true ) RmDir( "file:///home/me/Test" )End SubWith CompatibilityMode( true ) the program results in an error, otherwise the Test directory and all its content is deleted.Modifying Dir behaviorSub VBADirCommand CompatibilityMode( 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$End Sub
Refer to Identifying the Operating System and Getting Session Information for Option Compatible simple examples, or Access2Base shared Basic library for other class examples making use of Option Compatible compiler mode.
Variables scope modification in Using Procedures and Functions with CompatibilityMode() function.