Donnez vie à vos documents numériques !
 

Highlight first 2 greatest number

abracadabraPDF Forums PDF – Général Highlight first 2 greatest number

  • Ce sujet est vide.
  • Créateur
    Sujet
  • #46658
    Rakesh Kumar
    Participant

    Sir,

    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

Affichage de 12 réponses de 1 à 12 (sur un total de 12)
  • Auteur
    Réponses
  • #69621
    bebarth
    Maître des clés

    Hi,
    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:

    #69622
    Rakesh Kumar
    Participant

    Sir,

    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.

    #69623
    bebarth
    Maître des clés

    OK, I understood!
    I will have a look later in the day.
    @+
    :bonjour:

    #69624
    Rakesh 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

    #69625
    bebarth
    Maître des clés

    Hi,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:

    #69626
    Rakesh Kumar
    Participant

    Sir,

    Somehow your script is not working and throwing an error in console ,

    ReferenceError: val is not defined
    8:Field:Mouse Up

    Thanks

    #69627
    bebarth
    Maître des clés

    Hi,
    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:

    #69628
    Rakesh Kumar
    Participant

    Thanks 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

    #69629
    bebarth
    Maître des clés

    bonjour,
    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:

    #69630
    Rakesh Kumar
    Participant

    Sir,

    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

    #69631
    bebarth
    Maître des clés

    Hi,
    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         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; i            try {
                    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:

    #69632
    Rakesh Kumar
    Participant

    Thanks, 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.

Affichage de 12 réponses de 1 à 12 (sur un total de 12)
  • Vous devez être connecté pour répondre à ce sujet.