特殊・他 引数を省略出来るステートメント

※より実装に近く表示させる為、コードの改行を避けています。スマホ等で閲覧される際は向きを変えてご覧ください。

※実装するバージョンによってはバージョンアップの仕様により動作しないコードもあります。実装には動作確認の上ご使用下さい。

Option Explicit


Sub OptionalTest()
'********************************
'引数を省略出来るステートメント
'********************************

MsgBox test1("CCC", "BBB")

MsgBox test2("CCC")

MsgBox test3()

MsgBox test3("BBB")

'Optional str2 As String = "BBB"
'str2が省略された場合はstr2は"BBB"とする

'【使用可能ステートメント】
'Declare ステートメント
'
'Function ステートメント()
'
'Property Get ステートメント()
'
'Property Let ステートメント
'
'Property Set ステートメント
'
'Sub ステートメント()

End Sub


Private Function test1(str1 As String, str2 As StringOptional str3 As String = "AAA") As String
    If str3 = "AAA" Then
        test1 = "YES!"
    Else
        test1 = "NO!"
    End If
End Function


Private Function test2(str1 As StringOptional str2 As String = "BBB", Optional str3 As String = "AAA") As String
    If str2 = "BBB" And str3 = "AAA" Then
        test2 = "YES!"
    Else
        test2 = "NO!"
    End If
End Function


Private Function test3(Optional str3 As String = "CCC") As String
    If str3 = "CCC" Then
        test3 = "YES!"
    Else
        test3 = "NO!"
    End If
End Function

 

 

 

2000年01月01日|[VBサンプルコード]:[特殊・他]