When declaring a procedure in VB.Net, where a passed parameter is an object, is it possible to specify several possible object types in an "Or" type of syntax?
For instance, I want to pass one of the "list" controls so the procedure can access the .Items collection. But if I attempt to generalize and specify the parameter as Windows.Forms.Control, an error is generated because .Items is not a member of the .Control object.
I see mention of the "Type List" in the VB language reference, and this seems to almost be what I want, but not quite.
Here are some bits of code to demonstrate the issue...
Friend Sub ListFill( _
ByRef SourceControl As Windows.Forms.WebBrowser, _
ByRef TargetControl As Windows.Forms.Control)
TargetControl.Items.Add(SourceControl.DocumentTitle)
' Error: 'Items' is not a member of 'System.Windows.Forms.Control'.
In a general sense, I need syntax like this...
Friend Sub name ( ByRef varname As { type1 Or type2 Or ... } = defaultvalue )
But in terms of actual working code, this is as far as I got...
Friend Sub ListFill( _
ByRef SourceControl As Windows.Forms.WebBrowser, _
Optional ByRef TargetControl As Windows.Forms.ListBox = Nothing, _
Optional ByRef TargetControl As Windows.Forms.ComboBox = Nothing)
'Error: Parameter already declared with name 'TargetControl'.
Can this be done?