facebook

Setting Calculation Mode with If, Else Statements

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #332752 Reply

    mreade
    Member

    Support,

    I would like my app to be able to do calculations in either Imperial or Metric.

    I currently have a combolist box called “units” on the main.mobi startup screen. Here, users can select one of the two items:

    * US (Imperial)
    * Metric (SI)

    If the user selects the US mode, then the calculations on form calc.mobi will be in Imperials units. Or, if the Metric mode is selected, the calculations will be in Metric units.

    What would you suggest is the best method to use, where should the code go, and should I use a If, Else type of statement to control the calculations?

    Thanks in advance.

    Mike

    #332803

    mreade
    Member

    Support,

    Can you get me going in the right direction? I am looking to use a Combobox to select calculation mode (Imperial vs. Metric).

    What code would you suggest and where would you suggest placing it?

    Thanks

    Mike

    #332863

    mreade
    Member

    If anyone can assist here, I would appreciate your comments.

    function calcMode()
      {
      var US 
      var SI
      var mode
          
      US = $('select[name="m1-frmMain-units"]:selected').text("imperial");
      SI = $('select[name="m1-frmMain-units"]:selected').text("metric");
      mode = $('select[name="m1-frmMain-units"]:selected').text();
    
      if (mode = US)
        {
          //Place code to perform imperial calculations here
          alert("g = 32.2");
        }
      else
        {
          //Place code to perform metric calculations here
          alert("g = 9.81");
        }
      }

    I have a Combobox called “units” on the main startup form (frmMain.mobi) and just to test this a button to trigger the function calcMode () to show either mode.

    With the combobox (units) showing imperial, it shows imperial mode alert fine. However, with the combobox showing metric, it still shows imperial mode alert, and not the metric alert.

    I am sure there is something simply I am missing. All assistance would be appreciated.

    Thanks in advance

    #332866

    @mreade,

    I’ve modified your function and worked fine :

    function calcMode()
    {
    var mode = $(‘select[name=”units”] :selected‘).text();

    if (mode == “Imperial”)
    {
    //Place code to perform imperial calculations here
    alert(“g = 32.2”);
    }
    else
    {
    //Place code to perform metric calculations here
    alert(“g = 9.81”);
    }
    }

    I highlighted the changes I did to make it work.

    #332868

    mreade
    Member

    Octavia,

    Many thanks!

    I will give this a try and let you know how I make out.

    Mike

    #332869

    mreade
    Member

    Octavio,

    YES!

    This did work after I put a space between the ” ] ” and the ” : ”

    You have saved me a few brain cells trying to figure this out for the first time.

    Cheers!

    Mike

    PS: Is there a way now to save the state “Imperial” or “Metric” and use same the next time the app is run?

    Soooo, much to learn. 🙂

    #332914

    mreade
    Member

    Octavio,

    This is working perfectly now, thanks to your suggestion.

    I have implemented this in two forms, where those forms look to the main form for the combobox units setting. Both the results and the email body message show the proper format, calculation mode and units.

    You may mark this as CLOSED.

    Many thanks!

    Mike

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Setting Calculation Mode with If, Else Statements

You must be logged in to post in the forum log in