RateOfInterest...
-
Some one wanted to have this: "I have 12 text-boxes for entering Rate-Of-Intrest for different months. If user enters rateOfIntrest for January and August then rateOfInterest for February to July should be same as of January and rest should be as for August. If data for only January is entered then all the months will be same as that of January" Suggestion was: in this case when first text box value can given by the user then bellow method can help u.
TextBox1.Text ="10"; if (TextBox2.Text == "") { TextBox2.Text = TextBox1.Text; } if (TextBox3.Text == "") { TextBox3.Text = TextBox2.Text; } if (TextBox4.Text == "") { TextBox4.Text = TextBox3.Text; } if (TextBox5.Text == "") { TextBox5.Text = TextBox4.Text; } if (TextBox6.Text == "") { TextBox6.Text = TextBox5.Text; } if (TextBox7.Text == "") { TextBox7.Text = TextBox6.Text; } if (TextBox8.Text == "") { TextBox8.Text = TextBox7.Text; } if (TextBox9.Text == "") { TextBox9.Text = TextBox8.Text; } if (TextBox10.Text == "") { TextBox10.Text = TextBox9.Text; } if (TextBox11.Text == "") { TextBox11.Text = TextBox10.Text; } if (TextBox12.Text == "") { TextBox12.Text = TextBox11.Text; }
if TextBox3 text can change then it now consider TextBox3 values.. Oh! Come on... :doh:
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Some one wanted to have this: "I have 12 text-boxes for entering Rate-Of-Intrest for different months. If user enters rateOfIntrest for January and August then rateOfInterest for February to July should be same as of January and rest should be as for August. If data for only January is entered then all the months will be same as that of January" Suggestion was: in this case when first text box value can given by the user then bellow method can help u.
TextBox1.Text ="10"; if (TextBox2.Text == "") { TextBox2.Text = TextBox1.Text; } if (TextBox3.Text == "") { TextBox3.Text = TextBox2.Text; } if (TextBox4.Text == "") { TextBox4.Text = TextBox3.Text; } if (TextBox5.Text == "") { TextBox5.Text = TextBox4.Text; } if (TextBox6.Text == "") { TextBox6.Text = TextBox5.Text; } if (TextBox7.Text == "") { TextBox7.Text = TextBox6.Text; } if (TextBox8.Text == "") { TextBox8.Text = TextBox7.Text; } if (TextBox9.Text == "") { TextBox9.Text = TextBox8.Text; } if (TextBox10.Text == "") { TextBox10.Text = TextBox9.Text; } if (TextBox11.Text == "") { TextBox11.Text = TextBox10.Text; } if (TextBox12.Text == "") { TextBox12.Text = TextBox11.Text; }
if TextBox3 text can change then it now consider TextBox3 values.. Oh! Come on... :doh:
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
Yeah, OK, so what's the problem? How did you fix it?
-
Some one wanted to have this: "I have 12 text-boxes for entering Rate-Of-Intrest for different months. If user enters rateOfIntrest for January and August then rateOfInterest for February to July should be same as of January and rest should be as for August. If data for only January is entered then all the months will be same as that of January" Suggestion was: in this case when first text box value can given by the user then bellow method can help u.
TextBox1.Text ="10"; if (TextBox2.Text == "") { TextBox2.Text = TextBox1.Text; } if (TextBox3.Text == "") { TextBox3.Text = TextBox2.Text; } if (TextBox4.Text == "") { TextBox4.Text = TextBox3.Text; } if (TextBox5.Text == "") { TextBox5.Text = TextBox4.Text; } if (TextBox6.Text == "") { TextBox6.Text = TextBox5.Text; } if (TextBox7.Text == "") { TextBox7.Text = TextBox6.Text; } if (TextBox8.Text == "") { TextBox8.Text = TextBox7.Text; } if (TextBox9.Text == "") { TextBox9.Text = TextBox8.Text; } if (TextBox10.Text == "") { TextBox10.Text = TextBox9.Text; } if (TextBox11.Text == "") { TextBox11.Text = TextBox10.Text; } if (TextBox12.Text == "") { TextBox12.Text = TextBox11.Text; }
if TextBox3 text can change then it now consider TextBox3 values.. Oh! Come on... :doh:
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
Sandeep Mewara wrote:
bellow method can help
It helps me... bel·low/ˈbelō/ Verb: (of a person or animal) Emit a deep loud roar, typically in pain or anger: "he bellowed in agony";
It was broke, so I fixed it.
-
Yeah, OK, so what's the problem? How did you fix it?
Ok, since you asked, there can be ways, to start with, I will have a UI of dropdown and corresponding textbox and a '+' icon (to add another dropdown + textbox) Since user is aware of the fact that month selection will drive rate of interest, all they need to do is select a month(in dropdown) and then set rate of interest from that month(in textbox). If they want to change for any coming month, use the '+' icon to add another dropdown-textbox to add the values. UI is short and clean, so will be the implementation.
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Yeah, OK, so what's the problem? How did you fix it?
Ok, since you asked, there can be ways. To start with, I will have a UI of dropdown and corresponding textbox and a '+' icon (to add another dropdown + textbox) Since user is aware of the fact that month selection will drive rate of interest, all they need to do is select a month(in dropdown) and then set rate of interest from that month(in textbox). If they want to change for any coming month, use the '+' icon to add another dropdown-textbox to add the values. UI is short and clean, so will be the implementation.
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Yeah, OK, so what's the problem? How did you fix it?
BTW, your comment suggests that you think the way suggested was correct. Is so? Having a if for all the 12 textboxes with individual conditions, followed by rest of the textbox after the current one?
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Some one wanted to have this: "I have 12 text-boxes for entering Rate-Of-Intrest for different months. If user enters rateOfIntrest for January and August then rateOfInterest for February to July should be same as of January and rest should be as for August. If data for only January is entered then all the months will be same as that of January" Suggestion was: in this case when first text box value can given by the user then bellow method can help u.
TextBox1.Text ="10"; if (TextBox2.Text == "") { TextBox2.Text = TextBox1.Text; } if (TextBox3.Text == "") { TextBox3.Text = TextBox2.Text; } if (TextBox4.Text == "") { TextBox4.Text = TextBox3.Text; } if (TextBox5.Text == "") { TextBox5.Text = TextBox4.Text; } if (TextBox6.Text == "") { TextBox6.Text = TextBox5.Text; } if (TextBox7.Text == "") { TextBox7.Text = TextBox6.Text; } if (TextBox8.Text == "") { TextBox8.Text = TextBox7.Text; } if (TextBox9.Text == "") { TextBox9.Text = TextBox8.Text; } if (TextBox10.Text == "") { TextBox10.Text = TextBox9.Text; } if (TextBox11.Text == "") { TextBox11.Text = TextBox10.Text; } if (TextBox12.Text == "") { TextBox12.Text = TextBox11.Text; }
if TextBox3 text can change then it now consider TextBox3 values.. Oh! Come on... :doh:
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
Yeah, OK, so what's the problem? How did you fix it?
The problem is the obvious repetition of code, and the answer to fulfil the actual request is as simple as
// this would probably actually be created when the page was built, or be a list
TextBox[] boxes = new TextBox[] { TextBox1, TextBox2, ... };string previousContent = string.Empty;
foreach(TextBox box in boxes) {
if(string.IsNullOrEmpty(box.Text)) box.Text = previousContent;
else previousContent = box.Text;
} -
Ok, since you asked, there can be ways. To start with, I will have a UI of dropdown and corresponding textbox and a '+' icon (to add another dropdown + textbox) Since user is aware of the fact that month selection will drive rate of interest, all they need to do is select a month(in dropdown) and then set rate of interest from that month(in textbox). If they want to change for any coming month, use the '+' icon to add another dropdown-textbox to add the values. UI is short and clean, so will be the implementation.
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
Does the user need to add February in order to add March?
-
BTW, your comment suggests that you think the way suggested was correct. Is so? Having a if for all the 12 textboxes with individual conditions, followed by rest of the textbox after the current one?
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
Sandeep Mewara wrote:
suggests that you think the way suggested was correct
No, but the only issue appears to be a small amount of duplicated code, so I wouldn't bother changing it just for that. Especially if the resulting code is more complex. But the post also doesn't have much context -- if this code is called by the TextChanged events of the TextBoxes I could see performance issues as well.
-
The problem is the obvious repetition of code, and the answer to fulfil the actual request is as simple as
// this would probably actually be created when the page was built, or be a list
TextBox[] boxes = new TextBox[] { TextBox1, TextBox2, ... };string previousContent = string.Empty;
foreach(TextBox box in boxes) {
if(string.IsNullOrEmpty(box.Text)) box.Text = previousContent;
else previousContent = box.Text;
}BobJanova wrote:
obvious repetition of code
Yeah, so what? There's not much of it and it's clear. I totally agree with using an array. But I'd use a
for
loop starting at 1. -
BobJanova wrote:
obvious repetition of code
Yeah, so what? There's not much of it and it's clear. I totally agree with using an array. But I'd use a
for
loop starting at 1. -
If you don't see why 30 lines where 5 would do is a problem then I'm not sure we have the same opinion on code cleanliness ...
I agree with you. Just to add on, it's first 30 lines and not the end of whole code. It was just based on first textbox value, similar if for other following textbox was suggested. Complete answer says: if TextBox3 text can change then it now consider TextBox3 values.. It's too many code lines!
Sandeep Mewara [My last article]: Server side Delimiters in ASP.NET[^]
-
If you don't see why 30 lines where 5 would do is a problem then I'm not sure we have the same opinion on code cleanliness ...
BobJanova wrote:
30 lines where 5 would do is a problem
Well I wouldn't write it that way, but I don't consider it a problem (certainly a smell though) and wouldn't necessarily change it if it works properly -- it ain't broke, there's probably more important things to do than to clean this up. However, the OP says that this is just one small example, so perhaps revisiting all of it is worthwhile in this case.