Function Statement

処理結果を戻り値として返すサブルーチンを定義します。

構文

パラメーターを参照

パラメーター:

構文

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  REM 配列にテスト用データを代入

        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

REM LinSearch はテキスト配列 sList( ) 内に指定文字列を検索

REM 戻り値は、該当するインデックス値ないしゼロ (Null)

    For iCount=1 To Ubound( sList() )

        If sList( iCount ) = sItem Then

            Exit for REM 検索で sItem がヒット

        End If

    Next iCount

    If iCount = Ubound( sList() ) Then iCount = 0

    LinSearch = iCount

End Function