473,406 Members | 2,707 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,406 software developers and data experts.

Writing overrides

Hi all,

I am having a few questions today.

Anyway,

I want to create a class file, within the class file, I want to have
functions that can give you optional paramaters...

Such like...

public string AddText(int mynumber)

public string AddText(string MyText)

public string AddText(DataTable MyTableOfText)

public string AddText(StringBuilder MyStringOfText)

How do I really do this?

Probably really simple but an example would go down a treat.

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Nov 19 '05 #1
8 1147

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hi all,

I am having a few questions today.

Anyway,

I want to create a class file, within the class file, I want to have
functions that can give you optional paramaters...

Such like...

public string AddText(int mynumber)

public string AddText(string MyText)

public string AddText(DataTable MyTableOfText)

public string AddText(StringBuilder MyStringOfText)

How do I really do this?

Probably really simple but an example would go down a treat.

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Overloading, not overriding :)

public overloads string AddText(int MyNumber)
{
}

public overloads string AddText(string MyText)
{
}

HTH,
Mythran

Nov 19 '05 #2
>
Overloading, not overriding :)

public overloads string AddText(int MyNumber)
{
}

public overloads string AddText(string MyText)
{
}

HTH,
Mythran


Thank you.

I suppose then that I can easily pass from one to the other, such like...

MyString = AddText(25);

public overloads string AddText(int MyNumber)
{
return AddText(MyNumber.ToString());
}

public overloads string AddText(string MyText)
{
return MyText + " is not a prime";
}

would output "25 is not a prime"

Thanks.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
Nov 19 '05 #3
Hi David,

This is called Overloading, and in VB.Net, you would use the Overloads
keyword in your Function declaration. Example:

Public Overloads String AddText(int mynumber)
....

Public Overloads String AddText(String MyText)
....
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hi all,

I am having a few questions today.

Anyway,

I want to create a class file, within the class file, I want to have
functions that can give you optional paramaters...

Such like...

public string AddText(int mynumber)

public string AddText(string MyText)

public string AddText(DataTable MyTableOfText)

public string AddText(StringBuilder MyStringOfText)

How do I really do this?

Probably really simple but an example would go down a treat.

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

Nov 19 '05 #4
Could you explain when you should use Overloading and when not to?

Shawn
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Ow*************@TK2MSFTNGP09.phx.gbl...
Hi David,

This is called Overloading, and in VB.Net, you would use the Overloads
keyword in your Function declaration. Example:

Public Overloads String AddText(int mynumber)
...

Public Overloads String AddText(String MyText)
...
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
The sun never sets on
the Kingdom of Heaven

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hi all,

I am having a few questions today.

Anyway,

I want to create a class file, within the class file, I want to have
functions that can give you optional paramaters...

Such like...

public string AddText(int mynumber)

public string AddText(string MyText)

public string AddText(DataTable MyTableOfText)

public string AddText(StringBuilder MyStringOfText)

How do I really do this?

Probably really simple but an example would go down a treat.

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Nov 19 '05 #5

"Shawn" <bo********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you explain when you should use Overloading and when not to?

Shawn


Let's say you have a method that requires a single parameter, Text ...

Public Sub WriteLine(ByVal Line As String)
Console.WriteLine(Line)
End Sub

Now you have this line, but lets now say you would like to have a similar
method that writes a line to a file given a format and arguments:

Public Overloads Sub WriteLine(ByVal Line As String)
Console.WriteLine(Line)
End Sub

Public Overloads Sub WriteLine( _
ByVal Format As String, _
ByVal ParamArray Args As String() _
)
Console.WriteLine(Format, Args)
End Sub

And now you have need to write a numeric line:

Public Overloads Sub WriteLine(ByVal Line As String)
Console.WriteLine(Line)
End Sub

Public Overloads Sub WriteLine( _
ByVal Format As String, _
ByVal ParamArray Args As String() _
)
Console.WriteLine(Format, Args)
End Sub

Public Overloads Sub WriteLine(ByVal Number As Integer)
Console.WriteLine(Number.ToString())
End Sub
HTH,
Mythran

Nov 19 '05 #6
The Overloads keyword I mean. Take this example.
Are there any differeces between this way of writing it:
Private Overloads Sub test2(ByVal input As Integer)
...
End Sub

Private Overloads Sub test2(ByVal input As String)
...
End Sub

And this one:
Private Sub test2(ByVal input As Integer)
...
End Sub

Private Sub test2(ByVal input As String)
...
End Sub

Thanks,
Shawn
"Shawn" <bo********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you explain when you should use Overloading and when not to?

Shawn
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Ow*************@TK2MSFTNGP09.phx.gbl...
Hi David,

This is called Overloading, and in VB.Net, you would use the Overloads
keyword in your Function declaration. Example:

Public Overloads String AddText(int mynumber)
...

Public Overloads String AddText(String MyText)
...
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
The sun never sets on
the Kingdom of Heaven

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
Hi all,

I am having a few questions today.

Anyway,

I want to create a class file, within the class file, I want to have
functions that can give you optional paramaters...

Such like...

public string AddText(int mynumber)

public string AddText(string MyText)

public string AddText(DataTable MyTableOfText)

public string AddText(StringBuilder MyStringOfText)

How do I really do this?

Probably really simple but an example would go down a treat.

Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available



Nov 19 '05 #7
When you use Overloads, you can use any of the data types
that you included in the function overload(s).
Public Overloads Function writetext(ByVal h As String)Response.write(h)End FunctionPublic
Overloads Function writetext(ByVal h As Integer)Response.write(h.ToString)End
FunctionPublic Overloads Function writetext(ByVal h As Long)Response.write(h.ToString)End
FunctionBy using the Overloads methods above, your overloaded writetext function
will return the correct output, regardless of whether the returned data
is a string, an integer or a long.

In essence, you overload to allow different outputs for the same function.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Shawn" <bo********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you explain when you should use Overloading and when not to?

Shawn
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Ow*************@TK2MSFTNGP09.phx.gbl...
Hi David,

This is called Overloading, and in VB.Net, you would use the Overloads
keyword in your Function declaration. Example:

Public Overloads String AddText(int mynumber)
...

Public Overloads String AddText(String MyText)
...
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
The sun never sets on
the Kingdom of Heaven

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
> Hi all,
>
> I am having a few questions today.
>
> Anyway,
>
> I want to create a class file, within the class file, I want to have
> functions that can give you optional paramaters...
>
> Such like...
>
> public string AddText(int mynumber)
>
> public string AddText(string MyText)
>
> public string AddText(DataTable MyTableOfText)
>
> public string AddText(StringBuilder MyStringOfText)
>
> How do I really do this?
>
> Probably really simple but an example would go down a treat.
>
> Thanks.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
>



Nov 19 '05 #8
Aargh!

The formatting was messed up.

When you use Overloads, you can use any of the data types
that you included in the function overload(s).

Public Overloads Function writetext(ByVal h As String)
Response.write(h)
End Function

Public Overloads Function writetext(ByVal h As Integer)
Response.write(h.ToString)
End Function

Public Overloads Function writetext(ByVal h As Long)
Response.write(h.ToString)
End Function

By using the Overloads methods above, your overloaded writetext function
will return the correct output, regardless of whether the returned data
is a string, an integer or a long.

In essence, you overload to allow different outputs for the same function.


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
When you use Overloads, you can use any of the data types
that you included in the function overload(s).
Public Overloads Function writetext(ByVal h As String)Response.write(h)End
FunctionPublic Overloads Function writetext(ByVal h As
Integer)Response.write(h.ToString)End FunctionPublic Overloads Function writetext(ByVal
h As Long)Response.write(h.ToString)End FunctionBy using the Overloads methods above,
your overloaded writetext function
will return the correct output, regardless of whether the returned data
is a string, an integer or a long.

In essence, you overload to allow different outputs for the same function.

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"Shawn" <bo********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Could you explain when you should use Overloading and when not to?

Shawn
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Ow*************@TK2MSFTNGP09.phx.gbl...
Hi David,

This is called Overloading, and in VB.Net, you would use the Overloads
keyword in your Function declaration. Example:

Public Overloads String AddText(int mynumber)
...

Public Overloads String AddText(String MyText)
...
--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
The sun never sets on
the Kingdom of Heaven

"David" <da*****************@revilloc.REMOVETHIS.com> wrote in message
news:uI**************@TK2MSFTNGP14.phx.gbl...
> Hi all,
>
> I am having a few questions today.
>
> Anyway,
>
> I want to create a class file, within the class file, I want to have
> functions that can give you optional paramaters...
>
> Such like...
>
> public string AddText(int mynumber)
>
> public string AddText(string MyText)
>
> public string AddText(DataTable MyTableOfText)
>
> public string AddText(StringBuilder MyStringOfText)
>
> How do I really do this?
>
> Probably really simple but an example would go down a treat.
>
> Thanks.
> Best regards,
> Dave Colliver.
> http://www.AshfieldFOCUS.com
> ~~
> http://www.FOCUSPortals.com - Local franchises available
>




Nov 19 '05 #9

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

Similar topics

3
by: ECVerify.com | last post by:
I posted this earlier but never got a response...so I am trying again **************************** Hey everyone, I have a simple (I hope question) To get the events in C# I can go to the...
4
by: Christopher W. Douglas | last post by:
I am developing a VB.NET app using Visual Studio.NET 2003. VB.NET allows me to create a class with two or more methods that have the same name, as long as they have different (non-optional)...
9
by: Surrealist | last post by:
I need something likes as when I create an event procedure. I can use top-left and top-right dropdown list of code editor to select object and its exposed events respectively. Then, the IDE,...
10
by: Atif | last post by:
Hi I am here to solve a small confusion i have in "Overloads Overrides". "Overloading" says that the method's name should be same while no. of parameters and/or their datatypes should be changed...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
2
by: Kalvin | last post by:
I found some code in Google, don't remember where, for an AutoComplete combobox. Everything is great with it except for one thing. If I use the mouse to drop the list down, then start typing to...
10
by: cj | last post by:
I'm having a problem writing an insert command to work with a datatable. I've looked at what the sqldataadapter creates and created my insert command to look the same. I have:...
12
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i...
3
by: maw | last post by:
Hi, could somebody point me in the right direction for adding, removing and modifying nodes in an xml file programatically using vb.net (.net framework 2.0)? I have an xml file in the following...
4
by: Claire | last post by:
Hi, Im new at user control writing in dotnet. I've written a simple gradient painted panel control based on the UserControl class. It works reasonably, but the properties arent being persisted....
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.