<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .
Can you make the variables passed to a class optional?
How do you give the properties of a class default values?
Taking the second question first - you hold each [set of] value[s] in
a class-level variable, so set a default when you declare them, as in
Class X1
' Empty Array of DateTimes
Private _aryDates() as DateTime = New DateTime() {}
End Class
It's /usually/ cleaner to have multiple, overloaded Constructors
that [often] feed into one another, supplying default values for the
arguments not supplied, for example
Class SillyDate
Public Sub New( _
ByVal iaYear as Integer _
, ByVal iaMonth as Integer _
, ByVal iaDay as Integer _
)
End Sub
Public Sub New( _
ByVal iaYear as Integer _
, ByVal iaMonth as Integer _
)
Me.New( iaYear, iaMonth, 1 )
End Sub
Public Sub New( _
ByVal iaYear as Integer _
)
Me.New( iaYear, 1 )
End Sub
However, overloading only works well with either different numbers
of arguments or arguments of different Types (which is how VB tells
one from another). Since you have five arguments of only three different
Types, I think you'd be better off using optional Arguments,
as in
Public Sub New( _
Optional ByVal aryDates() As Date = Nothing _
, Optional ByVal aryPOO() As String = Nothing _
, Optional ByVal aryPOI() As String = Nothing _
, Optional ByVal aryDistance() As Integer = Nothing _
, Optional ByVal aryDirection() As Integer = Nothing _
)
Of course, you'll nbeed to test each argument for being Null-ness
before saving it into its relevant property.
HTH,
Phill W.