3 Replies Latest reply: Aug 17, 2011 11:51 AM by Marc Livingston RSS

    Change buttons color on selection, reset color when fields selected by button are cleared

      First off, I am on personal edition, so I can not open other user's sample qvw docs.


      Second, due to confideniality I am unable to post a sample doc with data.


      Third, I know almost no VB coding, and am very limited with SQL (I know the basic if then else statement)


      I have looked at some examples for macros, but without knowing VB I do not really understand them.


      I created a variable vColor and set it to rgb(0,51,170)  blue.


      The button has 3 actions:

      Select in Field   - Selects customers defined in the search string

      Select Excluded   - Selects everyone else, and unselects previously defined customers.

      Set Variable    - rgb(0,170,9) green.


      I changed the buttons properties for color to equal vColor.


      Once the button is selected, it does what I want, it changes from blue to green to show that it is selected.


      My issue is that I want to change this buttons properties back to blue (reset the variable) when the selection for customer is cleared.

      I was able to get this to work by changing the clear buttons properties to set the variable to rgb(0,51,170), but this only works if the clear button is used. If they use the eraser on the current selection screen, or on the customer list box the button does not change back.


      Is there a way to tell the variable that it needs to equal rgb(0,51,170) if the current customer selection is not matching what I defined with the button?

        • Re: Change buttons color on selection, reset color when fields selected by button are cleared

          I got it to work using this formula on the color base color calculation




          =if(getfieldselections (custid)='NOT General, GeneralMFG, PowerPlant, PPR, PPS',rgb(0,170,9),rgb(0,51,170))





          This is working for the most part.


          We have 4 companies, and all 4 companies do not have the same customers.


          So when I click the button when no company is selected, it works fine. If I change companies selected while the button is active it works fine.


          The issue is when I select one company, then click the button.

          Since this is selecting the above values, then selecting excluded values if a certian company is selected then it changes the string.




          PPS Customers- GeneralMFG, PPR

          PPR Customers- PPS


          Clicking the button when PPS is previously selected displays Not GeneralMFG,PPR

          Clicking the button when PPS and PPR are selected displays Not GeneralMFG,PPR,PPS


          Having 4 companies there are so many different combinations of selections, it will be dificult for me to base it off of this.

            • Re: Change buttons color on selection, reset color when fields selected by button are cleared
              John Witherspoon

              I'm doing similar in an application using macros.  For instance, here's one of the macros associated with one of the buttons:


              sub Set740745orders
                  activedocument.clearall false
                  set field = activedocument.fields("Skip Cancelled Order Items?")
                  field.select "Y"
                  set field = activedocument.fields("Steel Grade")
                  field.select "GR740"
                  field.toggleselect "GR745"
                  set field = activedocument.variables("740745orders")
                  field.setcontent activedocument.evaluate("getcurrentselections()"),false
              end sub


              The part to notice is in red, where I set a variable to getcurrentselections().  Then the button color can then just compare to that variable:




              Now, I do clear all other selections first, so it's not exactly your situation.  But I think it would work for your situation as well.  Regardless of what other selections have been made, when you press the button and make the desired additional selections, the variable will record the resulting selections.  If they subsequently change, it will gray out the button again.


              You might be able to do it with actions as well.  I haven't tried, but selecting some values and setting a variable seem like things easily done with actions.  The only possible problem I see is if QlikView decides to do the actions in parallel, and records the current selections before you've finished selecting.

                • Re: Change buttons color on selection, reset color when fields selected by button are cleared

                  I am trying the part using the action (due to not knowing or really understanding VB)


                  I have the button click action as set variable intercompany to getcurrentselection(custid)


                  When I click the button then check the variable screen, the variable intercompany says:getcurrentselection(custid)


                  How ever when I test this by creating a listbox and setting the expression to =intercompany it gives me an unavailable code on the window.

                  Yet, if I replace the expression to exactly what the variable is set to: Getcurrentselection(custid) it works fine.


                  Is there something I need to do that will record the output of the expression vs the actual expression?




                  I got it to display by using $(intercompany), however since the variable is set to the expression getcurrentselection(custid) and not the value of getcurrentselection(custid) it is changing the variable based on the selection instead of leaving it set to the selection on button click...





                  Ok I am slow and my test listbox that I have displaying the variable was wrong.


                  in the actions setting intercompany=getfieldselections(custid,',',100) works where it is getting the value.


                  Listbox has expression as field set to:



                  However your fear seems to be correct, where it is setting the variable before the selection of fields. So if no selections are made, and the button is clicked, it saves a null value to the variable. If the button is clicked a second time, then it saves the correct values.