gpt4 book ai didi

excel - 我可以使用函数返回两个值吗?

转载 作者:行者123 更新时间:2023-12-04 21:19:25 25 4
gpt4 key购买 nike

我可以使用返回 2 个 Double 类型值的函数吗?和 Boolean ?

Function FindLoop(arr, val, bol, x) As Double
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
FindLoop = c
Exit Function
End If
If c = UBound(arr, 2) Then
FindLoop = False
FindLoop = x
Exit Function
End If
Next c
Next r
End Function

最佳答案

您可以通过 ByRef Double 类型的参数到你的函数并在返回 Boolean 之前设置它的值值(value):

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

关于excel - 我可以使用函数返回两个值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58379339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com