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

am i overloading this function properly?

private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

======
the above works and i can pass either text box control or combo box
control as the first argument when calling the function. But in code it
looks like two different functions, is there anyway i can write the
above to make it more obvious that it's one function with two
overloaded sets of arguments?

Nov 8 '06 #1
6 1250
Well both TextBox and ComboBox are derived from Control, so you could
have one method that takes a Control and a checkbox. Then you can check
if it's a textbox or checkbox and extract the text into a variable and
then set visible on the Checkbox at the end.

Another alternative is to put the visible setting code into a third
method and call that passing in the Text.
CCLeasing wrote:
private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

======
the above works and i can pass either text box control or combo box
control as the first argument when calling the function. But in code it
looks like two different functions, is there anyway i can write the
above to make it more obvious that it's one function with two
overloaded sets of arguments?
Nov 8 '06 #2
This is how overloading works. You could however use one function like :
private void updateticks(Control control, CheckBox tickbox)
{
if (control.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

as Text is inherited from that. If you want them together than a region
around them can help with organising

HTH

Ciaran O'Donnell

"CCLeasing" wrote:
private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

======
the above works and i can pass either text box control or combo box
control as the first argument when calling the function. But in code it
looks like two different functions, is there anyway i can write the
above to make it more obvious that it's one function with two
overloaded sets of arguments?

Nov 8 '06 #3
Well, to me it already seems obvious enough, but probably I don't
understand well enough what you mean. You said:
control as the first argument when calling the function. But in code it
looks like two different functions
It not only _looks_ like two different functions, they actually _are_
two different functions. They just have the same name and scope. So you
can either (A) change the fact that they are two different functions by
DeveloperX's suggestion or (B) perhaps try to group them just a little
more:
[ A ]
private void updateticks(Control mycontrol, CheckBox tickbox)
{
if (mycontrol is TextBox) ....
else if (mycontrol is ComboBox) ...
}
[ B ]
#region updateticks overloads
private void updateticks(TextBox textbox, CheckBox tickbox) ...
private void updateticks(ComboBox combox, CheckBox tickbox)
#endregion

Hope that helps (a little :)).

-Jeroen

Nov 8 '06 #4

Ciaran O''Donnell wrote:
...
LOL, double post, sorry, was writing my post when you submitted.

Nov 8 '06 #5
Hi CCLeasing,
probably the simplest way to do this if you are always going to make the
CheckBox visible based on the length of a string would be to not pass in
different types of controls, but just a string i.e.:

private void UpdateTicks(string predicate, CheckBox tickBox)
{
tickBox.Visible = (predicate.Length 0);
}

then you are going to call this from other locations by:
UpdateTicks(myTextBox.Text, myCheckBox);
UpdateTicks(myComboBox.Text, myCheckBox);

so you do not have to re-write the logic each time for different types of
controls since all you are using is the length of a string to determine the
visibility of the tickBox.

Mark.
--
http://www.markdawson.org
"CCLeasing" wrote:
private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

======
the above works and i can pass either text box control or combo box
control as the first argument when calling the function. But in code it
looks like two different functions, is there anyway i can write the
above to make it more obvious that it's one function with two
overloaded sets of arguments?

Nov 8 '06 #6
It looks nothing wrong to me. If you can compile and produce the result you
want then just use it.

chanmm

"CCLeasing" <ga**@ccleasing.co.ukwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

======
the above works and i can pass either text box control or combo box
control as the first argument when calling the function. But in code it
looks like two different functions, is there anyway i can write the
above to make it more obvious that it's one function with two
overloaded sets of arguments?

Nov 9 '06 #7

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

Similar topics

17
by: Terje Slettebų | last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been discussed before, I'd appreciate a pointer to it. I again haven't found it in a search of the PHP groups. The PHP...
4
by: Dave Theese | last post by:
Hello all, I'm trying to get a grasp of the difference between specializing a function template and overloading it. The example below has a primary template, a specialization and an overload. ...
5
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that...
39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
45
by: JaSeong Ju | last post by:
I would like to overload a C function. Is there any easy way to do this?
3
by: CCLeasing | last post by:
Here is my code private void updateticks(TextBox textbox, CheckBox tickbox) { if (textbox.Text.Length 0) { tickbox.Visible = true; } else {
15
by: lordkain | last post by:
is it possible to do some kind of function overloading in c? and that the return type is different
10
by: looping | last post by:
Hi, for the fun I try operator overloading experiences and I didn't exactly understand how it works. Here is my try: def __pow__(self, value): return self.__add__(value) 6
2
by: crjjrc | last post by:
Hi. I'm trying to create a template class hierarchy and I'm running into some trouble. I've worked up as small an example as I can that reproduces the problem and placed it here: ...
10
by: Matthew | last post by:
Am I correct in thinking there is no method/function overloading of any kind in any version of PHP? Thanks, Matthew
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...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.