?
Solved

Overload Question...

Posted on 2011-04-20
8
Medium Priority
?
307 Views
Last Modified: 2012-06-27
I have a question regarding parameters and data type of a sub. I understand that the data type of parameters could be different (of course this is the main reason we overload, or isn’t it?).

Question: Do we have the same number of parameters in overload?

Some explanation with a sample will be appreciated.

Thank you.
0
Comment
Question by:Mike Eghtebas
8 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 400 total points
ID: 35437635
Yes at least one of the datatypes of the parameters have to be different for an overload.
You can have the same number of parameters or a diferent number of parameters for an overload.

http://support.microsoft.com/kb/311330
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 400 total points
ID: 35437904
To overload a method, you only need to use different number of parameters and/or different data type for at least on parameter.

You can have different number of parameters when using overload or same number of parameters as well (different data type for at least on parameter is required in that case).

http://msdn.microsoft.com/en-us/library/ms973896.aspx

Example on overloading:
Function GetWord() As String
Function GetWord(ByVal Position As Integer) As String
Function GetWord(ByVal Search As String) As String

Open in new window

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 35444064
We generally ovrload a routine from a derived class or from client code. We are overloading a routine that we dont't have access to it (in it in base class or DLL).

Question: Based on setup above, if a routine as only two parameters and we are changing the number of overloaded routin in the base class, how that routin will be able to use the new parameter that didn't exist before? Or what if instead of two parameter, the overload supplies only one parameter. How would the original routine function with a missing parameter?

Thanks,

Mike
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 400 total points
ID: 35445011
Overloading is used to REPLACE the functionality of the original function. Are you expecting to execute the overloaded function by using the overloading function?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 35447710
CodeCruiser,

re:> Overloading is used to REPLACE the functionality

If so, then I have no further question on this.

Does Override do the same (replacing the routine in the base class) as well?

Thanks

Mike
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 35448268
Hi Medo3337,

You have three examples of Overload:

Function GetWord() As String
Function GetWord(ByVal Position As Integer) As String
Function GetWord(ByVal Search As String) As String

Q1: Is Overload keyword optional? Are the lines below the same as what you have?

Overload Function GetWord() As String
Overload Function GetWord(ByVal Position As Integer) As String
Overload Function GetWord(ByVal Search As String) As String

Q2: Does overload exists in either in a derived class or client code?

Q3: Where is the code for code for "GetWord" to execute? In the base class or where it is called from?

Thank you.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 400 total points
ID: 35448622
Overloading is done in the same class. Overriding is done in child classes.

Here is a good example

http://www.codeproject.com/KB/vista/Overload_Vs_Overriding.aspx
0
 
LVL 14

Accepted Solution

by:
dejaanbu earned 800 total points
ID: 35453461
Code Cruiser, has provided an good example.. for the sake of answering ur question,

Ans1 : there is no keyword Overload.. but Overloads is the one

and the keyword Overloads is purely optional. you can have functions without them, but if you give Overloads for one function.. then the next overloadable definition of that function should contain the keyword Overloads.

that is

'this is correct
Sub Test(s as String)
Sub Test(i as Integer)

'this is also correct
Overloads Sub Test(s as String)
Overloads Sub Test(i as Integer)

' But this is Error
Overloads Sub Test(s as String)
Sub Test(i as Integer)

Open in new window


Ans2: Overloading is done in the same class as said already. but you can have function as shadows which is virtual implementation... for more info
http://ninopriore.com/the-overloads-overrides-and-shadows-keywords-in-vb-net-part-4/


Ans3: if you have a seperate class with this functions, you can create an object of that class and call the function according to ur need. But if you are going to define these functions in the same page class, you can call it from the base class without creating an object..

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question