9 Replies Latest reply on Jan 13, 2011 4:36 PM by Jo_2005

    Alert for a Stop Watch

    Jo_2005 Level 1

      Hello,

       

      I have an Acro Agenda form with a stop watch field and an duration/hours field.

       

      When the duration/hours text field is updated by the user eg "00:00:10:00", the stop watch is then started.

       

      I would like an alert to show 2 minutes before the end of the duration time.

       

      In the stop watch field, the following calculation script has been added:

       

      var g = this.getField("StopWatchDisp");

      var t = this.getField("Action Time").value;

      if (g.value == t)  {

      app.alert("Finish Agenda Item in two minutes");

      }

      The script is not working, can any one please provide assistance with an alert for the stop watch?

       

      Many thanks in advance

      Jo

       

        • 1. Re: Alert for a Stop Watch
          gkaiseril MVP & Adobe Community Professional

          What is not working?

           

          Does the stopwatch count down?

           

          Is the comparison not catching?

          1 person found this helpful
          • 2. Re: Alert for a Stop Watch
            Jo_2005 Level 1

            Thank you for your reply.

             

            The stop watch starts at zero and counts up continuously until stopped by a button.

             

            The stop watch works fine and there is no problem with this part of the script.

             

            The problem is getting the alert to show 2 minutes before the duration time is up, at the moment the alert is not showing at all.

             

            A stop watch is used rather than a count down timer as the agenda may go over the duration time allocated.

             

            many thanks

            Jo

            • 3. Re: Alert for a Stop Watch
              gkaiseril MVP & Adobe Community Professional

              I would compare the value of the difference of the event time field value and the stop watch display field value being equal to 2 minutes

               

              Without seeing the entire code, it is difficult to show the necessary code.

              1 person found this helpful
              • 4. Re: Alert for a Stop Watch
                Jo_2005 Level 1

                If the duration time is 00:00:10:00 I would like the alert to show at 00:00:08:00, after the stop watch is started.

                 

                can you please advise how I can revise the calculation script to work which is placed in the stop watch field.

                 

                var g = this.getField("StopWatchDisp");

                var t = this.getField("Action Time").value;

                if (g.value == t)  {

                app.alert("Finish Agenda Item");

                }


                This is the document level stop watch script

                 


                var nStartTime = 0;

                var cSWState = "Stopped"; // Also "Paused" and "Running" states
                var bSWStart = false;
                var bSWStop = false;
                var bSWPause = false;
                var bSWResume = false;
                var bSWClear = false;

                function StopWatchProc(nCurTime)
                {

                   switch(cSWState)
                   {
                     case "Stopped":
                       if(bSWStart)
                       {// Setup for start
                          bSWStart = false; // Turn off State Var
                          nStartTime = nCurTime;
                          cSWState = "Running";
                     SWSetEnables();
                       }
                       else if(bSWClear)
                       {// Setup for start
                          bSWClear = false; // Turn off State Var
                          this.getField("StopWatchDisp").value = "00:00:00:00";
                     SWSetEnables();
                       }
                       break;
                     case "Paused":
                       if(bSWStop)
                       {// Setup for start
                          bSWStop = false; // Turn off State Var
                          cSWState = "Stopped";
                     SWSetEnables();
                       }
                       else if(bSWResume)
                       {// Setup for start
                          bSWResume = false; // Turn off State Var
                          cSWState = "Running";
                     SWSetEnables();
                       }
                       break;
                     case "Running":
                       if(bSWStop)
                       {// Setup for start
                          bSWStop = false; // Turn off State Var
                          cSWState = "Stopped";
                     SWSetEnables();
                       }
                       else if(bSWPause)
                       {// Setup for start
                          bSWPause = false; // Turn off State Var
                          cSWState = "Paused";
                     SWSetEnables();
                       }
                       else
                       { // Update Display
                          var nDiff = nCurTime - nStartTime;
                          var hours = Math.floor(nDiff/oneHour);
                          nDiff -= hours * oneHour;
                          var mins = Math.floor(nDiff/oneMin);
                          nDiff -= mins * oneMin;
                          var secs = Math.floor(nDiff/oneSec);
                          var millis = (nDiff - secs * oneSec)/10;  // Get it down to 100ths of a sec
                          var strTime = util.printf("%02d:%02d:%02d:%02d",hours,mins,secs,millis);
                          this.getField("StopWatchDisp").value =strTime;
                       }
                       break;
                   }
                   this.getField("SWStatus").value = cSWState;
                }

                function SWSetEnables()
                {
                   switch(cSWState)
                   {
                     case "Stopped":
                       SetFldEnable(this.getField("SWStart"),true);
                       SetFldEnable(this.getField("SWStop"),false);
                       SetFldEnable(this.getField("SWPause"),false);
                       SetFldEnable(this.getField("SWClear"),true);
                       this.getField("SWPause").buttonSetCaption("Pause");
                       break;
                     case "Paused":
                       SetFldEnable(this.getField("SWStart"),false);
                       SetFldEnable(this.getField("SWStop"),true);
                       SetFldEnable(this.getField("SWPause"),true);
                       SetFldEnable(this.getField("SWClear"),false);
                       this.getField("SWPause").buttonSetCaption("Resume");
                       break;
                     case "Running":
                       SetFldEnable(this.getField("SWStart"),false);
                       SetFldEnable(this.getField("SWStop"),true);
                       SetFldEnable(this.getField("SWPause"),true);
                       SetFldEnable(this.getField("SWClear"),false);
                       this.getField("SWPause").buttonSetCaption("Pause");
                       break;
                   }
                }

                 

                 

                 

                 

                 

                Many thanks

                Jo

                • 5. Re: Alert for a Stop Watch
                  gkaiseril MVP & Adobe Community Professional

                  Form the script provided, you are aware that the displayed string is a uniquely formatted character string and you will have to match that format for your comparison.  Your stop watch is displaying time formatted as "HH:MM:ss:tt" or hours, minutes, seconds and hundredths of a second (milliseconds divided by 10). If your event time is in only Hours and Minutes, then you need to add the seconds and hundredths of a second for the comparison of the strings or remove the seconds and hundredths of second from the stop watch display value.

                   

                  You do not want to compare to the time length of the agenda item but the agenda item length less 2 minutes. You will need to separate out the minutes from the agenda item length to to get the value of minutes for the agenda item and then build the string for necessary comparison. You might want to adjust the comparison to only hours, minutes and seconds.

                   

                  If your agenda time has a format of "MM;SS" then you can use the 'split' method to extract the minutes values and seconds value.

                   

                  (function () {

                  // adjsut for a 2 minute waring and alert when adjusted time is matched
                  // get the stirng value for the agenda item duration
                  var sAgendaTime = this.getField("Action Time").value;
                  // only perform if there is a value for the event
                  if(sAgendaTime != '') {
                  // convert agenda item duration into an array with the elements for minutes and seconds with the adjusted time
                  var aAgendaTime = sAgendaTime.split(":");
                  var sAgendaWarning = util.printf("%02d:%02d:%02d", 0, aAgendaTime[0] - 2, aAgendaTime[1]);
                  // compare to the stop watch display value
                  if(event.value.substr(0,8) == sAgendaWarning) app.alert('2 min warning');
                  }
                  return;
                  }) ();

                  • 6. Re: Alert for a Stop Watch
                    Jo_2005 Level 1

                    Good morning,

                     

                    Thank you for your help, I am still unable to get the alert to show after adding your script to the calculation part of the stop watch field.

                     

                    I have changed the stop watch document level script by removing the milliseconds.

                     

                    The action time field is purely a text field for user input with a default value of 00:00:00.  There is no time formatting for this field.

                     

                    Could this be the reason the script you have so kindly given me is not functioning ?

                     

                    Many Thanks

                    Jo

                    • 7. Re: Alert for a Stop Watch
                      Jo_2005 Level 1

                      I have done some adjusting to the Acro form and the script you provided now works  successfully.

                       

                      I placed the script into a document level script called Alert.

                       

                      In the calculation area of the Stop Watch Field the document level script Alert(); was added.

                       

                      The alert shows successfuly, however the alert is showing 1 second before the Action time, not 2 minutes.

                       

                      Please advise how I can adjust the script to show alert in minutes rather than seconds?

                       

                      Much appreciated for your help, thank you very much.

                       

                      Jo

                      • 8. Re: Alert for a Stop Watch
                        gkaiseril MVP & Adobe Community Professional

                        I set the activity time for minutes and seconds, You can add an hours element but you will need to adjust the script for converting the time string into the number of minutes or seconds, adjusting the numeric value of the activity time and then converting the time back into a formatted string.

                        • 9. Re: Alert for a Stop Watch
                          Jo_2005 Level 1

                          I need to show the Action time field as 00:00:00 because there are other time fields requiring this format for calculations:

                           

                          I have modified the script to include the hours as well as the minutes and seconds.

                           

                          The alert is not showing, so I have not converted the hours correctly.

                           

                          Can you please advise where the script can be modified?

                           

                          function Alert() {
                          // adjsut for a 2 minute waring and alert when adjusted time is matched
                          // get the stirng value for the agenda item duration
                          var sAgendaTime = this.getField("Action Time").value;
                          // only perform if there is a value for the event
                          if(sAgendaTime != '') {
                          // convert agenda item duration into an array with the elements for minutes and seconds with the adjusted time
                          var aAgendaTime = sAgendaTime.split(":");
                          var sAgendaWarning = util.printf("%02d:%02d:%02d", 1, aAgendaTime[0], aAgendaTime[1] - 2,aAgendaTime[2]);
                          // compare to the stop watch display value
                          if(event.value.substr(1,8) == sAgendaWarning) app.alert('2 min warning');
                          }
                          return;
                          } Alert;

                           

                           

                          Thanks very much

                          Jo