Вы можете использовать параметр ByRef
типа Double
для своей функции и установить его значение перед возвратом значения Boolean
:
Function FindLoop(ByVal arr, ByVal val, ByVal bol, ByVal x, ByRef result As Double) As Boolean
Dim r As Double, c As Double
For r = 1 To UBound(arr, 1)
For c = 1 To UBound(arr, 2)
If arr(r, c) = val Then
result = c
FindLoop = ' TODO: return a boolean value
Exit Function
End If
If c = UBound(arr, 2) Then
result = x
FindLoop = False
Exit Function
End If
Next c
Next r
End Function
Использование:
Sub test()
Dim result As Double
Dim found As Boolean
found = FindLoop(arr, val, bol, x, result)
If found Then
' Returned True. Use the result value here.
Else
' Returned False. Use or discard the result value.
End If
End Sub