Option Base 1
Private Function find(a() As Single, x As Single) As Integer
Dim n%, p%
n = UBound(a) '数组元素个数
For p = 1 To n '循环每个元素
If x = a(p) Then Exit For '如果找到相同 则退出循环 此时的P值既是结果
Next p
'如果没找到 P值将会是 N+1
If p > n Then p = 0
find = p
End Function
Private Sub Form_click()
Dim test(10) As Single
Dim x As Single
Randomize
For i = 1 To 10
test(i) = Int(Rnd * 10 + 1)
Next
x = 2 '
MsgBox find(test, x)
End Sub
直接用这段代码就行了