I want to instance a class depending on a combobox selection. Let say I have the following classes and interface:
Public Interface Sports
Sub description()
End Interface
Public Class Football : Implements Sports
Public Sub description() Implements Sports.description
MsgBox("Football")
End Sub
End Class
Public Class Hockey : Implements Sports
Public Sub description() Implements Sports.description
MsgBox("Hockey")
End Sub
End Class
One solution for my client looks like:
Dim test As Sports
if combobox.selectedtext = "Football" then
test = New Football
else
test = New Hockey
end if
test.description()
With many subclasses this can be quite long, so I was thinking about a way to instance the chosen class depending on the selected text. I know this looks stupid, but something like:
Dim text As String = ComboBox1.SelectedText
test = New "test"
Is it possible to instance a class depending on an assigned string?