473,805 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can you use an if statement with an overload constructor

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 works fine...
====>>>> Member member = new Member();
=============== =============== =========
public void Button1_Click(o bject sender,System.E ventArgs e)
{
if (ContractNumber .Text =="")
{
Warning.Visible =true;
Warning.Text = "you Must put in a Contract Number to continue";
}
else
{
Warning.Visible =false;
=============== =============== =========
=============== =============== =========
THE PROBLEM COMES HERE...HOW TO USE AN OVERLOAD FUNCTION IN
THIS WAY.
THE RECORD1 GOES OUT OF SCOPE AFTER THE CLOSING }
SO THE CALLS TO THE VARIABLES AFTER THIS STATEMENT WILL NEVER BE
SEEN..

if(fee.Text!="" || memvalidation.T ext!="")
{
====>>>> Member record1 = new Member(fee.Text ,memvalidation. Text,Name.Text, barcode.Text,Ad dress.Text,phon e.Text);
}
=============== =============== =========
=============== =============== =========

Response.Write ("<br>" +record1.getNam e());
Response.Write ("<br>" +record1.getAdd ress());
}
is there any way to do conditional checks with overload constructors?

I can't figure out how to make decisions based on user input so I can populate a class and its parent class
ANY help or pointers or flames are very welcome.
I am stumped

thanks again
sparks

Nov 16 '05 #1
2 3299
You can declare a reference without pointing it at an object.

Member member = null;
if( foo == bar && quux == baz)
{
member = new Member(42);
}
else
{
member = new Member("Hello World");
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<gv************ *************** *****@4ax.com>

I had the bright idea of using if/else to call different constructors based on
a web form and what the user entered.

Nov 16 '05 #2
Worked like a charm thanks big time for the help

Sparks

On Sun, 07 Nov 2004 08:05:56 -0800, "Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote:
You can declare a reference without pointing it at an object.

Member member = null;
if( foo == bar && quux == baz)
{
member = new Member(42);
}
else
{
member = new Member("Hello World");
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<gv************ *************** *****@4ax.com>

I had the bright idea of using if/else to call different constructors based on
a web form and what the user entered.


Nov 16 '05 #3

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

Similar topics

7
4676
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++ copyconstructor1.cpp #copyconstructor1.cpp: In function `int main()': #copyconstructor1.cpp:86: no match for `sample& = sample' operator #copyconstructor1.cpp:53: candidates are: sample sample::operator=(sample&) ...
3
4831
by: Gordon Moore | last post by:
Hi, I'm new to using xml/xslt and although I can create an xml document using the dataset.WriteXml statement, and I have created an xslt to transform the xml into the output I want, I have to manually add the xsl reference statement to the xml file. i.e. <?xml version="1.0" standalone="yes"?> <?xml:stylesheet type="text/xsl" href="Questions.xsl"?> --> I have to
10
2679
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 method takes 0 arguments. #region tViewNodeCollection public class tViewNodeCollection : TreeNodeCollection { private tView _owner; private tViewNode _parent; /// <summary>
6
2384
by: Henry | last post by:
I was trying to derive a class from System.Windows.Forms.ComboBox. My goal was to create a class that loaded its own data. I did not want to create too many objects, so I tried to share a Database object from the calling class, but the compliler doesn't like it when I try to provide and overrided contructor. See the code below: Do I have to stick with the standard ComboBox constructor? If so, how else could I share a common reference to...
2
3466
by: Tom | last post by:
How is the best way to overload the New constructor for a form? For instance, I want to be able to pass things to the constructor, or just default with the plain New. Maybe say something like: Dim x as New MyForm(parm01, parm02) Should I just override new? What is the best way to do this for a form? (The reason I am asking is it appears that the New for a form does a number of things, like initialize controls, etc)
7
1540
by: portroe | last post by:
How do you overload constructors in VB .net? thanks Portroe
35
3631
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is to management theses :-((( I must to declare and use all variable with this scheme :
3
8300
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; }...
1
1756
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 = X(1,2), the elements 1 and 2 of X gets assigned to Y. In this case, the operator () overload should create a copy that is unmodifiable. In the 2nd case, I want do assign values to elements 1 and 2, e.g. X(1,2) = Y. Then in this case, the values...
0
9718
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.