我已经尝试过这里的示例代码( a = b + c
)。令人惊讶的是,现实并非预期的行为。
在 Win7 和 LO 4.4.2.2 中,我看到a
并被b
声明为值为 0 且c
为空的整数。
对于 Ubuntu 16.04 和 LO 5.1.6.2,它们都是空的。
知道如何解释第一种情况吗?
我已经尝试过这里的示例代码( a = b + c
)。令人惊讶的是,现实并非预期的行为。
在 Win7 和 LO 4.4.2.2 中,我看到a
并被b
声明为值为 0 且c
为空的整数。
对于 Ubuntu 16.04 和 LO 5.1.6.2,它们都是空的。
知道如何解释第一种情况吗?
From https://help.libreoffice.org/Basic/Using_Variables:
As soon as the variable has been declared, it is automatically set to the "Null" value. Numeric variables are automatically assigned the value "0" as soon as they are declared.
As the link in the question seems to suggest, implicit initialization is bad programming practice in Basic. So strange results should not be surprising when using old versions.
With Perl, $a = $b + $c;
sets the value of $a to zero because it is a mathematical result, and $b and $c are initialized to an empty string. Perl has a long history of facilitating undeclared variables, although nowadays use strict
is recommended.