473,383 Members | 1,716 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,383 software developers and data experts.

overload constructors

How do you overload constructors in VB .net?

thanks

Portroe

Nov 20 '05 #1
7 1504
* portroe <bo*@sleigh.com> scripsit:
How do you overload constructors in VB .net?


\\\
Public Sub New()
...
End Sub

Public Sub New(ByVal Name As String)
...
End Sub
..
..
..
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
do you mean something like this? (or a class that inherits and then
overloads?)

Public Class clsColli
Private colID As Integer
Private colNaam As String
Private colPrijs As Double
Private colOms As String

Public Sub New()
colID = 0
colNaam = ""
colOms = ""
colPrijs = 0
End Sub

Public Sub New(ByVal id As Integer)
Me.New()
colID = id

End Sub

Public Sub New(ByVal naam As String, Optional ByVal oms As String = "",
Optional ByVal prijs As Double = 0)
colID = 0
colNaam = naam
colOms = oms
colPrijs = prijs
End Sub
end class

"portroe" <bo*@sleigh.com> wrote in message
news:O9*************@TK2MSFTNGP09.phx.gbl...
How do you overload constructors in VB .net?

thanks

Portroe

Nov 20 '05 #3
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)

Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

thanks

EricJ wrote:
do you mean something like this? (or a class that inherits and then
overloads?)

Public Class clsColli
Private colID As Integer
Private colNaam As String
Private colPrijs As Double
Private colOms As String

Public Sub New()
colID = 0
colNaam = ""
colOms = ""
colPrijs = 0
End Sub

Public Sub New(ByVal id As Integer)
Me.New()
colID = id

End Sub

Public Sub New(ByVal naam As String, Optional ByVal oms As String = "",
Optional ByVal prijs As Double = 0)
colID = 0
colNaam = naam
colOms = oms
colPrijs = prijs
End Sub
end class

"portroe" <bo*@sleigh.com> wrote in message
news:O9*************@TK2MSFTNGP09.phx.gbl...
How do you overload constructors in VB .net?

thanks

Portroe



Nov 20 '05 #4
then you can do as i said :)
you yust have to keep in mind you can't have 2 constructors w the same type
of parameters

ex.

public sub new(x as integer, y as string)
xke= x
yke= y
end sub
public sub new(x as integer, z as string) ' will give an error, you are
passing an integer and a string 2 times the program won't know w one you
mean
xke= x
zke= y
end sub

'you can do this
public sub new(z as string, x as integer)
xke= x
zke= y
end sub

"portroe" <bo*@sleigh.com> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)

Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

thanks

Nov 20 '05 #5
"portroe" <bo*@sleigh.com> schrieb
How do you overload constructors in VB .net?


Like other methods.

And, no, constructors are not inherited.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
'Overloaded ' ***** Signatures must be different

Public Sub New( ByVal title As String, ByVal qualification As String) '
only two parameters

End Sub

'AND

Public Sub New( ByVal title As String ) ' only one parameters

End Sub

'AND

Public Sub New( ) ' Zero parameters

End Sub
Now your Constructor can be any of the above.

*** Note - here you are overloading constructors. Dont forget, if you
override a constructor, remember to call MyBase.New() from the overridden
constrcutor.

Regards - OHM


portroe wrote:
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)

Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this

thanks

EricJ wrote:
do you mean something like this? (or a class that inherits and then
overloads?)

Public Class clsColli
Private colID As Integer
Private colNaam As String
Private colPrijs As Double
Private colOms As String

Public Sub New()
colID = 0
colNaam = ""
colOms = ""
colPrijs = 0
End Sub

Public Sub New(ByVal id As Integer)
Me.New()
colID = id

End Sub

Public Sub New(ByVal naam As String, Optional ByVal oms As
String = "", Optional ByVal prijs As Double = 0)
colID = 0
colNaam = naam
colOms = oms
colPrijs = prijs
End Sub
end class

"portroe" <bo*@sleigh.com> wrote in message
news:O9*************@TK2MSFTNGP09.phx.gbl...
How do you overload constructors in VB .net?

thanks

Portroe


Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com
Nov 20 '05 #7
* portroe <bo*@sleigh.com> scripsit:
'my constructor looks like this

Public Sub New(ByVal title As String, ByVal qualification As String,
ByVal age As Integer)
Me.iTitle = title
Me.iQualification = qualification
Me.iAge = age

End Sub

' I want to implement multiple constructor overloads under this


What's the problem? Notice that the different overloads must have a
different signature (number of parameters, type of parameters).

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

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

Similar topics

2
by: Wolfgang Jeltsch | last post by:
Hello, consider the following code: #include <iostream.h> template < typename T > int f( T v ) { return 0; }
4
by: Chiller | last post by:
Ok, thanks to some good assistance/advice from people in this group I've been able to further develop my Distance class. Since previous posts I've refined my code to accept the unit measurement...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
10
by: Benny Raymond | last post by:
I'm trying to change the way a treeview works just a bit, i'm pretty new to C# and now i'm running into overloading. I tried the following code and it's yelling at me saying that no overload...
2
by: sparks | last post by:
I had the bright idea of using if/else to call different constructors based on a web form and what the user entered. ======================================= IF I DECLARE this here everything...
7
by: Raghu | last post by:
Hello All, I need some help regarding overloading operation. Is there any way to overload typecasting? I mean if i have a piece of code as below. int a = 2: float b; b = (float)a;
3
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
9
by: Anthony Williams | last post by:
Hi, Should the following compile, and what should it print? #include <memory> #include <iostream> void foo(std::auto_ptr<intx) { std::cout<<"copy"<<std::endl;
1
by: fabian.lim | last post by:
Hi all, Im having a problem with my code. Im programming a vector class, and am trying to overload the () operator in 2 different situations. The first situation is to assign values, e.g. Y =...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.