Page 237 - TP_IT_V1.0_C10_flipbpookl
P. 237

Passing Arguments to Functions created Using Macros
                 The values written within the circular brackets of the function are called arguments. These arguments are created to
                 pass as values to the functions.

                 Let us create a function to add two cells:

                   Function Addcells(a, b)
                   Addcells=a+b

                   End Function
                 In the above code a, b written within Addcells() are two arguments which are passed as values.

                 Now, enter 23 in cell A1 and 32 in cell A2 and then, type =Addcells(A1, A2) in any cell in the sheet.






















                 As soon as you press enter key you will see the total as 55.
















                 Passing the Arguments as Values
                 Values are always supplied as arguments from Calc to a macro. The cells that are used, if any, are unknown. For
                 instance, when =PositiveSum(C7) passes cell C7's value, PositiveSum is unaware that cell C7 was utilised. If you need
                 to know the values in the cells rather than the referenced cells, pass the range as a string, parse the string, and get the
                 values in the cells that are referenced.

                 Macros to Work like Built-in Functions

                 Macros do not actually behave like built-in functions, even if Calc detects and calls them like regular functions. For
                 instance, the function lists do not contain macros. By creating an Add-In, functions may be written that operate similar
                 to built-in functions.

                 Accessing Cells Directly

                 In LibreOffice Calc, you can use macros to directly access and manipulate cells. This means you can write instructions
                 to perform actions like changing the content of a cell, formatting cells, or performing calculations.

                                                                      Electronic Spreadsheet (Advanced) using LibreOffice Calc  235
   232   233   234   235   236   237   238   239   240   241   242