Istruzione Function
Definisce una subroutine che può essere usata come espressione per determinare il tipo di output restituito.
Sub or Function statements are similar methods, without distinction. They receive parameters by reference allowing them to be modified. LibreOffice Basic compiler accepts their respective syntax to be used interchangeably.
[Private | Public] Function Name[char] (argument1 [As Type][, argument2[char][,...]]) [As typename]
istruzioni
[Exit Function]
istruzioni
End Function
scope: Function default scope is Public. A Private scope denotes a module internal routine, not intended to be used from other modules.
name (nome): nome della subroutine che dovrà contenere il valore restituito dalla funzione.
arguments: parametri da passare alla subroutine.
Esempi:
Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
For siPasso = 0 to 10 ' Popola la matrice con dati di prova
sListArray(siStep) = chr$(siStep + 65)
MsgBox sListArray(siStep)
Next siStep
sReturn = LinSearch(sListArray(), "B")
Print sReturn
End Sub
Function LinSearch( sList(), sItem As String ) As Integer
Dim iCount As Integer
' Linsearch ricerca un TextArray:sList() per una TextEntry:
' Il valore restituito è l'indice della voce o 0 (Null)
For iCount=1 To Ubound( sList() )
If sList( iCount ) = sItem Then
Exit For ' sVoce trovato
End If
Next iCount
If iCount = Ubound( sList() ) Then iCount = 0
LinSearch = iCount
End Function