Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. RateOfInterest...

RateOfInterest...

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpasp-netcomsysadminjson
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PIEBALDconsult

    Yeah, OK, so what's the problem? How did you fix it?

    S Offline
    S Offline
    Sandeep Mewara
    wrote on last edited by
    #5

    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[^]

    P 1 Reply Last reply
    0
    • P PIEBALDconsult

      Yeah, OK, so what's the problem? How did you fix it?

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #6

      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[^]

      P 1 Reply Last reply
      0
      • S Sandeep Mewara

        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[^]

        G Offline
        G Offline
        greldak
        wrote on last edited by
        #7

        Using a control array might be better here - you could then loop through your checks and would also benefit from using the same event handler for all elements of the array rather than 12 seperate ones.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Yeah, OK, so what's the problem? How did you fix it?

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #8

          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;
          }

          P 1 Reply Last reply
          0
          • S Sandeep Mewara

            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[^]

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #9

            Does the user need to add February in order to add March?

            1 Reply Last reply
            0
            • S Sandeep Mewara

              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[^]

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #10

              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.

              1 Reply Last reply
              0
              • B BobJanova

                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;
                }

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #11

                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.

                B 1 Reply Last reply
                0
                • P PIEBALDconsult

                  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.

                  B Offline
                  B Offline
                  BobJanova
                  wrote on last edited by
                  #12

                  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 ...

                  S P 2 Replies Last reply
                  0
                  • B BobJanova

                    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 ...

                    S Offline
                    S Offline
                    Sandeep Mewara
                    wrote on last edited by
                    #13

                    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[^]

                    1 Reply Last reply
                    0
                    • B BobJanova

                      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 ...

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #14

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups