தனியார் மாறிகள்

செயல்முறைகளையும் செயலாற்றிகளையும் பயன்படுத்தல்

பின்வருவன LibreOffice அடிப்படையின் செயல்முறைகள் மற்றும் செயலாற்றிகள் ஆகியவற்றின் அடிப்படை பயன்பாட்டை விளக்குகிறது.

Note Icon

நீங்கள் ஒரு புது நிரல்கூற்றை உருவாக்கும்போது, LibreOffice அடிப்படையானது தானாகவே "முதன்மை" என்றழைக்கப்படும் SUB ஐ நுழைக்கிறது. இந்த முன்னிருப்புப் பெயர் LibreOffice அடிப்படைத் திட்டத்தின் ஒழுங்கமைவையோ தொடங்கு புள்ளியையோ தொடர்புடையது அல்ல. நீங்கள் இந்த SUB ஐ பாதுகாப்பாக மறுபயரிடலாம்.


Note Icon

உங்களின் பொது மாறிகள், துணைகள், மற்றும் செயலாற்றிகளில் சில கட்டுபாடுகள் செயற்படுத்தப்படுகின்றன. நூலகத்திந் நிரல்கூறிகளிலுள்ள அதே பெயரை நீங்கள் கண்டிப்பாகப் பயன்படுத்தகூடாது.


Procedures (SUBS) and functions (FUNCTIONS) help you maintaining a structured overview by separating a program into logical pieces.

One benefit of procedures and functions is that, once you have developed a program code containing task components, you can use this code in another project.

Passing Variables to Procedures (SUB) and Functions (FUNCTION)

Variables can be passed to both procedures and functions. The SUB or FUNCTION must be declared to expect parameters:


Sub SubName(Parameter1 As Type, Parameter2 As Type,...)
நிரல் குறியீடு
End Sub

The SUB is called using the following syntax:


SubName(Value1, Value2,...)

The parameters passed to a SUB must fit to those specified in the SUB declaration.

The same process applies to FUNCTIONS. In addition, functions always return a function result. The result of a function is defined by assigning the return value to the function name:


Function FunctionName(Parameter1 As Type, Parameter2 As Type,...) As Type
நிரல் குறியீடு
செயலாற்றி பெயர் = முடிவு
End Function

The FUNCTION is called using the following syntax:


Variable=FunctionName(Parameter1, Parameter2,...)
Tip Icon

You can also use the fully qualified name to call a procedure or function:
Library.Module.Macro()
For example, to call the Autotext macro from the Gimmicks library, use the following command:
Gimmicks.AutoText.Main()


Passing Variables by Value or Reference

Parameters can be passed to a SUB or a FUNCTION either by reference or by value. Unless otherwise specified, a parameter is always passed by reference. That means that a SUB or a FUNCTION gets the parameter and can read and modify its value.

If you want to pass a parameter by value insert the key word "ByVal" in front of the parameter when you call a SUB or FUNCTION, for example:


Result = Function(ByVal Parameter)

In this case, the original content of the parameter will not be modified by the FUNCTION since it only gets the value and not the parameter itself.

மாறிகளின் நோக்கம்

A variable defined within a SUB or FUNCTION, only remains valid until the procedure is exited. This is known as a "local" variable. In many cases, you need a variable to be valid in all procedures, in every module of all libraries, or after a SUB or FUNCTION is exited.

Declaring Variables Outside a SUB or FUNCTION


Global VarName As TYPENAME

The variable is valid as long as the LibreOffice session lasts.


Public VarName As TYPENAME

மாறி அனைத்து நிரல்கூறுகளிலும் செல்லுபடியாகும்.


Private VarName As TYPENAME

மாறி இந்த நிரல்கூற்றில் மட்டுமே செல்லுபடியாகும்


Dim VarName As TYPENAME

மாறி இந்த நிரல்கூற்றில் மட்டுமே செல்லுபடியாகும்.

தனியார் மாறிகளுக்கான எடுத்துக்காட்டு

தனியார் மாறிகள் நிரல்கூறுகளில் தனித்து இருக்க இணக்கமுறையை (உண்மையான) அமைத்தலின் வழி செயலாக்குக.


' ***** Module1 *****
Private myText As String
Sub initMyText
    myText = "வணக்கம்"
    அச்சிடு "நிரல்கூறு1 இல் : ", என்உரை
End Sub
 
' ***** Module2 *****
'Option Explicit
Sub demoBug
    CompatibilityMode( true )
    initMyText
    ' இப்போது, காலிச் சரத்தைத் திரும்பக் கொடுக்கிறது
    ' (or raises error for Option Explicit)
    அச்சிடு "நிரல்கூறு 2இல் : ", என்உரை
End Sub

Saving Variable Content after Exiting a SUB or FUNCTION


Static VarName As TYPENAME

The variable retains its value until the next time the FUNCTION or SUB is entered. The declaration must exist inside a SUB or a FUNCTION.

Specifying the Return Value Type of a FUNCTION

As with variables, include a type-declaration character after the function name, or the type indicated by "As" and the corresponding key word at the end of the parameter list to define the type of the function's return value, for example:


Function WordCount(WordText As String) As Integer

Please support us!