life cycle about the return variable of function in Star Basic in Calc

View: New views
2 Messages — Rating Filter:   Alert me  

life cycle about the return variable of function in Star Basic in Calc

by SlumberMan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
As is known to everyone, in a Star Basic function, the variable of
default return value share the name of the function. For instance, I
tried these:

New calc doc ==> Tools --> Macros --> Organize Macros --> OOo-dev Basic...
Create a module under "My macros -> Standard" and add a function in it.

   function reverse(str)
      for i = len(str) to 1 step -1
         *reverse*=reverse & mid(str, i, 1)
      next i
   end function

clearly, this function is to convert the sequence of a string.
Originally, I thought the variable "reverse" was a local variable. But
acctually, it was global.
Because after I used this function for several times, I noticed that the
result became the catenate of all the strings.

In my thought, the return value of function should be a local variable
rather than a global one. Any suggestions? TIA.

--
===========================================
Yuelin Zhuang   --   Testing 3, RedFlag2000
MSN :                 doze_worm@...
E-mail:          zhuangyuelin@...
===========================================


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...


Re: life cycle about the return variable of function in Star Basic in Calc

by SlumberMan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

SlumberMan wrote:

> Hi all,
> As is known to everyone, in a Star Basic function, the variable of
> default return value share the name of the function. For instance, I
> tried these:
>
> New calc doc ==> Tools --> Macros --> Organize Macros --> OOo-dev
> Basic...
> Create a module under "My macros -> Standard" and add a function in it.
>
>   function reverse(str)
>      for i = len(str) to 1 step -1
>         reverse=reverse & mid(str, i, 1)
>      next i
>   end function
>
> clearly, this function is to convert the sequence of a string.
> Originally, I thought the variable "reverse" was a local variable. But
> acctually, it was global.
> Because after I used this function for several times, I noticed that
> the result became the catenate of all the strings.
>
> In my thought, the return value of function should be a local variable
> rather than a global one. Any suggestions? TIA.
Here is an example of using the function above

               A                              B
1   abcdef                    =reverse(A1)        --->        fedcba
2               12345         =reverse(A2)        --->        fecdba54321
3   =reverse(B2)   --->   fedcba5432112345abcdef

--
===========================================
Yuelin Zhuang   --   Testing 3, RedFlag2000
MSN :                 doze_worm@...
E-mail:          zhuangyuelin@...
===========================================


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...