VBS中如何获取一个数组中最大值的位置?
以下VBS脚本可以实现这个功能:
Public Function getArrMaxValueIndex(ByVal arr)
Dim ix, ixMax
ixMax = 0
For ix = 1 To UBound(arr)
If ( arr(ixMax) < arr(ix) ) Then
ixMax = ix
End If
Next
getArrMaxValueIndex = ixMax
End Function
'Define array and index for max entry
Dim arr, ixMax
'Initialize the array
arr = Array(4, 1, 8, 6, 3,6)
'Get the index of the max value
ixMax = getArrMaxValueIndex(arr)
'Print result
MsgBox "Max value: " & arr(ixMax) & " was found at " & ixMax & " index."

本文介绍了一种使用VBS脚本确定数组中最大值所在位置的方法,并提供了一个示例脚本来展示如何找到并输出最大值及其索引。
2194

被折叠的 条评论
为什么被折叠?



