keithstruwig
New member
- Joined
- Oct 31, 2011
- Messages
- 1
- Programming Experience
- 10+
I have a class structure and am attempting to create an array of object instances from the class some instances are parents and some are children
Code snippets,
Parent Class object
Option Strict On
Option Explicit On
Public Class cTransportItem
Friend mName As String
Friend mWeight As Double
Friend mTransportStarDate As Double
....
Sub-class object (one of them)
Option Strict On
Option Explicit On
Public Class cCrew
Inherits cTransportItem
Public mCrewLevel As Integer
Public Sub New()
MyBase.New()
End Sub
....
Option Strict On
Option Explicit On
Public Class semtestb
Private mNoItems As Integer
Private mItemType As Integer
Private TransportArray() As cTransportItem
.
.
.
Private Sub cmdInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInput.Click
For i = 1 To mNoItems
mItemType = CInt(InputBox("Input Item Type : 1 = Crew, 2 = Supply, 3 = Engineer, 4 = Officers"))
Select Case mItemType
Case 1
TransportArray(i) = New cCrew
TransportArray(i).Name = InputBox("Input Name for Item " & CStr(i))
TransportArray(i).Weight = CDbl(InputBox("Input Weight for Item " & CStr(i)))
TransportArray(i).TransportStarDate = CDbl(InputBox("Input Transport Star Date for Item " & CStr(i)))
TransportArray(i).crewlevel = CInt(InputBox("Input Crew level for Item " & CStr(i)))
TransportArray(i) = cCrew.IsHuman
(ishuman is a function method on each class and subclass)
These last two lines give errors respectively
'crewlevel' is not a member of 'WindowsApplication.cTransportItem'
Reference to a non shared member requires an object reference.
Where have I gone wrong
Code snippets,
Parent Class object
Option Strict On
Option Explicit On
Public Class cTransportItem
Friend mName As String
Friend mWeight As Double
Friend mTransportStarDate As Double
....
Sub-class object (one of them)
Option Strict On
Option Explicit On
Public Class cCrew
Inherits cTransportItem
Public mCrewLevel As Integer
Public Sub New()
MyBase.New()
End Sub
....
Option Strict On
Option Explicit On
Public Class semtestb
Private mNoItems As Integer
Private mItemType As Integer
Private TransportArray() As cTransportItem
.
.
.
Private Sub cmdInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInput.Click
For i = 1 To mNoItems
mItemType = CInt(InputBox("Input Item Type : 1 = Crew, 2 = Supply, 3 = Engineer, 4 = Officers"))
Select Case mItemType
Case 1
TransportArray(i) = New cCrew
TransportArray(i).Name = InputBox("Input Name for Item " & CStr(i))
TransportArray(i).Weight = CDbl(InputBox("Input Weight for Item " & CStr(i)))
TransportArray(i).TransportStarDate = CDbl(InputBox("Input Transport Star Date for Item " & CStr(i)))
TransportArray(i).crewlevel = CInt(InputBox("Input Crew level for Item " & CStr(i)))
TransportArray(i) = cCrew.IsHuman
(ishuman is a function method on each class and subclass)
These last two lines give errors respectively
'crewlevel' is not a member of 'WindowsApplication.cTransportItem'
Reference to a non shared member requires an object reference.
Where have I gone wrong
Last edited: