I need to send a subroutine a Windows Form control name as optional parameter
我需要发送一个子例程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.
But the lbSystem is getting underlined and "Constant Expression Required" is error.
但是lbSystem被加下划线并且“需要常量表达式”是错误的。
Thanks!
谢谢!
1 个解决方案
#1
1
Try this instead:
试试这个:
Sub putdebug(ByVal str As String, Optional ByVal ctrl As ListBox = nothing)
If IsNothing(ctrl) Then
ctrl = lbSystem
End If
End Sub
VB wont allow you to assign a value to the optional parameter directly.
VB不允许您直接为可选参数赋值。
#1
1
Try this instead:
试试这个:
Sub putdebug(ByVal str As String, Optional ByVal ctrl As ListBox = nothing)
If IsNothing(ctrl) Then
ctrl = lbSystem
End If
End Sub
VB wont allow you to assign a value to the optional parameter directly.
VB不允许您直接为可选参数赋值。