指定可选参数窗口表单控件vb.net

时间:2014-05-19 11:36:41

标签: vb.net visual-studio-2012

我需要发送一个子程序,一个Windows窗体控件名称作为可选参数

e.g。

Sub putdebug(ByVal str As String, Optional ByVal ctrl As ListBox = lbSystem)

..output to different lisboxes depending on ctrl name, default to lbSystem if not specified.

但是lbSystem正在加下划线并且需要" Constant Expression Required"是错误。

谢谢!

1 个答案:

答案 0 :(得分:1)

请改为尝试:

Sub putdebug(ByVal str As String, Optional ByVal ctrl As ListBox = nothing)
    If IsNothing(ctrl) Then
        ctrl = lbSystem
    End If
End Sub

VB不允许您直接为可选参数赋值。