C
C#2y ago
Drip

Beginner project help

using System.Drawing.Text; using System.Runtime.CompilerServices; namespace KBlair_Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { this.Close(); } private void btnCalc_Click(object sender, EventArgs e) { String txtInput = Console.ReadLine(); } private void txtmAI_TextChanged(object sender, EventArgs e) { } private void txtInputValue_TextChanged(object sender, EventArgs e) {


//txtOutputValue.Text = txtInputValue.Text; //string outputValue = (string)txtInputValue.Text; //Output value of psig = ((mAI(this is the input value) - 4) / 16) * 12 + 3; // mA conversion to psig //outputValue = ((txtInputValue -4 ) / 16 ) * 12 + 3; //txtOutputValue.Text = outputValue; } private void btnClear_Click(object sender, EventArgs e) { txtInputValue.Text = ""; txtOutputValue.Text = ""; txtmAI.Text = ""; MessageBox.Show("All fields have been cleared!"); } private void txtOutputValue_TextChanged(object sender, EventArgs e) { } } }
24 Replies
Drip
DripOP2y ago
maxmahem
maxmahem2y ago
private void btnCalc_Clic(object sender, EventArgs e) {
if (double.TryParse(txtInputValue.Text, out double inputValue) is false) return;
// do calculations and assign result to txtOutputValue
}
private void btnCalc_Clic(object sender, EventArgs e) {
if (double.TryParse(txtInputValue.Text, out double inputValue) is false) return;
// do calculations and assign result to txtOutputValue
}
this should get you going in the right direction.
Drip
DripOP2y ago
okay max, im in VC-0 trying to get help streaming
hoggy077
hoggy0772y ago
Ok, now I'm done with my stuff for now. In the properties window there is a bunch of event options that let you set the method called when something happens, brief look, It looks like you want to look for the TextChanged event
maxmahem
maxmahem2y ago
you could do this on TextChanged but I think starting out I think doing the simpler thing and doing the calculation when the button is clicked is probably better.
hoggy077
hoggy0772y ago
yeh, I glanced over the doc, you have to have a calc button so do like Max said probs should have read through it thoroughly first aye
Drip
DripOP2y ago
Yeah i just dont know hwo to get calc to work
Mango
Mango2y ago
Did the professor explain things like events, event handler functions, functions, binding, variables? If not that’s a major fail on his part And you can’t do this Given that there is a Calculate button I would imagine any processing needs to happen on the click of it That txtOutputValue_TextChanged will likely never get fired as that textbox looks disabled
MODiX
MODiX2y ago
maxmahem
private void btnCalc_Clic(object sender, EventArgs e) {
if (double.TryParse(txtInputValue.Text, out double inputValue) is false) return;
// do calculations and assign result to txtOutputValue
}
private void btnCalc_Clic(object sender, EventArgs e) {
if (double.TryParse(txtInputValue.Text, out double inputValue) is false) return;
// do calculations and assign result to txtOutputValue
}
this should get you going in the right direction.
Quoted by
<@82228151555457024> from #Beginner project help (click here)
React with ❌ to remove this embed.
Mango
Mango2y ago
Was there any requirements for input validation? Some professors take off points for going the extra mile Yes it’s dumb, but I’ve seen it happen I would make as many assumptions as possible with data and let it hard fail
maxmahem
maxmahem2y ago
I can't imagine they would fault you for using TryParse over Parse but whose to say. Little point in learning the wrong way to do it though.
Mango
Mango2y ago
True but your implementation would do nothing if they enter in a non parseable value What if the professor wants it to fail if it can’t parse?
maxmahem
maxmahem2y ago
fail how. Crash? That's stupid behavior.
Mango
Mango2y ago
Yes Crash
maxmahem
maxmahem2y ago
I'd tell the professor that was stupid. I forget if WinForms has some validation routines you can build in here. I think WPF does.
Mango
Mango2y ago
Unlike work assignments, school assignments are usually graded on your ability to follow directions as is It depends on the professor of course But all I’m saying I’ve seen them knock off points for making it do what you made it do Because a crash is a more obvious indicator that it’s failed vs appearing not to do anything and not telling the user why If you’re not going to have it do anything, you better be showing validation messages
maxmahem
maxmahem2y ago
I mean you could throw in a MessageBox.Show on the fail path if you want I guess. It obviously wasn't meant to be a complete sollution, just something to get them started.
Drip
DripOP2y ago
He said it was super easy and we should add flair to it and the progress bar was for a curveball when we dont even know the basics its utter shit No he didnt explain ANY of that
Mango
Mango2y ago
That’s so dumb This is not a judgement on you, but it sounds like you don’t know the fundamentals of programming, let alone WinForms This is a week 2 assignment?
Drip
DripOP2y ago
this is week 2 And i dont know the fundamentals at all we never discussed them he even said to skip the book im not joking when I say we went from, getting the console to ask for a name and say your name is this or a birthday, then going into winforms +formulas and etc.
Mango
Mango2y ago
What’s the class?
Drip
DripOP2y ago
C# like the basic one ITSE1330
Mango
Mango2y ago
I can’t speak for others here, but when I went to school for computer science, we were taught the basics. I can say that you’re getting shafted. As a professional dev who’s trained juniors, your professor’s curriculum is shit. Sorry to hear that, but we aren’t geared towards doing your assignments for you and even just giving you a basic hint isn’t going to work without some significant learning on your part This assignment was doomed to fail But who knows, people can learn under pressure Just my 2c
Drip
DripOP2y ago
Hey I appreciate it man, I felt really discouraged looking at this thinking I wasn't capable of programming, but if its a matter of wrong curriculum that gives me hope and let's me know that I CAN do this if I apply myself elsewhere. I dont want to put this off on anyone as if it's their problen. I was desperate and thought maybe there's someone who really loves teaching who can help someone eager to learn is all. I'm still going to throw everything I can at it, it's the only programming class for my degree but I want to excell and plan on learning more after so IM GONNA DO IT.

Did you find this page helpful?