VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
nested Class with Index Posted by nortont on 7 Sept 2009 at 8:13 PM
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.
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    'AlarmID
    '   MonitorID
    '   SalvoID
    '   LoopReplay
    '       Time
    '       Camera
    '       Position
    '   LiveCamera
    '       Add
    '           MatrixID
    '           Position 
    '       Read
    '           MatrixID
    '           Position
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


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


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!

   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


Report
Re: nested Class with Index Posted by seancampbell on 8 Sept 2009 at 5:36 AM
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
Report
Re: nested Class with Index Posted by nortont on 8 Sept 2009 at 6:36 PM
In a similar way that you would add items to a ComboBox.
cboAlarmSource.Items.Add("Alarm1")
        cboAlarmSource.Items(1)

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.

Report
Re: nested Class with Index Posted by seancampbell on 9 Sept 2009 at 5:54 AM
Sounds simple enough, feel free to post when some code stumps you



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.