Invokes a subroutine by its string name.
CallByName(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.
Value | CallType Description |
---|---|
1 | Method: Calls a procedure as a function or a subroutine. |
2 | Get: Reads a property or variable content. |
4 | Let: Assigns a content to a Property or variable. |
8 | Set: 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
Option Compatible ' Calc.Maths module
Option Explicit
Public 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 If
End Function 'Calc.Maths.Multiply()