11 Replies Latest reply on Jun 8, 2015 11:28 AM by Steve Soeder

    Find MAX value from array of variables?

    Steve Soeder

      Is there any way in EPDM to find the max value from an array of variables?

      I want to use a weighted rating system for checkboxes.

      I need to be able to determine the highest point value of the checked boxes, as well as the total of all the checkboxes on the card.

      e.g. say I have 5 checkboxes with the following point values:

      chk1=1 point

      chk2=1 point

      chk3=2 point

      chk4=2 point

      chk5=3 point

      So if the user were to check:

      chk1 and chk5

      Then the max value=3 and total=6

      Or, if the user were to check:

      chk1, chk2, and chk3

      Then the max value =2 and the total = 4

      Hope that makes sense.

       

      My first thought is that I can tie the checkbox to a non-visible editbox and use control logic to set the point values.

      e.g. if chk1 = 0 then edit1=0

             if chk1 = 1 then edit1=1

             if chk2 = 0 then edit2=0

             if chk2 = 1 then edit2=1

             if chk3 = 0 then edit3=0

             if chk3 = 1 then edit3=2

             etc.

       

      I could then get the total using an input formula on another editbox and adding all the variables...but what I can't figure out is how to determine the max value??

      There doesn't seem to be any support for this in the mathematical operators available.

        • Re: Find MAX value from array of variables?
          Charley Saint

          Hey Steve,

           

          This is why I love the forums, always good for a challenge! So the key here is Aliases:

          2015 SOLIDWORKS Enterprise PDM Help - Using Input Formula Aliases

           

          This will allow you to set the weights of each check box. I used variables Check1, Check2, ..., Check5 with the weights 1,2,3,4,5. So for the total box I used the input formula:

          $Add($Add($Add($Add(%Check1(1=1, 0=0)%,%Check2(1=2, 0=0)%),%Check3(1=3, 0=0)%),%Check4(1=4, 0=0)%),%Check5(1=5, 0=0)%)

           

          And for the max formula I had to get a bit tricky. I used the string function $Left to take the first character in a string composed of weights, but instead of 0 for unchecked boxes I used the empty string. This will work as long as weights don't exceed 1 character.

          $Left(%check5(1=5, 0=)%%check4(1=4, 0=)%%check3(1=3, 0=)%%check2(1=2, 0=)%%check1(1=1, 0=)%,1)

           

          If you need 2 characters (we'll say there's a check10 for example) you can add that like so:

          $Left(%check10(1=10, 0=)%$Left(%check5(1=5, 0=)%%check4(1=4, 0=)%%check3(1=3, 0=)%%check2(1=2, 0=)%%check1(1=1, 0=)%,1),2)

           

          I've attached an example card

            • Re: Find MAX value from array of variables?
              Steve Soeder

              Charley you're on fire - that's the second question you helped me solve today!

              Using the left function with aliases is a pretty elegant solution.

              Not bad at all.  I thought for sure I was going to have to turn to VB for this one.

                • Re: Find MAX value from array of variables?
                  Charley Saint

                  Haha thanks, I've been at this for a while so it's nice when I see something I haven't thought of before

                    • Re: Find MAX value from array of variables?
                      Steve Soeder

                      In that case, maybe you can help me out with the next stumbling block I just ran into.
                      The input formula works great when it's used to populate a variable in an edit box on a file card.

                      I'm trying to use this on a template card - the score will be used to populate a different field on the file card for new file created.

                      I don't want the user to see the score, so I was thinking I would just construct the score using an input formula for a template variable, but it seems input formula is not an option for template variables. I think the next best option would be to make the edit box invisible, but I don't see how to do that either.

                      Got any suggestions for that?

                        • Re: Find MAX value from array of variables?
                          Charley Saint

                          Yup, that one's pretty easy. Make a tab control with the first tab blank (can be named anything) and the second tab with the max input box. Name the second tab Admin and make the tab controlled by variable <Name of the User>. Then only the admin can see that input box and everyone sees empty space.

                          2015-06-04_1409.png

                            • Re: Find MAX value from array of variables?
                              Steve Soeder

                              Charley, you've been a ton of help.
                              However, looks like my original idea of using a template at all may be a total bust.

                              There doesn't seem to be any way to copy a variable from the template card to the new file's card.

                               

                              e.g. I have an editbox on the template card tied to variable "ScoreMax" that is populated by your very handy MAX value input formula.

                              In the template editor, I have no way to tell it to copy this value.  I can only copy values to the new file's data card from template variables.

                              However on the template variable there doesn't seem to be any way to set it's value to anything from the card.  Only environmental variables or prompt the user.  I'm going to start a new question on this, as you've already answered my original question here.

                               

                              Thanks.

                              • Re: Find MAX value from array of variables?
                                Steve Soeder

                                I DON'T RECOMMEND DOING THIS.

                                Scroll down through the rest of thread for reasons why.

                                 

                                Just to follow up on this, I found an even better way to completely hide the control without leaving an empty tab on the screen.

                                I just used control logic and set it up to hide the control based on for Text contains <anything> OR Text does not contain <anything>.

                                  • Re: Find MAX value from array of variables?
                                    Charley Saint

                                    Hey Steve,

                                     

                                    Be careful when using this with input formulas, I've seen them not work in the past when the field is hidden using control logic.

                                      • Re: Find MAX value from array of variables?
                                        Steve Soeder

                                        I hate EPDM so much some times.

                                        NOTHING WORKS!

                                        There is always some caveat to every single function in this stupid poorly written software.

                                        Workaround after workaround after workaround - and then your workarounds need workarounds.  And then those workarounds will only work if the stars are aligned just right and you spin around in the mirror 3 times and say the right incantations to the EPDM gods.

                                         

                                        I've said it before and I'll say it again - I've used BETA versions of software that worked more consistently and predictably than this. For the cost of this software, it is infuriating how buggy it is. Totally unacceptable.

                                        I don't mean to ramble and complain, I just hope when people are shopping around for this software they might come across these posts and it might sway them away from it.

                                         

                                        (RANT OVER...)

                                    • Re: Find MAX value from array of variables?
                                      Michael Dekoning

                                      Charley,

                                       

                                      What I've done in the past to hide controls without using control logic is to make their height 0. Of course, you have to remember where it is if you need to edit it.

                                      Also, I've occasionally gotten done editing something else on a card and found that the height had magically increased. Just have to check that when saving the card.