Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Different Approach to the same code
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01514654
Message ID:
01515179
Views:
49
>Hi all:
>
>Im code reviewing a program and in a vb class I see some code that I believe can be enhance. I dont think that VB does not have other option to make the same thing more efficient. Here is the problem
>
>The programmer has to create 366 variables this way
>
>
>
>Private decPeriodDay1 As Decimal = Nothing
>    Private decPeriodDay2 As Decimal = Nothing
>    Private decPeriodDay3 As Decimal = Nothing
>.....
>
> Private decPeriodDay363 As Decimal = Nothing
>    Private decPeriodDay364 As Decimal = Nothing
>    Private decPeriodDay365 As Decimal = Nothing
>    Private decPeriodDay366 As Decimal = Nothing
>
>and then declare a property 366 times.
>
>Public Property PeriodDay1() As Decimal
>        Get
>            Return decPeriodDay1
>        End Get
>        Set(ByVal value As Decimal)
>            decPeriodDay1 = value
>        End Set
>    End Property
>
>.....
>
> Public Property PeriodDay366() As Decimal
>        Get
>            Return decPeriodDay366
>        End Get
>        Set(ByVal value As Decimal)
>            decPeriodDay366 = value
>        End Set
>    End Property
>
>All this information in a class. If somebody know a better approach I will apreaciate.

Maybe just an array in a class with methods rather than properties?:
Class PeriodDays
    Private Days As Decimal() = New Decimal(365) {}

    Public Function GetDay(i As Integer) As Decimal
        Return Days(i - 1)
    End Function

    Public Sub SetDay(i As Integer, d As Decimal)
        Days(i - 1) = d
    End Sub
End Class
Default values would be zero, might need some code to handle out of bounds exceptions as well.....
Previous
Reply
Map
View

Click here to load this message in the networking platform