vendredi 28 octobre 2016

Using "If" statements or commands in VBA

I need help with the proper formatting and structure for using an IF statement in VBA to get it to write out certain numbers and values in a cell itself.

I have ZERO experience in coding, in any form, so my wording above might be nonsense-able. So i'll just explain a bit more what i need.

I need to assign letter grades based of percentages using a macro that will work one line at a time. So if the % is 73.5, I need to have the cell next to it read "C" when I use the keyboard shortcut I assign in the macro and have that work no matter what the % is. I know I need to use "If/Then/ElseIF" format, but I simply cannot figure out how to properly type out the command

c++ bool template avoiding if statement

I'm looking a way to avoid if-statement when I'm dealing with template bool function.
Code below shows a simplification of my situation.

#include <iostream>
#include <string>

template<bool var>
void f(){
 std::cout << (var ? "TRUE" : "FALSE") << std::endl;
}

int main(int argc, char* argv[]){
    const bool b = (std::string(argv[1]).compare("TRUE") == 0);
    if (b) f<true>();
    else f<false>();
    return 0;   
}

I would like a way to write something like: f<b>();
But doing so, I obtain the following error:
error: the value of ‘b’ is not usable in a constant expression

Since in my application I have 4 bool templates, I would like to avoid to list all the combination of those four, like:

if(b1 && b2 && b3 && b4) f<true,true,true,true>();
else if (b1 && b2 && b3 && !b4) f<true,true,true,false>();
...

There is a way around? Does exists a shortcut that I can use in some way?
I tried also to use the if-statement shortcut f<(b?true:false)>();,
but I received the same error shows above.

Else if statement seems rational to me but breaks code

Challenge I'm working on:

Sum All Odd Fibonacci Numbers

Given a positive integer num, return the sum of all odd Fibonacci numbers that are less than or equal to num.

The first two numbers in the Fibonacci sequence are 1 and 1. Every additional number in the sequence is the sum of the two previous numbers. The first six numbers of the Fibonacci sequence are 1, 1, 2, 3, 5 and 8.

For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than 10 are 1, 1, 3, and 5.

EX:

sumFibs(1000) should return 1785.

sumFibs(4000000) should return 4613732.

sumFibs(4) should return 5.

Here's what I have that works:

function sumFibs(num) {
if (num === 1) {return 1;}
var fibList = [1, 1];
for(i=2; i < num; i++){
    if (fibList[i-1] + fibList[i-2] > num){
        break;
    }
    //else if ((fibList[i-1] + fibList[i-2])%2 !== 0){
    fibList.push(fibList[i-1] + fibList[i-2]);
    //}
}
return fibList.reduce(function(a, b){return a+b;});
}

It gives me the sum of the Fibonacci sequence, even and odd, up to the value that is less than or equal to the inputted number.

However, part of the challenge was to only add up the odd numbers. Initially, I thought this would be easy enough, but my best efforts have all failed. The part of my code that doesn't work is commented out. Any input equal to 4 or higher yields "NaN" as the result.

Can anyone help? Thanks so much.

use ajax object value as string stored in php variable for IF statement

I have radio group selects a user can choose from that get sent to my php file through ajax, (only the selected option from each group gets their value passed). I can $_POST() grab those values, save them in php variables and print_r() those variables successfully as so:

print_r() result ex: (in browser page)

Array ( [0] => Customer ) Array ( [0] => Completed Workorders ) Array ( [0] => All Workorders )

I am also able to use two of my other variables (from other checkbox values stored as an array) successfully in a MySQL WHERE clause.

Now, I'm trying to build a series of IF statements that say if the php variable = "[one of two value options from the radio group]" then $whereclause = "Some kind of value".

MY HTML CODE:

<label for="revenueCustomer">Customer</label>
<input type="radio" name="revenueTblType[]" id="revenueCustomer" value="Customer">

<label for="revenueCategory">Revenue Category</label>
<input type="radio" name="revenueTblType[]" id="revenueCategory" value="Revenue Category">

<label for="revenueCompletedWO">Completed Workorders</label>
<input type="radio" name="revenueWO[]" id="revenueCompletedWO" value="Completed Workorders">

<label for="revenueStatusWO">Workorder Status</label>
<input type="radio" name="revenueWO[]" id="revenueStatusWO" value="Workorder Status">

<label for="revenueAllWO">All Workorders</label>
<input type="radio" name="revenueWODate[]" id="revenueAllWO" value="All Workorders">

<label for="revenueDateRangeWO">Workorder Date Range</label>
<input type="radio" name="revenueWODate[]" id="revenueDateRangeWO" value="Workorder Date Range">

My $_POST() CODE:

//Get Table Type.
if (isset($_POST['revenueTblType'])) {
  $revenueTblType = $_POST['revenueTblType'];
  print_r($revenueTblType);
};

//Get Report Type
if (isset($_POST['revenueWO'])) {
  $revenueWO = $_POST['revenueWO'];
  print_r($revenueWO);
};

//Get date include value.
if (isset($_POST['revenueWODate'])) {
  $revenueWODate = $_POST['revenueWODate'];
  print_r($revenueWODate);
};

//Get date range.
$revenuefromajax=$_POST['revenuefrom'];
$revenuetoajax=$_POST['revenueto'];

$revenuefromstring = strtotime($revenuefromajax);
$revenuetostring = strtotime($revenuetoajax);

$revenuefrom=date("Y-m-d", $revenuefromstring);
$revenueto=date("Y-m-d", $revenuetostring);

//Get selected Status Values.
if (isset($_POST['revenue_checkboxes'])) {
  $revenue_check = $_POST['revenue_checkboxes'];
};

My IF statements:

if ($revenueTblType == 'Customer') {
        $groupbyclause = "x.company";
        $columnheader = 'Customer';
        $columnname = 'company';
    }
    else if ($revenueTblType == 'Revenue Category') {
        $groupbyclause = "x.revenue";
        $columnheader = 'Revenue Category';
        $columnname = 'revenue';
    }
    else {
        $groupbyclause = "x.revenue";
        $columnheader = 'Revenue Category';
        $columnname = 'revenue';
    }


    if (($revenueWO == 'Completed Workorders') and ($revenueWODate == 'All Workorders')) {
        $whereclause = "x.stagestatus = 'Complete'";
    }
    else if (($revenueWO == 'Completed Workorders') and ($revenueWODate == 'Workorder Date Range')) {
        $whereclause = "(x.stagestatus = 'Complete') AND (x.shippeddate BETWEEN '".$revenuefrom."' AND '".$revenueto."')"; 
    }
    else if ($revenueWO == 'Workorder Status') {
         $whereclause = "x.stagestatus IN (". implode(',', array_map(function($item) {return '"' . $item . '"'; }, $revenue_check)) .")";
    }
    else {
        $whereclause = "x.stagestatus = 'Complete'";
    }

When I run through this code, the result is always the "else" result even though the values for the selected buttons come through successfully.

Do I have to do something to the ajax results so I can use the sent values in my IF statements?

All help is welcome.

Thank you!!!

My formula works in one cell but returns FALSE in another cell

I am trying to perform a calculation and the first IF(OR) condition is giving me the right answer, but the second and third IF(OR) conditions are returning "FALSE" instead of a number.

Cell A23 is a dropdown list of products.

Below is my formula. What am I doing wrong?

=IF(OR(A23="ICS OTT",A23="ICS UI"),ROUNDUP(($B$3*$B$5/250*(1+$B$7)),
IF(OR(A23="ICS+VCS UI"),ROUNDUP(($B$3*$B$5/180*(1+$B$7)),
IF(A23="VCS Apps",ROUNDUP(($B$3*$B$6/180*1+$B$7),
"NA"))))))

Command not found unix shell scripting

So I'm currently working on a school project and I'm trying to write a shell script that will eventually decide which class gradle will build on. But I keep getting an error each time I choose either 1 or 2, but if I select anything else, the script prompts me the correct results.

Example 1: If input = 1

Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal
1
./testScript.sh: line 6: [ 1: command not found
1

Example 2: If input != 1 or 2

Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal
5
You have insulted us, go home!

-

#!/bin/sh

echo "Do you wish to play Tic Tac Toe as a web app or simply in the terminal? (1)Web app (2)Terminal"
read input

if [ "$input" != "1" ] || [ "$input" != "2" ]; then
    echo "You have insulted us, go home!"
elif [ "$input" = "1" ]; then
    echo "1"
elif [ "$input" = "2" ]; then
    echo "2"
fi

I've read and googled but the only suggestion I find is that I need to add spaces between if and [, and between [ and ". But as you can see that is not the case.

How to hide an html element with php if a button is pressed?

I would like to hide a simple div, if someone click a button. The 'details' var holds an id from db.

<div class="greetings" <?php if(isset($_GET['details'])) {echo " style='display: none'"; } ?>
  <p> some text </p>
<div>

But id doesn't work. I appreciate any suggestions :)