Invokes a subroutine by its string name.CallByName functionAPI;OfficeFilePickerCallByName(object As Object, ProcName As String, CallType As Integer [,arg0 [,arg1 …]])result: An optional variable that contains the result of the called method or property.object: A Basic module, ClassModule instance or UNO service holding properties or methods.ProcName: The Function, Sub or Property that is being called.CallType: The type of performed action such as Get, Let, Method and Set.arg0, arg1 …: The Function optional parameters given as positional arguments.Arguments are provided in the exact same order defined in the method signature. Keyword arguments are not possible.
ValueCallType Description1Method: Calls a procedure as a function or a subroutine.2Get: Reads a property or variable content.4Let: Assigns a content to a Property or variable.8Set: Assigns a reference value to an Object or Variant variable.
A Calc.Maths module contains a Multiply function expecting a varying list of numbers.ScriptForge.Platform.Architecture information is retrieved.DisplayDirectory property of com.sun.star.ui.dialogs.FilePicker UNO service is set to the user home folder, its content is read twice.Sub CallByName_example Const _Method = 1, _Get = 2, _Let = 4, _Set = 8 BasicLibraries.loadLibrary("Calc") ' Calc.Maths user library.module Dim cm As Object : cm = Calc.Maths MsgBox CallByName(cm, "Multiply", _Method, 3, 45, 1, 89) ' 12015 MsgBox CallByName(cm, "Multiply", _Method, 1.85e15, 44, 10^8) ' 8.14E+24 GlobalScope.BasicLibraries.loadLibrary("ScriptForge") Dim p As Object : p = CreateScriptService("ScriptForge.Platform") MsgBox CallByName(p, "Architecture", _Get) ' 32bit/64bit Dim uno As Object : uno = CreateUNOService("com.sun.star.ui.dialogs.OfficeFilePicker") Dim fs As Object : fs = CreateScriptService("ScriptForge.FileSystem") CallByName(uno, "DisplayDirectory", _Let, fs.HomeFolder) MsgBox CallByName(uno, "DisplayDirectory", _Get) var = CallByName(uno, "getDisplayDirectory", _Get)End Sub
Calc.Maths module
Option Compatible ' Calc.Maths moduleOption ExplicitPublic Function Multiply(ParamArray args() As Double) As Variant ''' Multiply a variable list of numbers ''' Dim ndx As Integer If UBound(args) >= 0 Then Multiply = 1.0 For ndx = 0 To UBound(args) Multiply = Multiply * args(ndx) Next ndx End IfEnd Function 'Calc.Maths.Multiply()