Description: Consider the following snippet in a Calc document: Function sheetNames As String oDoc=thisComponent sheets = oDoc.sheets For i = 0 to sheets.Count-1 sheetNames = sheetNames + sheets.getByIndex(i).Name Next i MsgBox sheetNames End Function Steps to Reproduce: 1. Open a Calc document 2. Press ALT+F11 3. Open the default module and copy/paste the above snippet 4. Execute it twice Actual Results: First time: Sheet1 Second time: Sheet1Sheet1 Expected Results: First time: Sheet1 Second time: Sheet1 Reproducible: Always User Profile Reset: No Additional Info: Version: 7.1.0.3 (x64) / LibreOffice Community Build ID: f6099ecf3d29644b5008cc8f48f42f4a40986e4c CPU threads: 6; OS: Windows 10.0 Build 19042; UI render: Skia/Raster; VCL: win Locale: de-DE (de_DE); UI: en-US Calc: CL and in Version 4.0.0.1 (Build ID: 527dba6f6e0cfbbc71bd6e7b88a52699bb48799)
Isn't this even a feature? The "function name" return variable is static and keeps its value if not initialized otherwise?
From https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/function-statement "If Static isn't used, the value of local variables is not preserved between calls." So I thought that the value should be cleared. How about recursions?
Created attachment 176035 [details] There is six bugs in code we successfully identified it so we mentioned these in this picture with code #include <iostream> using namespace std; public bool password(string password){ //first check password then user run this program string pass="ak2563"; bool=false; if (pass==password){ // bug:2 we cant compare string like that bool=true; return true; } else { return bool; } } int main() { int power; float number, result = 0; // bug:6 we need to initialized result=1 not "0" int times_of_multiply; //Bugs:1 This veriable times_of_multiply not used in entire program cout << "Enter number and number respectively: "; cin >> number >> power; cout << number << "^" << power << " = "; while (power != 1) { // bug:3 not getting our expected result result *= number; --number; // bug:4 we need to decrement power not number } cout << result, number; // bug:5 we dont need to print number we need to print just result return 0; }
#include <iostream> using namespace std; public bool password(string password){ //first check password then user run this program string pass="ak2563"; bool=false; if (pass==password){ // bug:2 we cant compare string like that bool=true; return true; } else { return bool; } } int main() { int power; float number, result = 0; // bug:6 we need to initialized result=1 not "0" int times_of_multiply; //Bugs:1 This veriable times_of_multiply not used in entire program cout << "Enter number and number respectively: "; cin >> number >> power; cout << number << "^" << power << " = "; while (power != 1) { // bug:3 not getting our expected result result *= number; --number; // bug:4 we need to decrement power not number } cout << result, number; // bug:5 we dont need to print number we need to print just result return 0; }
The content of attachment 176035 [details] has been deleted for the following reason: spam
(In reply to Andreas Heinisch from comment #2) > From > https://docs.microsoft.com/en-us/office/vba/language/reference/user- > interface-help/function-statement > > "If Static isn't used, the value of local variables is not preserved between > calls." > > So I thought that the value should be cleared. How about recursions? I've not seen VBA documentation that makes it clear that the name of a function is a "local" variable. But all versions of VBA treat it that way. The name of a function is a local variable of that function, and is initialised at every call of that function. Regarding recursion 'static' is not normally used with recursive VBA functions -- it kind of defeats the purpose in common cases.
Already repro with OOo 3.2