Using Form control inside a class












-4















using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Testapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
EBBill x = new EBBill();
x.Rent = double.Parse(textBox4.Text);
x.calcBill();
}

partial class EBBill:Form1
{
string ownerName;
double unit;

public double Rent
{
get;
set;
}

public void calcBill()
{
double tot;
unit = double.Parse(textBox3.Text);
ownerName = textBox1.Text;
tot = unit * Rent;
label6.Text = Convert.ToString(tot);
label7.Text = ownerName;

}
}
}
}


The following is my code. Can somebody tell me what is wrong with it?



I keep getting this UnhandledException error during runtime, which seems to make no sense to me.



The picture is attached for reference. UnhandledException










share|improve this question


















  • 3





    error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

    – Selvin
    Jan 1 at 17:33








  • 1





    Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

    – None of the Above
    Jan 1 at 17:39






  • 1





    The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

    – Scott Hannen
    Jan 1 at 18:21











  • Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

    – Handbag Crab
    Jan 1 at 21:21
















-4















using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Testapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
EBBill x = new EBBill();
x.Rent = double.Parse(textBox4.Text);
x.calcBill();
}

partial class EBBill:Form1
{
string ownerName;
double unit;

public double Rent
{
get;
set;
}

public void calcBill()
{
double tot;
unit = double.Parse(textBox3.Text);
ownerName = textBox1.Text;
tot = unit * Rent;
label6.Text = Convert.ToString(tot);
label7.Text = ownerName;

}
}
}
}


The following is my code. Can somebody tell me what is wrong with it?



I keep getting this UnhandledException error during runtime, which seems to make no sense to me.



The picture is attached for reference. UnhandledException










share|improve this question


















  • 3





    error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

    – Selvin
    Jan 1 at 17:33








  • 1





    Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

    – None of the Above
    Jan 1 at 17:39






  • 1





    The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

    – Scott Hannen
    Jan 1 at 18:21











  • Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

    – Handbag Crab
    Jan 1 at 21:21














-4












-4








-4








using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Testapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
EBBill x = new EBBill();
x.Rent = double.Parse(textBox4.Text);
x.calcBill();
}

partial class EBBill:Form1
{
string ownerName;
double unit;

public double Rent
{
get;
set;
}

public void calcBill()
{
double tot;
unit = double.Parse(textBox3.Text);
ownerName = textBox1.Text;
tot = unit * Rent;
label6.Text = Convert.ToString(tot);
label7.Text = ownerName;

}
}
}
}


The following is my code. Can somebody tell me what is wrong with it?



I keep getting this UnhandledException error during runtime, which seems to make no sense to me.



The picture is attached for reference. UnhandledException










share|improve this question














using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Testapp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
EBBill x = new EBBill();
x.Rent = double.Parse(textBox4.Text);
x.calcBill();
}

partial class EBBill:Form1
{
string ownerName;
double unit;

public double Rent
{
get;
set;
}

public void calcBill()
{
double tot;
unit = double.Parse(textBox3.Text);
ownerName = textBox1.Text;
tot = unit * Rent;
label6.Text = Convert.ToString(tot);
label7.Text = ownerName;

}
}
}
}


The following is my code. Can somebody tell me what is wrong with it?



I keep getting this UnhandledException error during runtime, which seems to make no sense to me.



The picture is attached for reference. UnhandledException







c# winforms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 17:30









Amit PanditAmit Pandit

1




1








  • 3





    error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

    – Selvin
    Jan 1 at 17:33








  • 1





    Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

    – None of the Above
    Jan 1 at 17:39






  • 1





    The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

    – Scott Hannen
    Jan 1 at 18:21











  • Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

    – Handbag Crab
    Jan 1 at 21:21














  • 3





    error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

    – Selvin
    Jan 1 at 17:33








  • 1





    Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

    – None of the Above
    Jan 1 at 17:39






  • 1





    The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

    – Scott Hannen
    Jan 1 at 18:21











  • Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

    – Handbag Crab
    Jan 1 at 21:21








3




3





error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

– Selvin
Jan 1 at 17:33







error is obvious you cannot parse empty string as double... please learn some basics like what is object instance, what is inheritance ... obviously x.textBox3 is not this.textBox3 inside button1_Click

– Selvin
Jan 1 at 17:33






1




1





Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

– None of the Above
Jan 1 at 17:39





Not everything can be parsed to a double. "Hello, Kitty" for instance. Thats why they also make Double.TryParse()

– None of the Above
Jan 1 at 17:39




1




1





The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

– Scott Hannen
Jan 1 at 18:21





The big reason why the question is downvoted is because it references a picture. It's better to describe in text what the exception is and where it's thrown. It also helps to specify what the exception is. Boiled down, the question is why you're getting a FormatException from double.Parse(textBox3.Text);

– Scott Hannen
Jan 1 at 18:21













Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

– Handbag Crab
Jan 1 at 21:21





Instead of using a TextBox to allow users to set rent values, why not use a NumericUpDown? It's value field is double so no conversion is required.

– Handbag Crab
Jan 1 at 21:21












1 Answer
1






active

oldest

votes


















-1














Any text from the text box cannot be parsed to Double,int etc. You should use TryParse() instead.Also always use try, catch block to avoid unhandled exceptions.






share|improve this answer
























  • Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

    – Ishtiaq
    Jan 1 at 18:18











  • Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

    – Uwe Keim
    Jan 1 at 18:29













  • I am talking about unhandled exceptions @UweKeim

    – Ishtiaq
    Jan 1 at 18:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997506%2fusing-form-control-inside-a-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














Any text from the text box cannot be parsed to Double,int etc. You should use TryParse() instead.Also always use try, catch block to avoid unhandled exceptions.






share|improve this answer
























  • Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

    – Ishtiaq
    Jan 1 at 18:18











  • Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

    – Uwe Keim
    Jan 1 at 18:29













  • I am talking about unhandled exceptions @UweKeim

    – Ishtiaq
    Jan 1 at 18:37
















-1














Any text from the text box cannot be parsed to Double,int etc. You should use TryParse() instead.Also always use try, catch block to avoid unhandled exceptions.






share|improve this answer
























  • Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

    – Ishtiaq
    Jan 1 at 18:18











  • Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

    – Uwe Keim
    Jan 1 at 18:29













  • I am talking about unhandled exceptions @UweKeim

    – Ishtiaq
    Jan 1 at 18:37














-1












-1








-1







Any text from the text box cannot be parsed to Double,int etc. You should use TryParse() instead.Also always use try, catch block to avoid unhandled exceptions.






share|improve this answer













Any text from the text box cannot be parsed to Double,int etc. You should use TryParse() instead.Also always use try, catch block to avoid unhandled exceptions.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 1 at 18:13









IshtiaqIshtiaq

205




205













  • Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

    – Ishtiaq
    Jan 1 at 18:18











  • Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

    – Uwe Keim
    Jan 1 at 18:29













  • I am talking about unhandled exceptions @UweKeim

    – Ishtiaq
    Jan 1 at 18:37



















  • Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

    – Ishtiaq
    Jan 1 at 18:18











  • Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

    – Uwe Keim
    Jan 1 at 18:29













  • I am talking about unhandled exceptions @UweKeim

    – Ishtiaq
    Jan 1 at 18:37

















Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

– Ishtiaq
Jan 1 at 18:18





Text Box may contain any value e.g some string or it can be empty as well. So obviously such values cannot be converted to double.

– Ishtiaq
Jan 1 at 18:18













Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

– Uwe Keim
Jan 1 at 18:29







Actually, never use try, catch blocks. This will filter out errors and makes your application error prone. Use central error handlers and logging instead.

– Uwe Keim
Jan 1 at 18:29















I am talking about unhandled exceptions @UweKeim

– Ishtiaq
Jan 1 at 18:37





I am talking about unhandled exceptions @UweKeim

– Ishtiaq
Jan 1 at 18:37




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997506%2fusing-form-control-inside-a-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas