abracadabraPDF › Forums › PDF – Général › Highlight first 2 greatest number
- Ce sujet est vide.
- 
		CréateurSujet
- 
		13 septembre 2021 à 07:02 #46658Rakesh Kumar ParticipantSir, I have say 30 text fields in which user can input numbers, or text or leave it blank now i want that when the user clicks a button then the first 3 greatest number is highlighted / changed color ignoring the blanks or the text values. Also, last 3 smallest number to be highlighted / changed color. Thanks 
- 
		CréateurSujet
- 
		AuteurRéponses
- 
		
			
				
13 septembre 2021 à 19:45 #69621 bebarthMaître des clés bebarthMaître des clésHi, 
 Please try that for the 3 smallest numbers:Code:var theNumbers=[];
 for (var i=0; i<30; i++) {
 var f=this.getField(« theField. »+i);
 f.strokeColor=color.transparent;
 if (!isNaN(f.value) && f.value!= » ») theNumbers.push();
 }
 // Ascending sort
 theNumbers.sort(function(a, b){return a[1]-b[1]});
 // reverse order sort
 // theNumbers.sort(function(a, b){return b[1]-a[1]});
 if (theNumbers.length) {
 for (var i=0; i<3; i++) {
 try {
 this.getField(« theField. »+theNumbers[0]).strokeColor=color.red;
 } catch(e) {}
 }
 }For the 3 greatest numbers, use the reverse order sort script line. 
 @+
 :bonjour:14 septembre 2021 à 01:06 #69622Rakesh Kumar ParticipantSir, The script is not working as intended…. this script is highlighting the first 3 entry of an array after sorting it in ascending ….. however i want the first 3 smallest number in the array to be highlighted after sorting… ie. removing the duplicates in the array. for ex – original array = [8,3,4,2,2,2,3,5,6,4] 
 after sorting the array will be = [2,2,2,3,3,4,4,5,6,8]
 so current script is highlighting 2,2,2 but my requirement is to highlight every entry which equal to 2,3,4 .Hope i was able to explain. 
 Same for the greatest one. it should highlight first 3 greatest number after sorting in descending order avoiding duplicates.thanks. 14 septembre 2021 à 07:11 #69623 bebarthMaître des clés bebarthMaître des clésOK, I understood! 
 I will have a look later in the day.
 @+
 :bonjour:14 septembre 2021 à 07:21 #69624Rakesh Kumar Participant@Bebarth please check your email, the issue has been solved and i have sent you the working pdf file on your email.. plz check and let me to know if it can be improved. thanks 14 septembre 2021 à 18:50 #69625 bebarthMaître des clés bebarthMaître des clésHi,I don't have a lot of things to tell you! 
 I didn't know your UArr function, so I would have written the script like this:Code:var arr=[];
 for (var i=0; i<30; i++) {
 var f=this.getField(« theField. » + i);
 if (!isNaN(f.value) && f.value!= » ») arr.push(f.value);
 }
 var dv=arr.sort(function(a, b){return b – a});
 function uniqueValue(anArray) {
 return anArray.filter((val, ind) => anArray.indexOf(val)===ind);
 }
 var myarr=uniqueValue(dv);
 for (var j=0; j<30; j++){
 var g=this.getField(« theField. » + j);
 if (g.value == myarr[0]) g.fillColor=color.red;
 else if (g.value == myarr[1]) g.fillColor=color.green;
 else if (g.value == myarr[2]) g.fillColor=color.magenta;
 else if (g.value == myarr[3]) g.fillColor=color.yellow;
 else {g.fillColor=color.transparent;}
 }
 this.getField(« Text1″).value= »Greatest 4 unique numbers are : » + « nn » + » « + myarr[0] + « n »+ » « + myarr[1] + « n »+ » « + myarr[2] + « n »+ » « + myarr[3];I allow myself to share both files. 
 @+
 :bonjour:15 septembre 2021 à 04:04 #69626Rakesh Kumar ParticipantSir, Somehow your script is not working and throwing an error in console , ReferenceError: val is not defined 
 8:Field:Mouse UpThanks 15 septembre 2021 à 13:39 #69627 bebarthMaître des clés bebarthMaître des clésHi, 
 That's working fine for me! I usually check the script works fine before sharing…
 Attached is a new version checking the numbers in both orders.
 @+
 :bonjour:17 septembre 2021 à 04:53 #69628Rakesh Kumar ParticipantThanks for the updated version… but this also not working…………. I will send you video of the same, if that would help in sorting out the issue. Thanks 17 septembre 2021 à 17:35 #69629 bebarthMaître des clés bebarthMaître des clésbonjour, 
 Je vois qu'il y a eu 4 téléchargements.
 Quelqu'un d'autre pourrait-il me dire si le script fonctionne ou pas pour elle/lui ?Hi, 
 I see 4 downloads have been done.
 Could someone else tell me if the script works fine for her/him or doesn't work?@+ 
 :bonjour:18 septembre 2021 à 02:26 #69630Rakesh Kumar ParticipantSir, Attached is the video link from downloading the file to testing it .. and error which console shows. https://www.dropbox.com/s/pmpgu1bodg0d7f6/issue.avi?dl=0 Please have a look. Hope this would help to solve the issue. Thanks 18 septembre 2021 à 17:06 #69631 bebarthMaître des clés bebarthMaître des clésHi, 
 I don't understand why the function doesn't work for you. I did a test on both PC and Mac and the file works fine with both OS.
 As your UArr fonction works fine too, you can you it for the file.
 I placed the script in an other funtion. That avoids to get it twice in the buttons:Code:// Document Scriprs
 function UArr(a){
 var newArr=[];
 for (var i=0; i < a.length; i++) {
 if (newArr.indexOf(a)===-1) newArr.push(a);
 }
 return newArr;
 }
 function greatORsmall(wichOne) {
 var arr=[];
 for (var i=0; i<30; i++) {
 var f=this.getField(« theField. »+i);
 if (!isNaN(f.value) && f.value!= » ») arr.push(f.value);
 }
 if (wichOne== »greatest ») {
 var dv=arr.sort(function(a, b){return b-a});
 } else {
 var dv=arr.sort(function(a, b){return a-b});
 }
 var myarr=UArr(dv);
 for (var i=0; i<30; i++){
 var f=this.getField(« theField. »+i);
 f.fillColor=color.transparent;
 if (f.value == myarr[0]) f.fillColor=color.red;
 else if (f.value==myarr[1]) f.fillColor=color.green;
 else if (f.value==myarr[2]) f.fillColor=color.magenta;
 else if (f.value==myarr[3]) f.fillColor=color.yellow;
 }
 this.getField(« Text1″).value= » »;
 if (myarr.length!=0) {
 if (myarr.length>4) var nbNumbers=4;
 else var nbNumbers=myarr.length;
 if (nbNumbers==1) this.getField(« Text1″).value= »The unique number is: »;
 else this.getField(« Text1 »).value= »The « +nbNumbers+ » « +wichOne+ » unique numbers are: »;
 for (var i=0; itry { 
 this.getField(« Text1 »).value+= »nu2022 « +myarr;
 } catch(e) {}
 }
 }
 }// Mouse up action scripts 
 // greatest and smallest buttons
 greatORsmall(event.target.buttonGetCaption());// reset button 
 for (var i=0; i<30; i++) {
 var f=this.getField(« theField. »+i);
 f.value= » »;
 f.fillColor=color.transparent;Please try the new file and let me know. 
 @+
 :bonjour:19 septembre 2021 à 03:03 #69632Rakesh Kumar ParticipantThanks, it is now working for me. also, i have sent 2 or 3 issue on your email.. plz check and let me know if its possible. Thanks again. 
- 
		AuteurRéponses
- Vous devez être connecté pour répondre à ce sujet.
