Automatic Conversion Depending on Units in ComboBox












0















I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.



Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.










share|improve this question



























    0















    I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.



    Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.










    share|improve this question

























      0












      0








      0








      I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.



      Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.










      share|improve this question














      I'm creating a time conversion app using python. So what I want to implement in the project is that, when the user change the combobox, the value automatically change/converted depending on the units. For example, I have a base value of 1 second, if I select millisec, the value will be converted. If I select again a unit under combobox, the base number "1" will be converted instead of the value in millisec.



      Is there a good logic about this? been trying things like when the user click the combobox, last value will be stored. But again, I want the base value to be converted.







      python time






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 1:40









      Arci Jeirico MalabananArci Jeirico Malabanan

      275




      275
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).



          If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:




          1. Declare a flag which shall store whether or not the base value has been entered (initially false)

          2. Declare a variable to store the base value

          3. Hook onto when the component is changed.

          4. When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.

          5. Do your calculations, etc and update the component programatically

          6. Once you have updated the component programatically, reset the flag to false.






          share|improve this answer


























          • Thank you for the suggestion. Will implement it asap.

            – Arci Jeirico Malabanan
            Jan 3 at 2:23












          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%2f54015337%2fautomatic-conversion-depending-on-units-in-combobox%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









          0














          I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).



          If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:




          1. Declare a flag which shall store whether or not the base value has been entered (initially false)

          2. Declare a variable to store the base value

          3. Hook onto when the component is changed.

          4. When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.

          5. Do your calculations, etc and update the component programatically

          6. Once you have updated the component programatically, reset the flag to false.






          share|improve this answer


























          • Thank you for the suggestion. Will implement it asap.

            – Arci Jeirico Malabanan
            Jan 3 at 2:23
















          0














          I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).



          If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:




          1. Declare a flag which shall store whether or not the base value has been entered (initially false)

          2. Declare a variable to store the base value

          3. Hook onto when the component is changed.

          4. When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.

          5. Do your calculations, etc and update the component programatically

          6. Once you have updated the component programatically, reset the flag to false.






          share|improve this answer


























          • Thank you for the suggestion. Will implement it asap.

            – Arci Jeirico Malabanan
            Jan 3 at 2:23














          0












          0








          0







          I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).



          If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:




          1. Declare a flag which shall store whether or not the base value has been entered (initially false)

          2. Declare a variable to store the base value

          3. Hook onto when the component is changed.

          4. When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.

          5. Do your calculations, etc and update the component programatically

          6. Once you have updated the component programatically, reset the flag to false.






          share|improve this answer















          I'm assuming the 'value' is inputted by some means such as an input box or etc. I am also assuming that you are trying to display the result in that same input box (or whatever component you are using).



          If this is the case, you could hook onto when the value is changed and store the value it is changed to in some variable - your base value. When you programatically update the input box with the converted value, make sure the component is updated but the hooked function is not called. If this is not supported in whatever UI framework you are using, then you can make use of boolean flags:




          1. Declare a flag which shall store whether or not the base value has been entered (initially false)

          2. Declare a variable to store the base value

          3. Hook onto when the component is changed.

          4. When the component is changed, if the flag is false, store the value of the component in that base value variable you declared and set the flag to true. Otherwise, if the flag is true, don't do anything.

          5. Do your calculations, etc and update the component programatically

          6. Once you have updated the component programatically, reset the flag to false.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 2:11

























          answered Jan 3 at 1:56







          user10859576




















          • Thank you for the suggestion. Will implement it asap.

            – Arci Jeirico Malabanan
            Jan 3 at 2:23



















          • Thank you for the suggestion. Will implement it asap.

            – Arci Jeirico Malabanan
            Jan 3 at 2:23

















          Thank you for the suggestion. Will implement it asap.

          – Arci Jeirico Malabanan
          Jan 3 at 2:23





          Thank you for the suggestion. Will implement it asap.

          – Arci Jeirico Malabanan
          Jan 3 at 2:23




















          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%2f54015337%2fautomatic-conversion-depending-on-units-in-combobox%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith