Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Case Select Statement For Client Side Calculated Field Expression

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Case Select Statement For Client Side Calculated Field Expression

    Is it possible to use Case Select statement in a client side calculated field expression in a UX component?
    Does anyone have an example that they are willing to share?

    I need to do a calculation but conditional on the value of certain controls on the UX.
    For example:

    if Control 1 = 'Value 1' AND Control 2 = 'Value 1' then use calculation x
    if Control 1 = 'Value 1' AND Control 2 = 'Value 2' then use calculation y
    if Control 2 = 'Value 1' AND Control 3 = 'Value 1' then use calculation z
    ... etc

    Is this something that can be done in a custom javascript function or is this strictly an xbasic structure?

    Thanks,
    Stephen
    Last edited by iRadiate; 01-23-2017, 06:18 PM.
    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

    #2
    Re: Case Select Statement For Client Side Calculated Field Expression

    You could do something like this...

    Code:
    var c1 = {dialog.Object}.getValue('control1');
    var c2 = {dialog.Object}.getValue('control2');
    var c3 = {dialog.Object}.getValue('control3');
    
    switch (true) {
        case c1=='Value 1' && c2=='Value 1':
            {dialog.Object}.setValue('control4','calc x');
            break;
        case c1=='Value 1' && c2=='Value 2':
    	{dialog.Object}.setValue('control4','calc y');
            break;
        case c1=='Value 1' && c3=='Value 1':
    	{dialog.Object}.setValue('control4','calc z');
            break;
    }
    But you must be careful of what you want. Once the first case statement is true... ie c1 and c2 are both 'Value 1' then the switch statement exits. The combination of c1 and c3 are not tested.
    Last edited by Davidk; 01-23-2017, 09:02 PM.

    Comment


      #3
      Re: Case Select Statement For Client Side Calculated Field Expression

      i am not sure select ...case ..break.. end case works best here. i think they work well when a single item can have many values.
      i think you can easily use if else if to branch out.
      if you need an example or if you want to post how far along you have come, please post back.
      Code:
      var j1 = {dialog.Object}.getValue('F1');
      var j2 = {dialog.Object}.getValue('F2');
      var j3 = {dialog.Object}.getValue('F3');
      var gg;
      if (j1 == 3 && j2 == 3) {
      gg = 3*9;//use your calculaton
      }
      if (j1 == 3 && j2 == 6) {
      gg = 6*9;//use your calculaton
      }
      if (j2 == 3 && j3 == 3) {
      gg = 9*9;//use your calculaton
      }
      {dialog.Object}.setValue('F4',gg );
      tested with this and seems okay so far.
      Last edited by GGandhi; 01-23-2017, 09:40 PM.
      thanks for reading

      gandhi

      version 11 3381 - 4096
      mysql backend
      http://www.alphawebprogramming.blogspot.com
      [email protected]
      Skype:[email protected]
      1 914 924 5171

      Comment


        #4
        Re: Case Select Statement For Client Side Calculated Field Expression

        Yes. App icon. I had Alpha generate all the icons. All the icons are my logo.

        Comment


          #5
          Re: Case Select Statement For Client Side Calculated Field Expression

          Originally posted by lvasic View Post
          Yes. App icon. I had Alpha generate all the icons. All the icons are my logo.

          ????
          Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

          Comment


            #6
            Re: Case Select Statement For Client Side Calculated Field Expression

            Thanks Ghandi. I've tried using the if statements, both directly in the client-side calculated expression, and as a javascript function call, but it always gives me "cannot parse expression".

            Attached is a simple test component should you have time to take a look? I haven't tried the case statement yet, will try that later on today.
            Attached Files
            Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

            Comment


              #7
              Re: Case Select Statement For Client Side Calculated Field Expression

              sorry, unfortunately i won't be able to open the a5cmp component built with version 12
              if you post your code i can see if there is some tweaking needed.
              thanks for reading

              gandhi

              version 11 3381 - 4096
              mysql backend
              http://www.alphawebprogramming.blogspot.com
              [email protected]
              Skype:[email protected]
              1 914 924 5171

              Comment


                #8
                Re: Case Select Statement For Client Side Calculated Field Expression

                Originally posted by Davidk View Post
                You could do something like this...

                Code:
                var c1 = {dialog.Object}.getValue('control1');
                var c2 = {dialog.Object}.getValue('control2');
                var c3 = {dialog.Object}.getValue('control3');
                
                switch (true) {
                    case c1=='Value 1' && c2=='Value 1':
                        {dialog.Object}.setValue('control4','calc x');
                        break;
                    case c1=='Value 1' && c2=='Value 2':
                	{dialog.Object}.setValue('control4','calc y');
                        break;
                    case c1=='Value 1' && c3=='Value 1':
                	{dialog.Object}.setValue('control4','calc z');
                        break;
                }
                But you must be careful of what you want. Once the first case statement is true... ie c1 and c2 are both 'Value 1' then the switch statement exits. The combination of c1 and c3 are not tested.
                David, when I use the following code I get a circular reference error and cannot parse expression:

                Code:
                var d1 = {dialog.Object}.getValue('Data1');
                var d2 = {dialog.Object}.getValue('Data2');
                var d3 = {dialog.Object}.getValue('Data3');
                
                switch (true) {
                    case d1=='3' && d2=='3':
                        {dialog.Object}.setValue('Output','d1+d2');
                        break;
                    case d1=='1' && d2=='5':
                	{dialog.Object}.setValue('Output','d1*d2');
                        break;
                }
                Circular Ref.jpg Expression Error.jpg

                Thanks,
                Stephen
                Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                Comment


                  #9
                  Re: Case Select Statement For Client Side Calculated Field Expression

                  when you define the calculated expression, you should use your function and declare that function in javascript function as follows:
                  Code:
                  function myFunction (f1, f2, f3) {
                  var j1 = {dialog.Object}.getValue('f1');
                  var j2 = {dialog.Object}.getValue('f2');
                  var j3 = {dialog.Object}.getValue('f3');
                  
                  var gg;
                  if (j1 == "red" && j2 == "red") {
                  gg = 3 * 9;
                  }
                  if (j1 == "red" && j2 == "blue") {
                  gg =  6 * 9;
                  }
                  if (j2 == "red" && j3 == "red") {
                  gg = 9*9;
                  }
                  return gg;
                  }
                  the screencast:
                  https://www.screencast.com/t/QsTMB9HdeP
                  Last edited by GGandhi; 01-24-2017, 11:13 AM.
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                    #10
                    Re: Case Select Statement For Client Side Calculated Field Expression

                    Thanks Ghandi, your video showed me one mistake I made but it still won't work.

                    This is what I get:
                    https://www.screencast.com/t/buBBGtG1o


                    Okay, never mind I've found the syntax problem .. I forgot the single quotes around var d1 = {dialog.Object}.getValue('Data1');

                    Thanks again for your assistance!
                    Last edited by iRadiate; 01-24-2017, 11:50 AM.
                    Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                    Comment


                      #11
                      Re: Case Select Statement For Client Side Calculated Field Expression

                      Code:
                      function myFunction (f1, f2, f3, operation) {
                      var j1 = {dialog.Object}.getValue('f1');
                      var j2 = {dialog.Object}.getValue('f2');
                      var j3 = {dialog.Object}.getValue('f3');
                      var jO = {dialog.Object}.getValue('operation');
                      var gg;
                      if (jO == 'f1PLUSf2') {
                      gg = parseInt(j1) + parseInt(j2);
                      }
                      if (jO == 'f1MINUSf2') {
                      gg = parseInt(f1) -parseInt(f2);
                      }
                      if (jO == 'f1TIMESf3') {
                      gg = parseInt(f2) * parseInt(f3);
                      }
                      if ( jO == 'f2DIVIDEDBYf3') {
                      gg = parseInt(f2) / parseInt(f3);
                      }
                      return gg;
                      }
                      screencast:
                      https://www.screencast.com/t/AVLdqYmiSuXV


                      edit:sorry did not realize you solved it.
                      very good. ( but do not forget parseInt() to get integer addition)
                      Last edited by GGandhi; 01-24-2017, 12:48 PM.
                      thanks for reading

                      gandhi

                      version 11 3381 - 4096
                      mysql backend
                      http://www.alphawebprogramming.blogspot.com
                      [email protected]
                      Skype:[email protected]
                      1 914 924 5171

                      Comment


                        #12
                        Re: Case Select Statement For Client Side Calculated Field Expression

                        Hi Gandhi, yes I had noticed that the '+' operand in javascript was actually concatenating the two numbers rather than adding them.
                        What I actually used was parseFloat() as in reality I will be using decimal values but I wanted to keep things simple so I could get the concept straight and not confuse things too much :)

                        This really was my actual design end goal:

                        UX_Calc.jpg

                        And the javascript function now looks like this:

                        Code:
                        function myCalculation (NCo60Dw, KQ, uenpmw, Ppol, Pion, KR50, Kecal, DDdref, spmw, Kdref_droutine, Kstd_Rout, Machine, Energy) {
                        
                        var d1 = {dialog.Object}.getValue('NCo60Dw');
                        var d2 = {dialog.Object}.getValue('KQ');
                        var d3 = {dialog.Object}.getValue('uenpmw');
                        var d4 = {dialog.Object}.getValue('Ppol');
                        var d5 = {dialog.Object}.getValue('Pion');
                        var d6 = {dialog.Object}.getValue('KR50');
                        var d7 = {dialog.Object}.getValue('Kecal');
                        var d8 = {dialog.Object}.getValue('DDdref');
                        var d9 = {dialog.Object}.getValue('spmw');
                        var d10 = {dialog.Object}.getValue('Kdref_droutine');
                        var d11 = {dialog.Object}.getValue('Kstd_Rout');
                        var c1 = {dialog.Object}.getValue('Machine');
                        var c2 = {dialog.Object}.getValue('Energy');
                        var calc1 = parseFloat(d1)*parseFloat(d2)*parseFloat(d3)*parseFloat(d4)*parseFloat(d5)*parseFloat(d11)/100;
                        var calc2 = parseFloat(d1)*parseFloat(d4)*parseFloat(d5)*parseFloat(d6)*parseFloat(d7)*parseFloat(d9)*parseFloat(d10)*parseFloat(d11)/parseFloat(d8);
                        var result;
                        
                        if (c1 == "21A" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21D" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21F" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21G" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21I" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21A" && c2 == "10X") {
                        	result = calc1;
                        }
                        if (c1 == "21D" && c2 == "10X") {
                        	result = calc1;
                        }
                        if (c1 == "21F" && c2 == "18X") {
                        	result = calc1;
                        }
                        if (c1 == "21G" && c2 == "18X") {
                        	result = calc1;
                        }
                        if (c1 == "21I" && c2 == "18X") {
                        	result = calc1;
                        }
                        if (c1 == "21B" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21C" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21E" && c2 == "6X") {
                        	result = calc1;
                        }
                        if (c1 == "21B" && c2 == "6FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21C" && c2 == "6FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21E" && c2 == "6FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21B" && c2 == "10X") {
                        	result = calc1;
                        }
                        if (c1 == "21C" && c2 == "10X") {
                        	result = calc1;
                        }
                        if (c1 == "21E" && c2 == "10X") {
                        	result = calc1;
                        }
                        if (c1 == "21B" && c2 == "10FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21C" && c2 == "10FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21E" && c2 == "10FFF") {
                        	result = calc1;
                        }
                        if (c1 == "21B" && c2 == "15X") {
                        	result = calc1;
                        }
                        if (c1 == "21E" && c2 == "15X") {
                        	result = calc1;
                        }
                        if (c1 == "21A" && c2 == "6e") {
                        	result = calc2;
                        }
                        if (c1 == "21D" && c2 == "6e") {
                        	result = calc2;
                        }
                        if (c1 == "21I" && c2 == "6e") {
                        	result = calc2;
                        }
                        if (c1 == "21A" && c2 == "9e") {
                        	result = calc2;
                        }
                        if (c1 == "21D" && c2 == "9e") {
                        	result = calc2;
                        }
                        if (c1 == "21I" && c2 == "9e") {
                        	result = calc2;
                        }
                        if (c1 == "21A" && c2 == "12e") {
                        	result = calc2;
                        }
                        if (c1 == "21D" && c2 == "12e") {
                        	result = calc2;
                        }
                        if (c1 == "21I" && c2 == "12e") {
                        	result = calc2;
                        }
                        if (c1 == "21A" && c2 == "16e") {
                        	result = calc2;
                        }
                        if (c1 == "21D" && c2 == "16e") {
                        	result = calc2;
                        }
                        if (c1 == "21I" && c2 == "16e") {
                        	result = calc2;
                        }
                        if (c1 == "21A" && c2 == "20e") {
                        	result = calc2;
                        }
                        if (c1 == "21D" && c2 == "20e") {
                        	result = calc2;
                        }
                        if (c1 == "21I" && c2 == "20e") {
                        	result = calc2;
                        }
                        
                        return result;
                        }
                        So thanks very much, you got me on the right path. Perhaps there is a cleaner way to implement all those if statements but I couldn't work out the javascript or '||' construct. This does work great however!
                        Stephen
                        Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                        Comment


                          #13
                          Re: Case Select Statement For Client Side Calculated Field Expression

                          very good.
                          i am glad you gave a simple example.

                          i think the way you did is probably the correct way to do since you are combining two entities to a single filter. even though the filter is finite when you combine them to a single dropdown to use select..case...break...end case, it will be prone for operator errors. here they cannot make mistake of selecting correct machine and correct energy to get the filter for the result.

                          to be honest whether one uses select case or multiple if statements, the compilers compiles to a if else statement i believe. and keeps it in memory to come to the result.
                          you are eliminating operator error to get the result properly that is important, i think end justifies the means here.

                          very good.
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          [email protected]
                          Skype:[email protected]
                          1 914 924 5171

                          Comment


                            #14
                            Re: Case Select Statement For Client Side Calculated Field Expression

                            additional thought for you:
                            you started off with select case then i moved you to if end if. may be you can do with switch statement you started off with. if you have time and patience you can try
                            Code:
                            switch(true) {
                            case (c1 == "21A" && c2 == "6X"):
                            case (c1 == "21D" && c2 == "6X"):
                            ...
                            ...
                            (list all calc1 cases one per line):
                            result = calc1;
                            break;
                            case (c1 == "21A" && c2 == "6e"):
                            case (c1 == "21D" && c2 == "6e"):
                            ...
                            ...
                            (list all calc2 cases one per line):
                            result = calc2;
                            break;
                            }
                            return result;
                            Last edited by GGandhi; 01-25-2017, 07:19 AM.
                            thanks for reading

                            gandhi

                            version 11 3381 - 4096
                            mysql backend
                            http://www.alphawebprogramming.blogspot.com
                            [email protected]
                            Skype:[email protected]
                            1 914 924 5171

                            Comment


                              #15
                              Re: Case Select Statement For Client Side Calculated Field Expression

                              Hmm, that is interesting, I like that idea as it is visually easier to read (and manage). I'll try to have a look at this approach later today .. time permitting.

                              Thanks for the suggestion.

                              Stephen
                              Alpha Anywhere v12.4.6.5.2 Build 8867-5691 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                              Comment

                              Working...
                              X