1 Reply Latest reply on Feb 15, 2012 6:38 AM by nabnub

    How to calculate the total of absences? How to collect data from a specific line of a table?

    nabnub Level 1


      Again, I made a nice coloured picture from a screen capture which summarise the improvements that I would like to make in my form,




      For an educational purpose, I made this form   to simplify the way of recording the data and also to develope the independence of the students.

      ( I am doing this on a voluntary basis, working extra hours on my free time but I don't really mind because I am learning a lot of things in the same time)


      After being tested by the teacher, the student has to record the short date, the lines memorised, his grade, number of mistakes, and his attendance.


      I created everything in Word, then converted the file in PDF, then I created all the different fields with Adobe acrobat.


      There is in total 4 sheets, there are all similar except the first one in which there is a box with: date started, date finished, total time spent, absences.


      Below this box there is a table with 16 lines from (A to P) and 7 columns (Days, Date, From.. to.. , Grade, No. lines memorised, No. Errors, Attendance) ( so this table is present on all the sheets)


      Due to the fact that some students need more time than others, and also beacause some text need more time, I estimated a need of 4 sheets at the very most.

      I would like to make the following amelioration and automate the inputting of some of the data because I know that some of the students will certainly forget, so to avoid this scenario I am trying to make this form the easiest possible.



      screen capture of the form:


      2 questions.jpg


      screen capture of the form editing, you can see the names of the different fields:



      FORM EDITING.jpg




      here is the form (only the first page) : http://cjoint.com/12fe/BBotMMgfYIy_memorisation_sheet_sample.pdf



      In  yellow 00000:



      At present, the students has to input the total of absences manually, is there a way ( script) to automate this by initialising the field next to "Absences" at  " 0 day"   and then everytime that Absent is selected from the COMBO BOX, it add 1 and it is displayed like this:  " 1 day" then " 2 days"  then " 3 days" etc … (so from what I read I have to initialise a counter a the beginning and then for (i...   ) count= count++; something like this...


      Furthermore, I need a solution to overcome the possibility that a second sheet may be needed for the same student; therefore I would need the data from the "attendance column" from the second sheet ( and perhaps the 3rd and 4th aswell) to be added on the "absences field" in the first sheet


      My idea: everytime that the short date is inputted in the first line (next to A) in the "Date" column of one of the 4 sheets then we check the 16 Combo box of the attendance column in this sheet instead to check 16*4=64 fields fot the 4 sheets in one go?

      but I don't know at all how to write it in Javascript. Or perhaps there is a way more easier than that?

      Shall I allocate a value for Absent on the “ export value”?



      In purple


      At present I wrote a simple script which matches the number of lines to the poem selected (Eg.  if I select the poem V.Hugo,  the number "36" will appear next to Number of lines).

      Again I would like the make the life of the students very easy so I would like a script which detects this number “36” on the "From .. to …" column,  as soon it is detected (on the first sheet or 2nd or 3rd or 4th)  check from the same line if "A / Pass" or "B / Pass" have been selected in the "Grade" column ,if yes the short date inputted on this line will be written on the field next to "Date finished" .


      this is a simple example with 36 lines only but somethimes, the students may have to memorise 80 lines and more, this is the reason for having 4 sheets in total.


      So basically I would like to automate the field next to" Date finished:" with a script that collect the short date from the day in which the student has finished his memorisation with "A / Pass" or "B / Pass"



      As for the "Total time spent" George Johnson helped me with a script that calculate the difference betwen date started and date finished (thank you)



      I am sollicting your help, because after trying for hours I was really confused with the different if/else needed. And in top of that, it’s my first experience with Javascript.



      I anticipate your assistance, thanking you in advance.

        • 1. Re: How to calculate the total of absences? How to collect data from a specific line of a table?
          nabnub Level 1

          I found this for counting the absences, its give you the total that's perfect, but is there a better methode which avoid me to write all the fields name, more simple????





          ( I found the idea here : Re: Total number added automatically  )




          // custom calculation script for field "Total #"


          function CountFields(aFields) {

          var nFields = 0;

          for(i = 0; i < aFields.length; i++) {

          try {

          // count null values, export value of Absence is 0;

          if(this.getField(aFields[i]).value == "0") nFields++;

          } catch(e) {

          if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);

          else app.alert(e.toString());

          } // end catch

          } // end for aFields

          return nFields;




          // create array of field names to count


          var aNames = new Array("Sheet1AttendanceA","Sheet1AttendanceB","Sheet1AttendanceC","Sheet1AttendanceD","Sh eet1AttendanceE","Sheet1AttendanceF",

          "Sheet1AttendanceG","Sheet1AttendanceH","Sheet1AttendanceI","Sheet1AttendanceJ","Sheet1Att endanceK","Sheet1AttendanceL",

          "Sheet1AttendanceM","Sheet1AttendanceN","Sheet1AttendanceO","Sheet1AttendanceP" );


          // count the non-null fields;


          event.value = CountFields(aNames);




          As for the 2nd question, I've tried to do something similar to the previous script, but of course it doesn't work, but I am quite sure that the idea is similar:

          I don't know also how to add the other condition: the student should get A / Pass or B / Pass in order to consider he has finished??? and also how to check these condition from page 2, 3 and 4 and collect the date



          function Datefinished(bFields) {

          d2.value = nFields[i].value;

          for(i = 0; i < aFields.length; i++) {

          try {

          if(this.getField(aFields[i]).value == this.getField("NumberLines").value) d2.value = nFields[i].value;

          } catch(e) {

          if(e['message'] == "this.getField(aFields[i]) has no properties") app.alert("unknown field name: " + aFields[i]);

          else app.alert(e.toString());

          } // end catch

          } // end for aFields

          return nFields;




          // create array of field names to check




          var aNames = new Array("Texte00","Texte54","Texte56","Texte58","Texte60","Texte62","Texte64","Texte66","Te xte68","Texte70","Texte72","Texte74","Texte76","Texte78","Texte80","Texte82");




          var bNames = new Array("d1","d3","d4","d5","d6","d7","d8","d9","d10","d11","d12","d13","d14 ","d15","d16","d17");   // d1 is included because in some cases a student can finish in 1 day (short text);

          1 person found this helpful