選擇性參數

在Visual Basic 宣告函式時,可以載尾端加入選擇性參數,使用前綴Optional,並且必須賦予初始值。

]Function test(ByVal testNormal As String, Optional ByVal testOptional As String = "testD")As String

]Return testNormal & testOptional

]End Function

]

]MsgBox(test("testA", "testB")) //使用者指定參數時,就會像一般函式一樣驅動。MsgBox 裡顯示"testAtestB"。

]MsgBox(test("testC")) //使用者未對選擇性參數指定值時,函式會以預設值代入並驅動。MsgBox 裡顯示"testCtestD"。

文章標籤
全站熱搜
創作者介紹
創作者 GPhettoH 的頭像
GPhettoH

歇息,等待明日的天空

GPhettoH 發表在 痞客邦 留言(0) 人氣(2)