Why does a variable name work without being declared?

Hello!
I noticed we never declared oPar, like:

global oPar as string

in the code:

Sub k 
    
    oParEnum = ThisComponent.getText.createEnumeration 
    Do While oParEnum.hasMoreElements() 

        oPar = oParEnum.nextElement()  
        x=x+1
        a(x)=oPar
        print oPar.getString

      Loop 

End Sub

Do we have to declare it at all? (I think in oooB we don’t…)

Many thanks for explanation!

Basic has the very dangerous property to set a default declaration when a new variable is used the first time. As you are novice in programming in Basic, you should always set option explicit to enforce the need of declaration. Otherwise a simple typo will cause a lot of trouble.

I have never used Basic, so where should one set option explicit? At the top of the file?

The application help has the item ‘Command Reference’ in ‘Macros and Programming’ in tab ‘Contents’. From there “This statement must be added before the executable program code in a module.”