Is there ways to create optional arguments to functions in vbscript?

后端 未结 5 1271
名媛妹妹
名媛妹妹 2020-12-17 08:14

Is there ways to create optional arguments to functions in vb script allowing you to write functions something like...

myFunc(\"happy\")
myFunc(\"happy\", 1,         


        
5条回答
  •  攒了一身酷
    2020-12-17 08:52

    You can always make it a class and use Public Property Let to populate your Sub/Function before calling it:

      Set oSubName = New cSubName
    
        'fill your parameters, you can always add more later
        oClass.OptionalParameter1 = true
        oClass.OptionalParameter2 = false
    
        'execute sub
        oSubName.Execute
    
      Set oSubName = Nothing
    

    This would require some knowledge on how to make classes, but is probably the next best solution to using arrays.

    Good luck.

提交回复
热议问题