简体   繁体   English

如果LiveCycle用Java编写其他语句

[英]If Else Statements in Javascript for LiveCycle

I am creating a form on Adobe LiveCycle that adds the numbers in different fields. 我正在Adobe LiveCycle上创建一个将数字添加到不同字段中的表单。 I need to have the final field (Eligible Assets) add all the previous fields but exclude the sum of three of them and one in specific but only if it is greater than 60000. I've written the script as follows for the first part (to sum all the fields) this is in a field I've titled TotalAssets: 我需要在最后一个字段(合格资产)中添加所有之前的字段,但要排除其中三个的总和,但要具体包括一个,但前提是该字段必须大于60000。我为第一部分编写了以下脚本(对所有字段求和),这是在我名为TotalAssets的字段中:

this.rawValue =Cash.rawValue+SavingsAccount.rawValue+ChildrensSavings.rawValue+CheckingAccount.rawValue+ValueHome1.rawValue+ValueHome2.rawValue+ValueVehicle1.rawValue+ValueVehicle2.rawValue+ValueVehicle3.rawValue+BusinessAccount.rawValue+BusinessAssets.rawValue+StocksBonds.rawValue+Retirement.rawValue+CDs.rawValue+OtherInvestments.rawValue+OtherAssets.rawValue;

This has worked fine, but the Retirement value if it is greater than 60000 should not be added into the calculation. 此方法工作正常,但如果退休值大于60000,则不应将其添加到计算中。 This is what I've written (EligibleAssets): 这是我写的(EligibleAssets):

if (Retirement.rawValue > 60000) {
Retirement.rawValue = 0; 
} else {
Retirement.rawValue == Retirement.rawValue ; 
}

this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue+ValueVehicle1.rawValue +Retirement.rawValue);

When I save the form as a PDF the first total of the fields calculates correctly but the second field comes up blank. 当我将表单另存为PDF时,第一个字段总计可以正确计算,但是第二个字段为空白。

If you can spot what I'm missing or doing wrong I would really appreciate any feedback. 如果您能发现我的缺失或做错事,我将不胜感激。 Thank you! 谢谢!

There are two simple problems that I see here. 我在这里看到两个简单的问题。

First problem is that you are using == when you should be using = . 第一个问题是,当应该使用=时,您正在使用==

== - check if the left side is equal to the right side. == -检查左侧是否等于右侧。 Example: if(x == 5) { 示例: if(x == 5) {

= - set the left side to the value of the right side. = -左侧设置 右侧的值。 Example: x = 5 示例: x = 5

In the first example we leave x alone, but in the second example we change x to 5. 在第一个示例中,我们不理会x,但是在第二个示例中,我们 x 更改为5。

So your code should look like: 因此,您的代码应如下所示:

} else {
    Retirement.rawValue = Retirement.rawValue;
}

However, when you think about this, this code doesn't actually do anything. 但是,考虑到这一点,此代码实际上并没有执行任何操作。 Retirement.rawValue will not change. Retirement.rawValue不会更改。

This leads us to the second mistake in the code, at least, it looks to me like a mistake. 这导致我们在代码中出现第二个错误,至少在我看来,这是一个错误。

if(Retirement.rawValue > 60000) {
    Retirement.rawValue = 0;
}

This actually changes Retirement.rawValue , which might potentially change what's inside the Retirement field of your form . 这实际上会更改 Retirement.rawValue ,这可能会更改表单的Retirement字段中的内容 Worse, its possible that the form would look the same, but act differently when some other field calculates, since you've changed its rawValue . 更糟的是,其可能的形式看起来相同,但采取不同的,当一些其他领域的计算,因为你已经改变了它的rawValue That would be a very tough bug to catch. 那将是一个很难捕捉的错误。

The solution is to create a new variable: http://www.w3schools.com/js/js_variables.asp 解决方案是创建一个新变量: http : //www.w3schools.com/js/js_variables.asp

So now we can create a new variable, set that variable to either the retirement amount or nothing, and then add that variable to the other rawValue s at the end: 因此,现在我们可以创建一个新变量,将该变量设置为退役金额或不设置任何值,然后最后将该变量添加到其他rawValue

var retirementOrZero;

if(Retirement.rawValue > 60000) {
    retirementOrZero = 0;
} else {
    retirementOrZero = Retirement.rawValue;
}

this.rawValue = TotalAssets.rawValue - (ValueHome1.rawValue + ValueVehicle1.rawValue + retirementOrZero);

Now we have a number that we can name anything we want, and we can change it however we want, without affecting any code but our own. 现在,我们有了一个数字,可以命名所需的任何名称,并且可以根据需要更改名称,而不会影响任何代码,但不会影响我们自己的代码。 So we start by checking if our retirement value is greater than 60000. If it is greater, we set our variable to 0. Otherwise, we set our variable to the retirement value. 因此,我们首先检查我们的退休值是否大于60000。如果更大,则将变量设置为0。否则,将变量设置为退休值。 Then we add that variable we made, to the home and value cost. 然后,我们将所做的变量添加到房屋和价值成本中。

As a final question, is it supposed to do 最后一个问题,它应该做吗

if(Retirement.rawValue > 60000) {
    retirementValueOrZero = 0;
}

or is it supposed to do 还是应该做

if(Retirement.rawValue > 60000) {
    retirementValueOrZero = 60000;
}

Of course, if you are setting it to 60000 instead of setting it to zero, you probably want to name your variable cappedRetirementValue or something like that -- just make sure you rename it everywhere its used! 当然,如果将其设置为60000而不是将其设置为零,则可能要命名您的变量cappedRetirementValue或类似的名称-只需确保将其重命名即可!

Hopefully that helps! 希望有帮助!

Edit: You said you're only adding retirement value if it is greater than 60k, so what you want is this: 编辑:您说您仅在退休价值大于60k时才添加,所以您想要的是:

if(RetirementValue.rawValue > 60000) {
    retirementValueOrZero = RetirementValue.rawValue;
} else {
    retirementValueOrZero = 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM