VBS中如何获取一个数组中最大值的位置?

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."

你可能感兴趣的:(function,脚本)