473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Class variables

Can you make the variables passed to a class optional?

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, ByVal
aryPOI() As String, _
ByVal aryDistance() As Integer, ByVal aryDirection() As
Integer)

How do you give the properties of a class default values?

Public ReadOnly Property Acquisitions() As String
Get
Return _TargetsTracked
End Get
End Property

Public ReadOnly Property IDFTimeSpan() As TimeSpan
Get
Return _IDFTimeSpan
End Get
End Property

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
7 1378
In VB you might (not sure). But in either VB or C# you can just have
different versions of the constructor, each with the parameters you want in
there. So one version takes 1 argument, another version takes 2, and a third
version takes 3.

For properties, to give them default values, assign a value to the
underlying variable.

<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .
Can you make the variables passed to a class optional?

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, ByVal
aryPOI() As String, _
ByVal aryDistance() As Integer, ByVal aryDirection() As
Integer)

How do you give the properties of a class default values?

Public ReadOnly Property Acquisitions() As String
Get
Return _TargetsTracked
End Get
End Property

Public ReadOnly Property IDFTimeSpan() As TimeSpan
Get
Return _IDFTimeSpan
End Get
End Property

Thanks,

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #2

If I am following you correctly, you are saying that I would have one sub
like:

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, _
ByVal aryPOI() As String, ByVal aryDistance() As Integer, _
ByVal aryDirection() As Integer)

which requires 5 parameters, but I could also have one like:

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, _
ByVal aryPOI() As String, ByVal aryDistance() As Integer)

which would only requires 4 parameters. Now my next question is what do
I name the subsequent Subs. I would not think that I can name them all
Sub New?

Thanks for the help.

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3
"Marina" <so*****@nospam.com> schrieb:
Can you make the variables passed to a class optional?


In VB you might (not sure).


Yes, you actually can...

\\\
Public Sub New( _
ByVal UserName As String, _
Optional ByVal Password As String = Nothing _
)
...
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4
> Can you make the variables passed to a class optional?

Yes, you can - something like this:

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)
End Sub

With non-array variables, you can assign a default value other than Nothing,
eg
Optional Byval iVariable as Integer = 123
Alas, I don't know how to do this with arrays. With arrays defaulted to
nothing, you can code your New body like this:

if aryDates is nothing then
' put a default for aryDates somewhere
else
' put aryDates somewhere
endif
Nov 21 '05 #5
You can do it the way you have it now. It's called overloading.

As Herfried said, you can also just make them optional.

It sounds like you should probably read up on the VB.NET language.

<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .

If I am following you correctly, you are saying that I would have one sub
like:

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, _
ByVal aryPOI() As String, ByVal aryDistance() As Integer, _
ByVal aryDirection() As Integer)

which requires 5 parameters, but I could also have one like:

Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, _
ByVal aryPOI() As String, ByVal aryDistance() As Integer)

which would only requires 4 parameters. Now my next question is what do
I name the subsequent Subs. I would not think that I can name them all
Sub New?

Thanks for the help.

Thomas

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Nov 21 '05 #6

<th*****@msala.net> wrote in message
news:43**********************@news.newsdemon.com.. .
:
: If I am following you correctly, you are saying that I would have one
: sub like:
:
: Public Sub New(ByVal aryDates() As Date, _
: ByVal aryPOO() As String, _
: ByVal aryPOI() As String, _
: ByVal aryDistance() As Integer, _
: ByVal aryDirection() As Integer)
:
: which requires 5 parameters, but I could also have one like:
:
: Public Sub New(ByVal aryDates() As Date, _
: ByVal aryPOO() As String, _
: ByVal aryPOI() As String, _
: ByVal aryDistance() As Integer)
:
: which would only requires 4 parameters. Now my next question is
: what do I name the subsequent Subs. I would not think that I can name
: them all Sub New?
Actually you can - this is known as overloading a function. You can have
multiple functions with the same name as long as each function has a
unique parameter list. For example:
Public Sub New()
...

Public Sub New(String)
...

Public Sub New(String, Integer)
...

Public Sub New(Integer, Integer)
Note that it is the parameter list that is the determinant. The
following is illegal:
Public Function Foo(String) As Boolean

Public Function Foo(String) As Integer
While they return different types, they have identical signatures and
therefore are illegal.
Ralf
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Nov 21 '05 #7
<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.
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Neil Zanella | last post by:
Hello, It seems to me that using too many variables at class scope in C++ (e.g. private data members) can be just as bad as having a C program with lots of global variables. This is especially...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
8
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that...
4
by: Nick Dreyer | last post by:
Is it possible to see public class variables of a COM addin in Excel 97 VBA? I have successfully created the (Visual Basic 2003 .NET) COM and referenced it in an Excel 97 VBA project. The VBA...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
16
by: digitalorganics | last post by:
What's the difference between initializing class variables within the class definition directly versus initializing them within the class's __init__ method? Is there a reason, perhaps in certain...
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
5
by: tshad | last post by:
In VS 2003, I am setting up an abstract class that is setting up classes for each datatype of VB.Net (as well as C#). I am trying to set it up so that most of the work is done in the Abstract...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
3
by: Immortal Nephi | last post by:
The rule of inheritance states that you define from top to bottom. Sometimes, you want to define base class and set reference from dervied class to base class, but you violate the rule. Here is an...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.