nested Class with Index - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

nested Class with Index

nortontnortont Posts: 2Member
Im not sure is a nested class is the right way to do this.

I am trying to build a class that can store multiple alarm ID's and for each ID have several other settings.
This will then be used to raise an event in another part of the program and pass the other settings with the event.

The structure I am trying to create would be like this.
[code]'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'AlarmID
' MonitorID
' SalvoID
' LoopReplay
' Time
' Camera
' Position
' LiveCamera
' Add
' MatrixID
' Position
' Read
' MatrixID
' Position
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[/code]

To create a new Alarm Source, I want to be able to do the following
[code]AlarmID.Add=20
AlarmID(20).MonitorID=1
AlarmID(20).LiveCamera.Add(Matrix,Monitor)[/code]

Then be able to read each part back based on the AlarmID


I have been experimenting with nested Classes as follows but just cant work it out!

[code] Class AlarmID
Public LiveCameras() As LiveCamera
Private m_Items(0) As Integer

Default Public ReadOnly Property Item(ByVal AlarmID As Integer) As Integer
Get
Item = m_Items(AlarmID)
End Get
End Property
Private m_Count As Integer
Public ReadOnly Property Count() As Integer
Get
Count = m_Count
End Get
End Property
Public Sub Add(ByVal AlarmID As Integer)
ReDim Preserve m_Items(Count)
m_Items(Count) = AlarmID
m_Count += 1

End Sub
Class LiveCamera
Private m_Items(1, 0) As Integer
Default Public ReadOnly Property Item(ByVal MatrixID As Integer, ByVal WindowID As Integer) As Integer
Get ' (1)
Item = m_Items(MatrixID, WindowID)
End Get
End Property
Private m_Count As Integer
Public ReadOnly Property Count() As Integer
Get
Count = m_Count
End Get
End Property
Public Sub Add(ByVal MatrixID As Integer, ByVal WindowID As Integer)
ReDim Preserve m_Items(1, Count)
m_Items(0, Count) = MatrixID
m_Items(1, Count) = WindowID
m_Count += 1
End Sub

End Class
End Class[/code]

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Generally the only time that you would nest a class is when you are only ever going to declare it inside of that class object.

    In other words, if I build a class object that requires some special functionality that I need to use a class object for, but only that one class object will be using it, I would nest it. If I was making something that I might want to declare separately from the class, then I would have to define the class unnested.

    I couldn't figure out what the problem you were having, could you reiterate
  • nortontnortont Posts: 2Member
    In a similar way that you would add items to a ComboBox.
    [code]cboAlarmSource.Items.Add("Alarm1")
    cboAlarmSource.Items(1)[/code]
    I want to be able to add items to my data structure but instead of having 1 index = one item, I need 1 index to give me access to many items.

    EG
    An alarm event will cause the following to occur
    Cameras to display in on of 4 monitors
    A specific layout of cameras on that monitor such as 2X2 or 3x2
    4 cameras to display in that layout
    Looped replay of a specific camera to start

    I need to give the user a method of setting this data via a config.txt file that I then load into the data structure I am trying to create.

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Sounds simple enough, feel free to post when some code stumps you
Sign In or Register to comment.