I have a pretty simple calculation in gravityform, but because I add +1 and +0.5 to what people are filling out in the input fields, then the total from the begining is showing a number instead of only 0.
Example:
Field A +1
Field B +0.5
Calculation Field A x B x 295. But because I add +1 and +0.5 to what people put in the input field, then the total from the beginning, shows 147,5. Because it calculate 1*.0.5*295 = 147,5.
But I want the total just to show 0 until people are filling out the input field.
How can I avoid this?
Your best bet for a code-based solution will probably be to use the gform_calculation_result filter and check a value of 1 or 0.5 and return 0 instead.
gform.addFilter( 'gform_calculation_result', function( result, formulaField, formId, calcObj ) {
if ( result == 1 || result == 0.5 ) {
result = 0;
}
return result;
} );
An alternate approach would be to use conditional statements right in the calculation formula, powered by our Gravity Forms Advanced Calculations plugin.
You could check if the field has a value and provide a formula for that and return 0 otherwise.
if ( F1 > 0 ):
F1 + 1
else:
0
endif;
Related
I am trying to extract an integer value from R console by asking the user the question: "How many dice do you want to save?". The user can only choose a number between 1 to 5.
Following is my code snippet:
# .... previous steps to roll 5 dices and print output
cat("Player ", player_start, ":\nDice after 1 roll(s):\n", x, "\nHow many dice do you want to save?")
number_saved_dices <- scan()
#if number_saved_dices out of the range, stop the function
if(number_saved_dices > 5 || number_saved_dices < 0 ) {
stop("You can only save between 0 and 5 dices. Try again:")
} else if(number_saved_dices == 5 ) {
#if player wants to save all five
print("For which category should the result be used?")
} else if( 0< number_saved_dices < 5 ) {
print("Please enter the values of the dice to save.")
}
For example, if the user wants to save 12 dices, then the script should be stopped with the error message "You can only save between 0 and 5 dices. Try again. " However, I can't perform if-else control flow with the number_saved_dices.
I would appreciate any help or insight!!
Thanks very much in advance!
I'm trying to get the product of 2 fields in the 'ELSE' portion of a CASE statement of a Formula(Text) row in a Netsuite saved search, but I keep getting 'ERROR: Invalid Expression' when I run the search. Current formula is:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
I've tried to simplify it by doing something like this:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE 1 + 1 END
But it still fails with an invalid expression error. All of the Googling I've done leads me to believe that this should work, but I can't seem to find my mistake. I'm hoping the extra eyes here can give me a kick in the right direction. Thank you.
The data type returned from the formula needs to match the Formula type selected. You can correct your formula by setting it to a Formula (Numeric) type and simply removing the quotes around the '0' after the first THEN:
CASE WHEN {binonhandcount} = 0 THEN 0 ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
Or if you really want a text formula for some reason, you can wrap the ELSE statement in a TO_CHAR function:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE TO_CHAR(NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0)) END
In your NetSuite saved search replace Formula(text) to Formula(Numeric).
And your formula would be:
CASE WHEN {binonhandcount} = 0 THEN 0 ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
Please remove the string from THEN '0'. You should be fine.
I have a groovy collections which is an array, containing value starting from 0 through 'n'. I need to find a particular array index when a series of conditions occured. And,I do not need to scan through every value of the array but can jump across pre-defined intervals. For example, look for the condition for every 10 values in the array. Can someone tell me a way to do this?
For example, I want to do somehting like this below
def alltimes = [0 . . . . . 10000]
def end_time = 10000
def time = 0
while(time <= end_time)
{
// check the condition for alltimes[time]
if(condition_satisfied){
println "condition satisfied at time ${time}"
break
}
time = time + 50
}
When i explored all available methods of array, i did not find any one which can allow to jump variables instead of just one as in methods each, eachwithindex.
Seems like I need to use metaclass and create a new method?
You can use find for this:
def allTimes = 0..10000
Closure<Boolean> checkCondition = { all, single ->
single > 300
}
(0..10000).step( 50 ).find { time -> checkCondition( allTimes, time ) }
Which is ripe for currying:
def allTimes = 0..10000
Closure<Boolean> checkCondition = { all, single ->
single > 300
}
(0..10000).step( 50 ).find checkCondition.curry( allTimes )
Is there an existing function where we can pop a (key,value) pair from a map in GO? I use the word pop instead of remove because a pop would re-arrange the elements after the index where the (key,value) was removed.
As an example the following code:
package main
import "fmt"
func main() {
mapp := make(map[int]int)
fmt.Println("before removal:")
for i := 1; i < 7; i++ {
mapp[i] = i
}
fmt.Println(mapp)
delete(mapp, 2)
fmt.Println("\nafter the removal:")
for i := 1; i < 7; i++ {
fmt.Println(i, mapp[i])
}
}
Produces the following output:
before removal:
map[1:1 2:2 3:3 4:4 5:5 6:6]
after the removal:
1 1
2 0
3 3
4 4
5 5
6 6
We notice that index location 2 is empty. I would like the output to be the following:
before removal:
map[1:1 2:2 3:3 4:4 5:5 6:6]
after the removal:
1 1
2 3
3 4
4 5
5 6
Is this functionality already in Go or would I have to implement it?
I think that you are misunderstanding what a map is and how it works. You should not see it as an "array with gaps", but as a classic hash table.
And to answer your question, when you use delete(), the value is deleted from the map, the problem is how you iterate over the "values" of the map.
To help you understand:
mapp := make(map[int]int)
fmt.Println(2, mapp[2])
will print
2 0
Why ? Simply because when the requested key doesn't exist, we get the value type's zero value. In this case the value type is int, so the zero value is 0.
So, you want to see if a key exists in the map before printing it and you have to use two-value assignment, like that:
for i := 1; i < 7; i++ {
if value, exists := mapp[i]; exists {
fmt.Println(i, value)
}
}
and it will print
1 1
3 3
4 4
5 5
6 6
Not really what you want, but the closer you can get directly with maps.
You can have a look at this blog post for more information and examples.
If you really want to have an array where you can remove values, see Verran's answer and use slices instead.
From the Go documentation:
When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next.
From this, it follows that there would be no way to automatically move a value up one position to fill a gap, since the key can be in a different iteration position each time you look at the values and theres no guarantee that the value mapped to 2 will slide up to 1.
If you want to do something like this, you will have to manually shift everything down one key value, something like:
for key := 2; key < len(map)-1; key++ {
map[key] = map[key+1]
}
Alternatively, you could use slices and if you know the index you need to "pop", create a new slice that omits the value:
value := slice[2]
slice = copy(slice[:2], slice[2+1:])
First off, let me warn you that my Maths knowledge is fairly limited (hence my coming here to ask about this).
It's a silly example, but what I essentially want is to have a variable number of rows, and be able to set a maximum value, then for each progressive row decrease that value until half way at which point start increasing the value again back up to the maximum by the final row.
To illustrate this... Given that: maxValue = 20, and rows = 5, I need to be able to get to the following values for the row values (yes, even the 0):
row 1: 20
row 2: 10
row 3: 0
row 4: 10
row 5: 20
There are limitations though because I'm trying to do this in Compass which uses SASS. See here for the available operations, but to give you the gist of it, only basic operations are available.
I'm able to loop through the rows, so just need the calculation that will work for each individual row in the series. This is the kind of loop I'm able to use:
$maxValue:20;
$rows:5;
#for $i from 1 through $rows {
// calculation here.
}
I haven't really worked with SASS before, but try something like this using a basic if and the floor function, not sure if will work
// set various variables
$maxValue:20;
$rows:5;
// get row number before middle row, this instance it will be 2
$middleRow = floor( $maxValue / $rows )
// get increment amount, this instance should be 10
$decreaseValue = ( max / floor( rows / 2) )
#for $i from 0 through $rows - 1 {
#if $i <= $middleRow {
( $maxValue- ( $decreaseValue * $i ) )
}
#else{
// times by -1 to make positive value
( $maxValue - ( $decreaseValue * -$i ) ) * -1
}
}
I have tested the above in js ( with relative syntax ) and it yielded the required results ( jsBin example ). Hope this helps