Smarter way of looping through object property and assign value

Hi ,
   I've got below code written

  Public Function FillZoneDetails() As Zones
                Dim z As New Zones()
                With z
                    With .Zone1
                        .ZoneStartPoint = 0
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone1 / 100) * 1
                    End With
                    With Zone2
                        .ZoneStartPoint = Zone1.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone2 / 100) * 1
                    End With
                    .......   'up until zone5

                End With
                  
     End Function

Open in new window


 basically, I'll have a list of different zones and their details will be calculated based on different factor, but I can tell by the stuff I have this function is going to be massive once all zones are filled.
I'm wondering, is there a smarter way of constructing this object? or shall I change the structure of the zone class somehow?
LVL 2
miketonnyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
If you are just going to have 5 zones like the 2 you show, that's not "massive". What am I missing?
0
miketonnyAuthor Commented:
I will have zones based on (speed,accelaration, decclearation,heartrate, etc)

to instantiate all the zones, i'll need to write this function something like:
   Public Function FillZoneDetails(ByVal zoneDef As ZoneDef) As Zones
        Select Case zoneDef
            Case Zones.ZoneDef.Speed
                Dim z As New Zones(Zones.ZoneDef.Speed)
                With z
                    With .Zone1
                        .ZoneStartPoint = 0
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone1 / 100) * 1
                    End With
                    With Zone2
                        .ZoneStartPoint = Zone1.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone2 / 100) * 1
                    End With
                    With Zone3
                        .ZoneStartPoint = Zone2.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone3 / 100) * 1
                    End With
                    With Zone4
                        .ZoneStartPoint = Zone3.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxVelocity * (_Settings.SpeedZone4 / 100) * 1
                    End With
                    With Zone5
                        .ZoneStartPoint = Zone4.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxVelocity * 1
                    End With
                End With
            Case Zones.ZoneDef.Accelaration
                Dim z As New Zones(Zones.ZoneDef.Accelaration)
                With z
                    With .Zone1
                        .ZoneStartPoint = 0
                        .ZoneEndPoint = _Settings.MaxAccelaration * (_Settings.AccelZone1 / 100) * 1
                    End With
                    With Zone2
                        .ZoneStartPoint = Zone1.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxAccelaration * (_Settings.AccelZone2 / 100) * 1
                    End With
                    With Zone3
                        .ZoneStartPoint = Zone2.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxAccelaration * (_Settings.AccelZone3 / 100) * 1
                    End With
                    With Zone4
                        .ZoneStartPoint = Zone3.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxAccelaration * (_Settings.AccelZone4 / 100) * 1
                    End With
                    With Zone5
                        .ZoneStartPoint = Zone4.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxAccelaration * 1
                    End With
                End With
            Case Zones.ZoneDef.HR
                Dim z As New Zones(Zones.ZoneDef.HR)
                With z
                    With .Zone1
                        .ZoneStartPoint = 0
                        .ZoneEndPoint = _Settings.MaxHR * (_Settings.HRZone1.Y / 100) * 1
                    End With
                    With Zone2
                        .ZoneStartPoint = Zone1.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxHR * (_Settings.HRZone2.Y / 100) * 1
                    End With
                    With Zone3
                        .ZoneStartPoint = Zone2.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxHR * (_Settings.HRZone3.Y / 100) * 1
                    End With
                    With Zone4
                        .ZoneStartPoint = Zone3.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxHR * (_Settings.HRZone4.Y / 100) * 1
                    End With
                    With Zone5
                        .ZoneStartPoint = Zone4.ZoneEndPoint
                        .ZoneEndPoint = _Settings.MaxHR * 1
                    End With
                End With


        End Select




    End Function
	

Open in new window



current  property of zones class

    Public Property Zone1 As ZoneDetail
        Get
            Return _zone1
        End Get
        Set(ByVal value As ZoneDetail)
            _zone1 = value
        End Set
    End Property
    Private _zone1 As ZoneDetail

    Public Property Zone2 As ZoneDetail
        Get
            Return _zone2
        End Get
        Set(ByVal value As ZoneDetail)
            _zone2 = value
        End Set
    End Property
    Private _zone2 As ZoneDetail

    Public Property Zone3 As ZoneDetail
        Get
            Return _zone3
        End Get
        Set(ByVal value As ZoneDetail)
            _zone3 = value
        End Set
    End Property
    Private _zone3 As ZoneDetail

    Public Property Zone4 As ZoneDetail
        Get
            Return _zone4
        End Get
        Set(ByVal value As ZoneDetail)
            _zone4 = value
        End Set
    End Property
    Private _zone4 As ZoneDetail

    Public Property Zone5 As ZoneDetail
        Get
            Return _zone5
        End Get
        Set(ByVal value As ZoneDetail)
            _zone5 = value
        End Set
    End Property
    Private _zone5 As ZoneDetail



    Public Class ZoneDetail
        Public Property ZoneStartPoint As Decimal
            Get
                Return _startPt
            End Get
            Set(ByVal value As Decimal)
                _startPt = value
            End Set
        End Property
        Private _startPt As Decimal
        Public Property ZoneEndPoint As Decimal
            Get
                Return _endPt
            End Get
            Set(ByVal value As Decimal)
                _endPt = value
            End Set
        End Property
        Private _endPt As Decimal

    End Class
	

Open in new window


these just to start with and i can see a lot of repetitive codes already, I'm planning to expand the zones to 10+ later on.

the common thing between zone1-zone5 properties are their 'StartPoint' is always going to be the 'EndPoint'  of previous zone, is there something I could do to improve this part?
0
Martin LissOlder than dirtCommented:
Sorry but I don't think I have anything useful to contribute.
0
ChloesDadCommented:
Why not create a Zones collection in Zone

Private _Zones as New Collection
Public Read Only Property Zones as Collection
  Get
     Return _Zones
  End get
End property

Then add a method in Zones

Public Sub AddZone(index as Integer, StartValue as Decimal, endValue as decimal)
 Zones.Add(index,Newe ZoneDetail(startValue,EndValue)
End Sub

And Create a constructor of ZoneDetail to accept the two parameters and set the zoneDetails properties.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
miketonnyAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.