mardi 1 août 2017

This formula can't be entered because it uses more than 64 levels of nesting

If i get this message of 64 levels, am i able somehow still use more than 64 if? or i need to think new formula?

Maybe someone can help me to create new?

I need to check if one cell equal to other more than 64 cells, and if it is equal i need to get different value.

For example

=IF(AJ$2=info!$AJ$2;info!$AJ3;IF(Production!AJ$2=info!$AK$2;info!$AK3;IF(Production!AJ$2=info!$AL$2;info!$AL3;IF(Production!AJ$2=info!$AM$2;info!$AM3;IF(AJ$2=info!$AN$2;info!$AN3;IF(Production!AJ$2=info!$AO$2;info!$AO3;IF(AJ$2=info!$AP$2;info!$AP3;....

i have like this table:

enter image description here

And im cheking if my other cell equal to number in table and if yes, returning sign "x" or "-". (im doing this checking for a lot of rows.

Cannot print "no"?

I am very,VERY new to Lua so I got a little stuck studying it.

Why is it that I cannot print "no" here? What else should I add?

if (expression_1) then
    if (expression_2) then
      print("yes")
    end
  else
  if (expression_3) then
      print("no")
    end

if-else statement ignored on RubyonRails view (html.erb)

I have a weird situtation with a RubyOnRails if-else statement.

I have an string named pregunta[1] which I obtained in this way:

pregunta[1] can have 3 possible values: (+), (-) or (?)

After that pregunta[1] is assigned to another string named modo in this way:

<%= modo = pregunta[1] %>

Depending of the value of modo, I need to display different things, in order to do that I need 3 different if-else statements:

<%= modo %>

<% if modo == "(+)" %> Write something to modo afirmativo <% end %>

<% if modo == "(?)" %> Write something to modo interrogativo <% end %>

<% if modo == "(-)" %> Write something to modo negativo <% end %>

I put the first line <%= modo %> in order to check that I am reciving the right value. And it is not adding other stuff like \n or something.

On the browser, the .erb.html view, is showing the first line modo value perfectly with the right value, but the three different if-else statements are completely ignored.

I think, it should have something to do with my sintaxis, because I tried a case statement with the same result.

It is not an option to write the code on the controller, I need to have it on the view. Because it is part of another code which I need to have in there.

Any idea about what I am doing wrong?

Thank you. =)

JQuery: using document.on inside if condition

I have one .js file for the whole website, in some places in the code I put $(document).on event inside if condition to make the event only available in certain pages.

example:

if( $(".some-class").length )
{
    $(document).on("click",".some-button",function(){
    ......
    });
}

The code runs fine, but I am worried if this is bad practice? or if it will cause bugs on some older browsers?

I don't think there will be any benefit to performance from what I did, but if it is not harmful then I want to keep it, because it will be difficult to run over all the code to change it.

Cleaner way of writing multiple conditional statements

I need to ask if you guys can find a much cleaner way of rewriting this code. I can't see to make it possible

Update

 const uploadedFiles = images.map((item, index) => {
  const imageContainer = <ImageContainer
      src={item.blobUrl}
      key={index}
      id={index}
      onClose={this.props.removeImage}
    />;

  if (images.length < 2 && item.file.name.match(/.(gif)$/i)) {
    return (
      <ImageGif
        key= {index}
        src= {item.blobUrl}
        onClose={this.props.removeImage}
      />
    );
  } else if (images.length < 2) {
    return { imageContainer };
  } else if (images.length >= 2) {
    if (MAX_SIZE === index + 1) {
      return (<ImageContainer
          src={item.blobUrl}
          key={index}
          id={index}
          onClose={this.props.removeImage}
          hiddenImages={hiddenImages}
        />);
    }
    if (MAX_SIZE !== index + 1) {
      return { imageContainer };
    }
  }

  return null;
});

Would really appreciate any directions. Have a good day.

PHP - Variable returns NULL when setting in if statement

I'm somewhat of an amateur php programmer and am looking for help with an if statement that is not working as I intend it to.

<?php

var_dump($_GET['name']);
var_dump($_GET['id']);
var_dump($search);
var_dump($param);
var_dump($raw);
var_dump($json);

// for debugging
error_reporting(E_ALL);
ini_set('display_errors', 'on');

// choose between either the name or id parameter
if(isset($_GET['name'])) {
    global $search;
    $search = $_GET['name'];
}
elseif(isset($_GET['id'])) {
    global $search;
    $search = $_GET['id'];
}

// build parameters for either name OR id
if (isset($_GET['name'])) {
    $param = http_build_query(array(
        'name' => $_GET['name'],
        'getMembers' => 'yes',
        'rand' => rand(),
    ));
}
elseif (isset($_GET['id'])) {
    $param = http_build_query(array(
        'id' => $_GET['id'],
        'getMembers' => 'yes',
        'rand' => rand(),
    ));
}

// get raw json from server
$raw = file_get_contents("http://ift.tt/2uTLn6n?".$param);

// decode the raw json response
$json = json_decode($raw);

... ?>

Notice how I've dumped the vars on the third line for debugging purposes. $search, $param, $raw, and $json all return NULL every time. I'm thinking it has something to do with the if statements, but I can't figure out what for the life of me. Help would be much appreciated. Cheers!

lundi 31 juillet 2017

Untangling large nested if else code structures in C#

I have inherited a large nested if else structure, I am trying to separate the leaves of the if else tree into separate if statements only e.g. :

if ( c1 )
  { dc1 }
else if ( c2 )
          { dc2 }
     else {dc3}

should become something like :

if (c1) {dc1;}

if ((!c1) & (c2)) {dc2;}

if ((!c1) & (!c2)) {dc3;}

This is much simpler than the unholy structure I am trying to untangle.

Side question : it easy to see that there is no condition that takes into account the case

if ((c1) & (c2)) 

is there a tool or simpler way of linearising the if else structures and seeing all the conditions that have not been included.

I hope my example is correct.