i just want to know what this formula means .need help. please elaborate with if else statements.
=(IF(D11<=49.69,8.2404,IF(D11<50,((50-D11)*100*0.2084)+1.78, IF(D11>50.04, 0, ((50.05-D11)*100*0.356)))))
The syntax of the IF function in Excel is =IF(condition,value1,value2) where condition is something that evaluates to either TRUE or FALSE. value1 and value2 can be anything valid for insertion into an Excel cell: number, text or a formula. In the question, value2 is a formula which just happens to be another IF function and which also happens to contain further IF's in its arguments.
You can think of an IF in programming terms as
`If Condition Then Value1 Else Value2 End If'
The Help system in Excel is usually quite useful and a lot quicker than posting here and waiting for replies.
this is the logic:
If (D11<=49.69) Then
8.2404
Else
If (D11<50) Then
((50-D11)*100*0.2084)+1.78
Else
If (D11>50.04) Then
0
Else
((50.05-D11)*100*0.356)
End if
End If
End if
translated in php as:
if ($D11 <= 49.69) {
$x = 8.2404;
} elseif ($D11 < 50) {
$x = ((50-$D11)*100*0.2084)+1.78;
} elseif ($D11>50.04) {
$x = 0;
} else {
$x = ((50.05-$D11)*100*0.356)
}
Related
I want to make coding about the final score display. If someone has done 10 multiple choice questions and he clicks on the final score button, then his final score will appear along with the description. The score will be made in a range according to the category, namely 1-59 = Under Average, 60-79 = Average, and 80-100 = Above Average.
I've tried coding it but I found error 1176 on line 7 and 11.
Can you help me fix it?
finalscorebutton.addEventListener(MouseEvent.CLICK, finalscore);
function finalscore(event:MouseEvent):void
{
multiplechoicefinalscore.text = sumofscores;
var finalscore:String = finalscore.toString;
finalscore = multiplechoicefinalscore..text;
if(finalscore.toString < 60){
description.text =
"UNDER AVERAGE.";
}
else if(finalscore.toString >= 60 && finalscore.toString <=79){
description.text =
"AVERAGE.";
}
else{
description.text =
"ABOVE AVERAGE.";
}
}
There are multiple syntax and logic errors.
Something.toString is a reference to a method, you probably mean Something.toString() which calls the said method and returns a text representation of whatever Something is.
You don't need a text representation because you want to compare numbers, you need a numeric representation (which is either int, uint or Number).
There are 2 dots in multiplechoicefinalscore..text, what does it even mean?
There is function finalscore and then you define var finalscore, defining things with the same names is a bad idea in general.
You should keep your script formatted properly, otherwise reading it and understanding would be a pain.
So, I assume you have the user's result is in sumofscores. I'm not sure if the script below will actually work as is, but at least it is logically and syntactically correct:
finalscorebutton.addEventListener(MouseEvent.CLICK, onFinal);
function onFinal(e:MouseEvent):void
{
// Ok, let's keep this one, I think you are putting
// the score result into some kind of TextField.
multiplechoicefinalscore.text = sumofscores;
// Get a definitely numeric representation of the score.
var aScore:int = int(sumofscores);
// In terms of logic, putting the complicated condition case
// under the "else" statement will simplify the program.
if (aScore < 60)
{
description.text = "UNDER AVERAGE.";
}
else if (aScore > 79)
{
description.text = "ABOVE AVERAGE.";
}
else
{
description.text = "AVERAGE.";
}
}
let duration = "365460"
console.log((/^\d+$/.test(duration)))
Actual result: false
Expected result: true
But,
let duration = "11"
console.log((/^\d+$/.test(duration)))
Actual result: true
Expected result: true
What could be the problem? Please guide me
There's an extra character after 365460, and that's why your pattern does not match!
You can use the following to diagnose such issues in the future:
const duration = "365460";
for(let i = 0; i < duration.length; ++i) {
console.log(`Char at index ${i}: ${duration[i]} | Unicode: ${duration.charCodeAt(i)}`);
}
As you may observe from the result of the above code, there is a character with unicode value 8236, which is some sort of formatting character known as "Pop Directional Formatting".
https://www.codetable.net/decimal/8236
There is a unicode character at the end of the string which makes result false.
duration = "365460"
console.log(duration.split(""));
console.log(duration.length); // 7 instead of 6
isdigit(str) {
let pattern = /^\d+$/
if (str.match(pattern)) {
return true
} else {
return false
}
}
You can use the above function it solves the problem of detecting only numbers.
You can use isNaN() instead which would be the relevant syntax in your case
I am trying to get input from a user, lookup the input value in an Excel column and return the value of the cell on the right side of the matching value.
This is what I came up with. As long as I replace %index% with a number, it will return a value from the Excel file.
The error I receive tells me there is a 'type mismatch' where I use %index% in
value := workbook.Sheets("Sheet1").Cells(%index%, 1).Value
Any ideas how to fix the type mismatch?
#a::
workbook := ComObjGet("somepath\tester.xlsx")
InputBox, OutputVar, Question 1, What are you looking for?
if (OutputVar)
MsgBox, Let me do this for you.
intent = OutputVar
index = 1
value = ""
Loop {
index := %index% + 1
value := workbook.Sheets("Sheet1").Cells(%index%, 1).Value
}
Until %intent% = %value%
SendInput, workbook.Sheets("Sheet1").Cells(%index%, 2).Value
Return
Use index, not %index%, in expressions. Also, you can use the built-in A_INDEX variable inside of loops
Here's your corrected code:
#a::
workbook := ComObjGet("somepath\tester.xlsx")
MAX_ROWS := 10
InputBox intent, Question 1, What are you looking for?
if ( ErrorLevel == 0 && intent ) {
Loop %MAX_ROWS% {
if ( intent == workbook.Sheets("Sheet1").Cells(A_Index, 1).Value ) {
SendInput % workbook.Sheets("Sheet1").Cells(A_Index, 2).Value
return
}
}
MsgBox 48, Not Found, "%intent%" not found in column a
}
return
Notes:
You cannot use substitution when a command takes an expression
ErrorLevel == 0 means OK was pressed. See InputBox
SendInput % makes the line use expression mode; everything following "% " is evaluated as an expression
Your loop never exits if intent is not found in the spreadsheet
I tried to add a column named FTE containing this formula :
=I2/SUMPRODUCT(I:I,(M:M=M2) * (C:C=C2) * (N:N=N2))
This formula worked when applied in Excel, but when added from php, I just get an error:
maximum execution time calculation.php phpexcel
$assembly = $arrayWorksheet->addColValByRow($assembly, 'FTE', ['= I', '/SUMPRODUCT(I:I,(M:M=M', ')*(C:C=C', ')*(N:N=N'], '))');
// Output : =I2/SUMPRODUCT(I:I,(M:M=M2)*(C:C=C2)*(N:N=N2))
Sadly I can't figure out why. My initial formula was SUMIFS that I converted into SUMPRODUCT, because I know that SUMIFS isn't implemented yet.
function addColValByRow($worksheet, $title, $valArray, $finalVal = NULL) {
// Take the last column
$lastCol = key( array_slice( $worksheet[1], -1, 1, TRUE ) );
$newCol = ++$lastCol;
// tke the last cell
$lastCell = key( array_slice( $worksheet, -1, 1, TRUE ) );
$worksheet[1][$newCol] = $title;
for ($i = 2; $i <= $lastCell; $i++) {
$worksheet[$i][$newCol] = "";
foreach (array_keys($valArray) as $key) {
$worksheet[$i][$newCol] .= $valArray[$key] . $i;
}
if ($finalVal != NULL) {
$worksheet[$i][$newCol] .= $finalVal;
}
}
return $worksheet;
}
It's not SUMPRODUCT() that's causing the problem, it's the fact that PHPExcel doesn't support column/row ranges fully, so it's a column range like I:I or M:M or C:C that's causing the problem.
If you can change this to an actual cell range (e.g. I1:I2048), then it shouldn't be an issue.
And (for future reference) SUMIFS() is implemented in the latest code in the develop branch on github
I'm currently coding a game for an assignment and I need help comparing Strings.
The question in the game asks the users to type out a specific sequence on their keyboard. I have provided a sequence "SWAGAFFAD" and I want my code to compare a the values that people might enter. If they get the sequence correct I want them to be able to proceed to the next question and if they don't type in the exact sequence they just get an error message come up. Just not sure how to code this. Can someone help me out? Assuming I'd need an IF ELSE statement??
Thanks in advance!!!
Use the == and != operators to compare strings with each other and to compare strings with other types of objects, as the following example shows:
var str1:String = "1";
var str1b:String = "1";
var str2:String = "2";
trace(str1 == str1b); // true
trace(str1 == str2); // false
var total:uint = 1;
trace(str1 == total); // true
for more detail info adobe doc
You can use ObjectUtil.compare(string1,string2). It will return 0 if both the strings are equal else 1 or -1
Yes you might want to use if-else statement and == operator as others suggested. Here's one very simple way:
var word:String = "SWAGAFFAD";
var index:int = 0;
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
function keyUp(e:KeyboardEvent):void{
if(String.fromCharCode(e.keyCode) == word.split("")[index]){
index++;
trace("Correct letter!");
if(index == word.length){
//Player got the whole word, proceed to next one
}
}else{
//Wrong letter, do something else
}
}