Contents

# CallByName Function

Invokes a subroutine by its string name.

### Syntax:

      CallByName(object As Object, ProcName As String, CallType As Integer [,arg0 [,arg1 …]])

### Return value:

result: An optional variable that contains the result of the called method or property.

### Parameters:

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.

მნიშვნელობა | 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.

### Example:

1. A Calc.Maths module contains a Multiply function expecting a varying list of numbers.

2. ScriptForge.Platform.Architecture information is retrieved.

3. 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 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()

დაკავშირებული თემები

Call Statement

ScriptForge.Platform service

Option Compatible Statement

Option ClassModule Statement