简体   繁体   English

Adobe Livecycle cacluations和if语句

[英]Adobe Livecycle cacluations and if statements

my first time posting, and tbh I have very little Xp. 我第一次发帖,而且我的XP很少。 I'm using livecycle for Adobe 9 pro, and trying to make a calculation work, and keep getting error messages. 我正在使用livecycle for Adob​​e 9 pro,并尝试进行计算,并不断收到错误消息。

My basic premise I need to do a calculation: enter info in cella, and have result of (cella/2)-5 rounded down, keeping the negative integer come out in another cell. 我的基本前提是需要进行计算:在cella中输入信息,并将(cella / 2)-5的结果四舍五入,使负整数在另一个单元格中出现。 (yes, trying to do my own 3.5 d20 character sheet for ability scores). (是的,尝试为能力得分做我自己的3.5 d20字符表)。

In excel I was able to string a slightly more complicated trunc formula of =IF((Cella-10)/2<0,TRUNC((Cella)/2-0.5),TRUNC((Cella-10)/2)), but have no idea what to do in livecycle. 在excel中,我可以将= IF((Cella-10)/ 2 <0,TRUNC((Cella)/2-0.5),TRUNC((Cella-10)/ 2))的字符串截断公式稍微复杂一点,但不知道在生命周期中该做什么。

I tried something like this following a tutorial for livecycle, with no avail. 我在针对livecycle的教程之后尝试了类似的方法,但无济于事。 honestly noobing it here on all accounts including where notations and variables should be, thanks for the help. 老实说,在这里包括所有符号和变量应该在所有帐户上使用,感谢您的帮助。

var x = cell1/2-5; var x = cell1 / 2-5; if (x <0) {return Math.ceil(x)}; 如果(x <0){返回Math.ceil(x)}; else {return Math.floor(x)} 其他{返回Math.floor(x)}

//cell1 pick from sheet in livecycle using control+click, tried calculation and enter formats on script line. // cell1使用control + click在livecycle中从工作表中选择,尝试计算并在脚本行中输入格式。 //Do I need a var x for my formula, not sure, some tutorials said yes, others no for live cycle. //我的公式是否需要var x,不确定,有些教程说是的,另一些教程说不是。 //not sure where to put { } if at all. //不确定是否将{}放在哪里。 // Math.floor and Math.ceil do not show up highlighted blue like other functions do in the livecycle script bar, which I leave in javamode for all cells. // Math.floor和Math.ceil不会像其他功能在livecycle脚本栏中一样显示突出显示的蓝色,我在javamode中保留了所有单元格。

Previous answer has got the math right but it won't work in a LiveCycle event (return statement is invalid in an event.) 先前的答案算术正确,但在LiveCycle事件中不起作用(在事件中return语句无效。)

Let's assume you have two fields: cellA (where you input numbers), cellB (where the rounded result should display). 假设您有两个字段:cellA(在其中输入数字)和cellB(在其中显示四舍五入的结果)。 Replace with the actual names in your sheet as necessary. 根据需要替换为工作表中的实际名称。

In the calculate event for cellB (the field that holds the RESULT) put in this code: 在此代码中放置的cellB(包含RESULT的字段)的calculate事件中:

var v = null;
if (cellA.rawValue != null && cellA.rawValue != "")
{   
    v = cellA.rawValue / 2 - 5; 
    v = v < 0 ? Math.ceil(v) : Math.floor(v);
}
this.rawValue = v;

The if statement is there so that it won't calculate when you first open the form. 该if语句在那里,因此在您第一次打开该窗体时将不会计算。

Side note, the javascript editor in livecycle pretty much sucks so don't expect a lot of help with syntax/formatting. 旁注,Livecycle中的javascript编辑器很烂,因此不要期望在语法/格式设置方面有很多帮助。 I would recommend you download Notepad++ and paste the java code in there, it is more helpful for highlighting some syntax and for checking open/closed parentheses. 我建议您下载Notepad ++并在其中粘贴Java代码,这对于突出显示某些语法以及检查打开/关闭括号更为有用。

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

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