Contenido

# Función CompatibilityMode()

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

Utilice esta función con cautela; limítela a la conversión de documentos, por ejemplo.

### Sintaxis:

          CompatibilityMode(Optional Enable As Boolean) As Boolean

### Return type:

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.

### Parámetros:

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

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

Esta función puede coadyuvar o perjudicar las situaciones siguientes:

- Scoping of variables.

- Ejecutar la orden RmDir en modo VBA. En VBA, solo se eliminan los directorios vacíos con RmDir, mientras que LibreOffice BASIC quita un directorio de forma recursiva.

- Changing behavior of Basic Dir command. The directory flag (16) for the Dir command means that only directories are returned in LibreOffice Basic, while in VBA normal files and directories are returned.

- Color components calculation with the Red and Blue functions which are interchanged (The Green function is not affected).

### Ejemplo:

Dado un directorio NO vacío en 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.

### Ejemplo:

Modificar el comportamiento de Dir

        Sub VBADirCommand
            CompatibilityMode( Enable := True )   ' Muestra también los archivos normales
            Entry$ = Dir( "file:///home/me/Tmp/*.*", 16 )
            Total$ = ""
            While Entry$ <> ""
                Total$ = Total$ + Entry$ + Chr$(13)
                Entry$ = Dir
            Wend
            MsgBox Total$
            CompatibilityMode Enable := False ' Muestra directorios solamente
        End Sub

Temas relacionados

Instrucción Option Compatible

Instrucción Rem

Variables scope modification in Using Procedures and Functions with CompatibilityMode() function.

Instrucción Option Base

Instrucción Option Explicit

Instrucción Option VBASupport

Instrucción Option ClassModule

¡Necesitamos su ayuda!