How can I use an optional array argument in a VBA procedure?

前端 未结 4 459
旧巷少年郎
旧巷少年郎 2020-12-18 23:11

I\'ve got a private procedure in a VBA script for MS Access:

Private Sub drawLineDiagram(chartSpace As Variant, title As String, caption As String, x_val() As

4条回答
  •  余生分开走
    2020-12-18 23:17

    If you need an optional array in VBA, declare it as Variant without array specificator, but access it as an array anyway. This way you get a Variant (single variable) that holds an array of Variants, as opposed to just array of Variants. No default value is required:

    Private Sub drawLineDiagram(chartSpace As Variant, title As String, caption As String, x_val As Variant, y_val As Variant, Optional y_val2 As Variant)
    

    For consistency, also declare as plain Variants the other two parameters.

    If you hate the IDE, do not use it. Use notepad. Then paste written code.

提交回复
热议问题