7 Replies Latest reply on Jun 10, 2014 10:40 AM by philmodjunk

    Creating a Color-cycling button



      Creating a Color-cycling button


           I apologize if this has been explained in another post. I'm an absolute noob to this program--just started learning it today--and I've got zero programming background. Creating fields is easy enough, but I've got a task for an asset management that needs problem solving.

           For digital asset tracking I'd like to create a button that, when clicked, cycles through 1 of 5 colors.  (Blue, green, red, yellow, and orange.) They represent different stages of approval from our department head and this system is used across multiple documents.  Having a button that just rotates through these colors as the approval status changes would make it very easy.



        • 1. Re: Creating a Color-cycling button

               You'll need a field to store the values 1 through 5. Your button's script will do two things to cycle the colors:

               Increment the value of the field by 5, either stopping at 5 or returning to 1 depending on the results that you want.

               Then it either does a refresh object (FileMaker 13) on the button or Refresh Window (Older versions) to force the button's conditional formatting to update.

               And that's what you can set up to get 5 different fill colors.

               Set up a portal filter expression such as:

               YourTable::Status = 1

               and specify a fill color.

               Then add a second expression:

               YourTable::Status = 2 and choose a different fill color

               Repeat until you have one portal filter expression for each possible value of the status field

          • 2. Re: Creating a Color-cycling button

                 Re: PhilModJunk's response

                 I'm sure you're correct...but I just have no idea what any of what you said means.

                 I've tried creating a portal, but it doesnt let me select a field of any kind...That's aside from the fact that I can't find out how to create a field that simply stores the values 1,2,3,4,5.

                 Also, you say "your button's script" which I assume also means creating a button. How does that button and the field of numbers and the portal all interact with each other?

                 And do you mean "Increment the value of the field by 1" ? Instead of "by 5" ?

            • 3. Re: Creating a Color-cycling button

                   Yes I did mean increment the value by 1.

                   Your layout is based on a table. If you are going to click a button to cycle the color of that button, you need to keep track of which record in your table is which status as that in turn determines what color that button should be.

                   So in the table on which your layout is based, define a field named status. This field need not be visible on your layout, but you'll probably want to add it to your layout next to your color cycling button so that you can see it work, then remove it when you are confident that things are working as you need it to.

                   Use the button tool to add a button to your layout. This will be the button you use that does two things, changes the status of your record and, then shows that status by changing the fill color of the button.

                   The button should be set up to modify the value of your status field by adding 1 to it. What you do when the status value reaches a value of 5 is up to you. You can have it stay on 5 or start over by setting the field back to 1. It's your decision.

                   Your button's script might look like this:

                   Set FIeld [YourTable::Status ; Mod ( YourTable::Status + 1 ; 5 ) + 1 ]
                   Refresh Window[]

                   This will assign a value incremented by 1 until you reach the value 5, then it starts over as 1 again.

                   Then right click your button while in layout mode and select conditional format. Use the info in my previous post to create a series of conditional format expressions. Each expression tests for a different value in the status field and and assigns a different fill color to your field based on what value is in the status field.

                   So cycling the status field through the values of 1 thru 5, also cycles your button's fill color through a series of 5 colors...

              • 4. Re: Creating a Color-cycling button

                     So far so good. Creating the Status field, I can very much change the color of the button by changing the values manually, but the script is a bit wonky. It only currently increases the value by 1 a total of 2 times, then suddenly jumps to increasing it by 5. Also, there is no indication of resetting the value back to 1 once it reaches past 5. It just keeps adding numbers.


                • 5. Re: Creating a Color-cycling button

                       My mistake, Set field expression should be: Mod ( YourTable::Status ; 5 ) + 1

                  • 6. Re: Creating a Color-cycling button

                         Sir you're a scholar and a gentleman. That was the missing piece.

                         For the record here's my image of the script's setup.


                    • 7. Re: Creating a Color-cycling button

                           Note that in FileMaker 13, you have a better option that Refresh Window. Instead of refreshing the entire window, you can use the inspector to give the button an object name and then you can use Refresh Object in place of Refresh Window.