![]() |
Forum Index : Microcontroller and PC projects : Variable Scope
Author | Message | ||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
(This pertains to the CMM2 but probably applies to others too.) A quick test shows that LOCAL variables are only visible in the subroutine or function in which they are declared and not in subroutines or functions called by said sub or function. For example, in the following test1 ' call first subroutine there is no way for the second subroutine to set the value of v1 for use by the first subroutine. Instead, test2 can only alter the global v1.? " main:v1 =" v1 end sub test1 ' first subroutine local v1 test2 ' call second subroutine ? "test1:v1 =" v1 end sub sub test2 ' nested subroutine v1 = 5544 ' set a value for test1 to use - sorry, denied ? "test2:v1 =" v1 end sub I suppose that is the way of things and there is no way around this without using global variables... Visit Vegipete's *Mite Library for cool programs. |
||||
mkopack73 Senior Member ![]() Joined: 03/07/2020 Location: United StatesPosts: 261 |
Correct... If you want/need it accessible/modifyable by the 2nd level function, you have to pass it in as a parameter... |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |