Pagrindiniai objektai
Ši sekcija suteikia pagrindus darbui su LibreOffice Basic.
LibreOffice Basic kodas yra parašytas pagal paprogrames ir funkcijas, kurios yra patikslintos tarp sub... ir pabaigos sub bei funkcijos... ir pabaigos funkcijos seckcijų. Kiekvienas sub arba funkcija gali iškviesti kitus subs arba funkcijas. Jeigu prižiūrite bendrinio kodo rašymą sub arba funkcijai, galite jį panaudoti ir kitose programose. Taip pat žiūrėkite:Procedūros ir funkcijos.
Kai kurie ribojimai yra pritaikyti pavadinimas viešiesiems kintamiesiems, subs bei funkcijoms. Jūs negalite naudoti to paties pavadinimo vienam iš modulių iš tos pačios bibliotekos.
Kas yra Sub?
Sub is the short form of subroutine, that is used to handle a certain task within a program. Subs are used to split a task into individual procedures. Splitting a program into procedures and sub-procedures enhances readability and reduces the error-proneness. A sub possibly takes some arguments as parameters but does not return any values back to the calling sub or function, for example:
DoSomethingWithTheValues(MyFirstValue,MySecondValue)
What is a Function?
A function is essentially a sub, which returns a value. You may use a function at the right side of a variable declaration, or at other places where you normally use values, for example:
MySecondValue = myFunction(MyFirstValue)
Global and local variables
Global variables are valid for all subs and functions inside a module. They are declared at the beginning of a module before the first sub or function starts.
Variables that you declare within a sub or function are valid only inside this sub or function. These variables override global variables with the same name and local variables with the same name coming from superordinate subs or functions.
Structuring
After separating your program into procedures and functions (Subs and Functions), you can save these procedures and functions as files for reuse in other projects. LibreOffice Basic supports Modules and Libraries. Subs and functions are always contained in modules. You can define modules to be global or part of a document. Multiple modules can be combined to a library.
You can copy or move subs, functions, modules and libraries from one file to another by using the Macro dialog.