jeudi 2 février 2017

Excel AND Condition to be based on the results of a MATCH Query

So, I've got two tables on one sheet (call them table1 and table2) which are split at row 1128. I have the following statement to see if a value in the B column of table2 exists in the B column of table1: "=IFERROR(IF(MATCH(B1161,$B$2:$B$1128,0),"yes",),"no")" While this is fairly standard, I want this to return a value based on the accumulative results on 1) If the value in table2 exists in table1 (this is the match query above) AND 2) If (in the row of data it found a match in table1) the value of table1's column J is equal to table2's column K in the row I'm performing the query.

Is this possible?

I have come out with this so far, but I don't know how to link the second match by saying "Look in the row in which you found that last bit of data":

=IFERROR(IF(AND(MATCH(B1133,$B$2:$B$1128,0),SecondClauseHere),"yes",),"no")

Any help would be appreciated.

Any way to optimise this loop?

So I am writing a program which reads logs from different files, sorts them by a given status and outputs them to the accordingly files. There are approx. 8-10k logs at any time and I currently have this wile loop to check their status :

    private void SortByStatus(TreeSet<Log> allLogs) {
    Iterator<Log> iter = allLogs.iterator();
    while(iter.hasNext()){
        Log temp = iter.next();
        if(temp.getLogStatus() == Log.Status.INFO)
            INFOlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.WARN)
            WARNlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.DEBUG)
            DEBUGlogs.add(temp);
        if(temp.getLogStatus() == Log.Status.ERROR)
            ERRORlogs.add(temp);
    }
}

I was just wondering if this can be improved in any way, even marginally faster would be nice if possible

Thanks in advance

Short form for Java If Else statement

I have a method which checks null's, I s there a way to short the method to less rows? the code looks "dirty"

private int similarityCount (String one, String two) {

    if (one==null && two==null) {
        return 1;
    } else if (one==null && two!=null) {
        return 2;
    } else if (one!=null && two==null) {
        return 3;
    } else {
        if(isMatch(one, two))
             return 4;
                return 5;
    }
}

Thanks

What does return void 0 === i && (i = 3), 0 === i ? ( ..A.. ) : ( ..B.. ) do?

I came to this code but I don't understand very well what it does..

test.update = function(i) 
{ 
return void 0 === i && (i = 3), 0 === i ? (..A..) : (..B..) 
}

(..A..) and (..B..) are just other lines of code I haven't posted.

Let's say if i would have a 0 value, what the function will return?

What does "void 0 === i && (i = 3)" do? Specially (i = 3). Does that mean that if (void 0 === i) is true and i can get 3, i will be 3? And what about the comma? I've checked this question but I still don't get it.

Sorry for so many questions but I'd like to have a complete answer so I can totally understand what is going on.

Thank you

Function to find wordpress custom post type ancestor

I have been struggling a lot recently with a CPT I'm working with in wordpress.

I have a cpt setup called cats and rewrote the url to 'rewrite' => array( 'slug' => 'our-animals/rehome-a-cat', 'with_front' => false) so the structure is our-animals > rehome-a-cat > cats (individual cpt page).

I want to show a menu on each of those pages which will show the ancestor (our-animals) and the any children minus each indivdual cpt. so for example if I had added a rehome-a-dog page and dogs cpt the menu for our-animals, rehome-a-dog, rehome-a-cat and each indivdual cat and dog cpt will show, our-anmals, rehome-a-dog and rehome-a-cat.

Currently I have a fucntion the find teh ancestor of a page and then displays the menu as I want:

function my_get_ancestor_id($post) {
    if ( $post->post_parent ) {
        $ancestors = get_post_ancestors($post->ID);
        $root = count($ancestors)-1;
        $parent = get_post($ancestors[$root]);
    } else {
        $parent = $post;
    }
    return $parent->ID;
}

and a function to generate my menu

if ( ! function_exists( 'wpb_list_child_pages' ) ) {    
  function wpb_list_child_pages() {
    global $post;   
    $parent_id = my_get_ancestor_id($post);
    if ( is_page() && $post->post_parent ){
      $args = array(
        'sort_order' => 'ASC',
        'sort_column' => 'menu_order',
        'hierarchical' => 1,
        'exclude' => '',
        'child_of' => $parent_id,
        'parent' => -1,
        'exclude_tree' => '',
        'number' => '',
        'offset' => 0,
        'post_type' => 'page',
        'post_status' => 'publish'
      ); 
      $childpages = get_pages($args); 
    }else{
      $args = array(
        'sort_order' => 'ASC',
        'sort_column' => 'menu_order',
        'hierarchical' => 1,
        'exclude' => '',
        'child_of' => $parent_id,
        'parent' => -1,
        'exclude_tree' => '',
        'number' => '',
        'offset' => 0,
        'post_type' => 'page',
        'post_status' => 'publish'
      ); 
      $childpages = get_pages($args); 
    }

    if ( $childpages ) {
        $string = '<ul class="hh-rightmenu-ul">';
        foreach($childpages as $page){
         $string .= '<a href="'.get_page_link( $page->ID ).'"><li class="hh-rightmenu-li"><div class="hh-rightmenu-li-inner">'.$page->post_title.'</div></li></a>';
        }
        $string .= '</ul>';
    }
    echo $string; 
  }

}

Now on our-animals and rehome-a-cat it works great, but I think because teh cpt cats doesnt have a actual physcial parent or something the my_get_ancestor_id function doesnt work when you go to each CPT and no menu is displayed. The second condition in my menu function shows controls the menu on posts as if i put 106(our-animals ID) in place of 'child_of' => $parent_id, it shows the menu I want.

So basically I'm struggling to find a way in my ancestors function to maybe get the ancestor from the slug if its a CPT as it can't find any parent ID.

Any thoughts?

Any help appreciated.

thanks in advance.

Ian

mercredi 1 février 2017

Javascript ELSE error

This is maddening. I have the following javascript:

var ut = "";    
for (var i = 0; i < Rows.length; i++ ) {
        if (i === 0) {
                    ut = "Overwrite";
                } else {
                    ut = "Update";
                }
    }

Throwing this error:

Exception of type 'Jint.Native.JsException' was thrown.

But when I empty the else statement it does not throw the error.

var ut = "";    
for (var i = 0; i < Rows.length; i++ ) {
            if (i === 0) {
                        ut = "Overwrite";
                    } else {
                    }
        }

What would cause this?

How to stop after successful if statement? C programming

I'm trying to get user input to find out deductions from salary and so they put their ID and a salary that is in range with that ID number. For example if I input ID 1 and then a salary of 500 and it should output the salary entered, salary deducted, and net salary. It does all of that, but where it checks if the salary is in range for the correct ID number it checks it with every ID number even after the ID entered has been checked.

#include <stdio.h>
#include <stdlib.h>

int main()
{
int ID;  // variable for ID
float Base_Salary; // variable for base salary
float Amount_Deducted; // variable for amount deducted from employee
float Net_Salary; // variable for employees' net salary

printf("%s", "Enter ID: \n"); // prompt for ID number
scanf("%d", &ID );

// Validate user's ID
if (ID == 1)
    printf("You have entered the ID 1\n");
else { if (ID == 2)
        printf("You have entered the ID 2\n");
        else { if (ID == 3)
            printf("You have entered the ID 3\n");
                else { if (ID == 4)
                    printf("You have entered the ID 4\n");
                        else { if (ID == 5)
                            printf("You have entered the ID 5\n");
                                else { if (ID < 1 && ID > 5)
                                    printf("You didn't enter a proper ID\n");
                                }
                        }
                }
        }
}

printf("%s", "Enter your salary in the appropriate range: \n");
scanf("%f",&Base_Salary);

// Validations

   if (ID == 1 && Base_Salary >= 100 && Base_Salary <= 1000) {
        printf("Base salary is in range for ID given.\n");
   }
   else {
        printf("Salary must be between 100-1000 for ID 1.\n");
   }

   if (ID == 2 && Base_Salary >= 1001 && Base_Salary <= 5000) {
        printf("Base salary is in range for ID given.\n");
   }
   else {
        printf("Salary must be between 1001-5000 for ID 2.\n");
   }

   if (ID == 3 && Base_Salary >= 5001 && Base_Salary <= 10,000) {
        printf("Base salary is in range for ID given.\n");
   }
   else {
        printf("Salary must be between 5001-10,000 for ID 3.\n");
   }

   if (ID == 4 && Base_Salary >= 10,001 && Base_Salary <= 15,000) {
        printf("Base salary is in range for ID given.\n");
   }
   else {
        printf("Salary must be between 10,001-15,000 for ID 4.\n");
   }

   if (ID == 5 && Base_Salary >= 15,001 && Base_Salary <= 20,000) {
        printf("Base salary is in range for ID given.\n");
   }
   else {
        printf("Salary must be between 15,001-20,000 for ID 5.\n");
   }

// Calculations
if (ID == 1) {
    Amount_Deducted = Base_Salary * 0.50;
    Net_Salary = Base_Salary - Amount_Deducted;
    printf("The Base Salary you have entered = %.2f.\n", Base_Salary);
    printf("The Amount of salary deducted is = %.2f.\n", Amount_Deducted);
    printf("The Net Salary is = %.2f.\n", Net_Salary);
}
if (ID == 2) {
    Amount_Deducted = Base_Salary * 1.50;
    Net_Salary = Base_Salary - Amount_Deducted;
    printf("The Base Salary you have entered = %.2f.\n", Base_Salary);
    printf("The Amount of salary deducted is = %.2f.\n", Amount_Deducted);
    printf("The Net Salary is = %.2f.\n", Net_Salary);
}

if (ID == 3) {
    Amount_Deducted = Base_Salary * 2.50;
    Net_Salary = Base_Salary - Amount_Deducted;
    printf("The Base Salary you have entered = %.2f.\n", Base_Salary);
    printf("The Amount of salary deducted is = %.2f.\n", Amount_Deducted);
    printf("The Net Salary is = %.2f.\n", Net_Salary);
}

if (ID == 4) {
    Amount_Deducted = Base_Salary * 3.50;
    Net_Salary = Base_Salary - Amount_Deducted;
    printf("The Base Salary you have entered = %.2f.\n", Base_Salary);
    printf("The Amount of salary deducted is = %.2f.\n", Amount_Deducted);
    printf("The Net Salary is = %.2f.\n", Net_Salary);
}

if (ID == 5) {
    Amount_Deducted = Base_Salary * 4.50;
    Net_Salary = Base_Salary - Amount_Deducted;
    printf("The Base Salary you have entered = %.2f.\n", Base_Salary);
    printf("The Amount of salary deducted is = %.2f.\n", Amount_Deducted);
    printf("The Net Salary is = %.2f.\n", Net_Salary);
}

}