Function 语句

定义可以用作表达式的子例程以确定返回类型。

语法

请参阅「参数」部分

参数:

语法

Function Name[(VarName1 [As Type][, VarName2 [As Type][,...]]]) [As Type]

语句块

[Exit Function]

语句块

End Function

参数

Name」: 含有函数返回值的子例程的名称。

VarName」:要传送到子例程的参数。

Type」: 类型声明关键字。

示例:


Sub ExampleExit
Dim sReturn As String
Dim sListArray(10) As String
Dim siStep As Single
    For siStep = 0 To 10 ' 用测试数据填充数组
        sListArray(siStep) = chr$(siStep + 65)
        MsgBox sListArray(siStep)
    Next siStep
    sReturn = LinSearch(sListArray(), "B")
    Print sReturn
End Sub
 
Function LinSearch( sList(), sItem As String ) As Integer
Dim iCount As Integer
' Linsearch 搜索 TextArray:sList() 中的 TextEntry:
' 返回值为条目的索引或 0 (Null)
    For iCount=1 To Ubound( sList() )
        If sList( iCount ) = sItem Then
            Exit For ' 找到 sItem
        End If
    Next iCount
    If iCount = Ubound( sList() ) Then iCount = 0
    LinSearch = iCount
End Function