文章詳情頁
asp(vbscript)中自定義函數(shù)的默認參數(shù)實現(xiàn)代碼
瀏覽:133日期:2022-06-04 16:35:47
現(xiàn)代語言的函數(shù)中都可以帶有默認參數(shù),在vbscript系統(tǒng)內建的函數(shù)可以帶有可選值(如常用的 split()等等),然而我們自己定義的函數(shù)中無法具有此功能.
下面提供一個方法實現(xiàn)可選參數(shù)的功能.
functin foo(dtype, dsize, value) dim a, b if TypeName(dtype) <> "Error" Then a = dtype else a = "default value" end if If TypeName(dsize) <> "Error" Then b = dsize else b = -1 end if . end function
如示例代碼所示, foo函數(shù)中dtype, dsize均為可選函數(shù),調用時可以傳參數(shù),也可不傳參數(shù).當不傳參數(shù)的時候,逗號占位符不能丟了,即應該使用 foo(,,"myvalue") 的形式.
標簽:
ASP
相關文章:
排行榜
