S
samadams_2006
I have what seems to be a very simple straight-forward program (shown
below), but I'm getting an error:
Unable to cast object of type 'TestApp1.ParentTable' to type
'TestApp1.ChildTable'.
on the line: objTable = .SelectedOptions (the fifth line from
the top in the following code).
Why is this? I should be able to go from a parent to the child,
correct? .SelectedOptions is of type ParentTable, and objTable is of
type ChildTable. ChildTable inherits from ParentTable. I've also
tried the commands Ctype and DirectCast, and this does not solve the
problem.
Can anyone tell me how to resolve this?
Thanks
--------------------------------------------------
Module Toolbars
Public Sub Main()
Dim objTable As ChildTable
With frmClass
objTable = .SelectedOptions
End With
End Sub
End Module
--------------------------------------------------
Public Class frmClass
Public ReadOnly Property SelectedOptions() As ParentTable
Get
Dim objTable As New ParentTable
With objTable
.strParent = "SelectedOption"
End With
Return objTable
End Get
End Property
End Class
--------------------------------------------------
Option Explicit On
Public Class ChildTable
Inherits ParentTable
Public ReadOnly Property strChild() As String
Get
Return "strChild"
End Get
End Property
End Class
Public Class ParentTable
Public strParent As String
End Class
--------------------------------------------------
below), but I'm getting an error:
Unable to cast object of type 'TestApp1.ParentTable' to type
'TestApp1.ChildTable'.
on the line: objTable = .SelectedOptions (the fifth line from
the top in the following code).
Why is this? I should be able to go from a parent to the child,
correct? .SelectedOptions is of type ParentTable, and objTable is of
type ChildTable. ChildTable inherits from ParentTable. I've also
tried the commands Ctype and DirectCast, and this does not solve the
problem.
Can anyone tell me how to resolve this?
Thanks
--------------------------------------------------
Module Toolbars
Public Sub Main()
Dim objTable As ChildTable
With frmClass
objTable = .SelectedOptions
End With
End Sub
End Module
--------------------------------------------------
Public Class frmClass
Public ReadOnly Property SelectedOptions() As ParentTable
Get
Dim objTable As New ParentTable
With objTable
.strParent = "SelectedOption"
End With
Return objTable
End Get
End Property
End Class
--------------------------------------------------
Option Explicit On
Public Class ChildTable
Inherits ParentTable
Public ReadOnly Property strChild() As String
Get
Return "strChild"
End Get
End Property
End Class
Public Class ParentTable
Public strParent As String
End Class
--------------------------------------------------