Hello everyone. As the title suggest I have a bit of a problem with a current project which happens to use RadioButtons. Being a bit lost I have come to dream in code for help.
My current issues is writing the project without using (if else) statement. Let me just link this
( http://www.genghiskh...Assign03_.htm). That would be the link to the project I am working on. I made a working version of it using (if else) statements. However the projects specifies that we are not allowed to use (if else) when making the project. This is where I am lost I don't know of any other way to make the project other than using (if else) statement. At the moment I am having a bit of trouble wording my question. So if my question seems vague I do apologize. Any help would be appreciated. Thanks in advance.
-Nogard
9 Replies - 894 Views - Last Post: 06 November 2011 - 12:42 AM
#1
Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 07:06 PM
Replies To: Radiobutton project that doesnt use (if, else if) statement
#2
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 08:31 PM
Your link doesn't work
This post has been edited by tlhIn`toq: 05 November 2011 - 06:33 AM
Reason for edit:: No need to quote the entire immediately preceding post
#3
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 08:48 PM
Sorry about that should have checked. The website for some reason doesn't work if it is through a link. Lets try this
(/http://www.genghiskhent.com/devvie/895/Assignments/895Assign03_.htm\). Only works if the link is copied pasted.
-Nogard
(/http://www.genghiskhent.com/devvie/895/Assignments/895Assign03_.htm\). Only works if the link is copied pasted.
-Nogard
#4
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 09:08 PM
I'm sorry, but we won't do homework assignments for you. We ask that you show YOUR effort. Post what you have tried here. Don't link to another site.
#5
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 10:36 PM
The instructions in part one tell you how you can do this without an if-else statement. You have two options...
"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."
Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"
So you covered a method in class that you use to determine which radio button was selected.
As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.
"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."
Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"
So you covered a method in class that you use to determine which radio button was selected.
As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.
#6
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 10:38 PM
I was not asking for a solution just would like to know a different way of using radio buttons without (if, else if) a simple code snippet would suffice.
A piece of my code that I used. As I stated before I completed the program and it does work as intended. However when programing I did not follow the assignment specifications. I used (if, else if) statements for the radio buttons which I am not allowed to.
if (radJPY.Checked )
{
convertedAmmount = dollars * JPY;
lblConvertedAmount.Text = convertedAmmount.ToString() + "Yen(s)";
}
else if (radEUR.Checked)
{
convertedAmmount = dollars * EUR;
lblConvertedAmount.Text = convertedAmmount.ToString() + "Euro(s)";
}
A piece of my code that I used. As I stated before I completed the program and it does work as intended. However when programing I did not follow the assignment specifications. I used (if, else if) statements for the radio buttons which I am not allowed to.
#7
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 04 November 2011 - 11:07 PM
I guess that class I missed comes back to haunt me
. Though I did read the entire assignment and did try with a foreach loop. However when programing I realized I had no idea how to take the users radio button input without assigning the radio buttons a constant variable. Perhaps I might be over thinking the program and making it unnecessarily difficult. This is as far as I got on the click event handler. Which doesnt work for some reason it says " convertedAmt = dollars * Eur;" that dollars is unassigned local variable.
Thanks for the reply.
-Nogard
private void radEUR_Checked(object sender, EventArgs e)
{
decimal dollars;
const decimal Eur = 0.65m;
decimal convertedAmt;
convertedAmt = dollars * Eur;
lblConvertedAmount.Text = convertedAmt.ToString();
}
Thanks for the reply.
-Nogard
Martyr2, on 04 November 2011 - 10:36 PM, said:
The instructions in part one tell you how you can do this without an if-else statement. You have two options...
"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."
Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"
So you covered a method in class that you use to determine which radio button was selected.
As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.

"use either (1) a foreach loop or (2) a general RadioButton click event handler that is wired to each RadioButton in the group."
Another line to pay attention to is right before this line and reads "See if you can use one of the methods shown in class to determine which RadioButton was selected"
So you covered a method in class that you use to determine which radio button was selected.
As for the wiring approach, think of one function which will take a sender object and an eventargs parameter, then in each click event of the radio buttons it passes the parameters to this function.
#9
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 05 November 2011 - 07:59 PM
Thanks for the help folks. I got it to work ecept one problem when adding the input validation I get "not all code paths return a value" error on my set inputs.
private bool SetInputs(ref String strCurrency, ref Double dollars)
{
bool isValidVal;
isValidVal = Double.TryParse(txtValue.Text, out dollars) && dollars >= 0;
if (!isValidVal)
{
MessageBox.Show("Input must be a nonnegative number",
"Invalid Input", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
txtValue.Focus();
txtValue.SelectAll();
}
else
foreach (RadioButton rdo in grpBtn.Controls)
{
if (rdo.Checked)
{
strCurrency = rdo.Text;
break;
}
}
}
#10
Re: Radiobutton project that doesnt use (if, else if) statement
Posted 06 November 2011 - 12:42 AM
It's because no paths return a value. Your method claims it returns a bool, yet you never return anything at all. If you don't want it to return anything, use void. Otherwise, return a valid value along every possible exit point (or make the method have only one exit point).
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|