I am having a problem with the behaviour of global variables and I am hoping someone can help me.
Without dumping lots of code, the structure is as in the image with a description of the behaviour I am seeing after that.
The function of the code is to display a bunch of data and wait while the user decides what actions to take to change how it is displayed or to edit the data in different ways by using the command buttons.
1) sub_in_main_ONE: Sets the values of the public variables and dynamically creates the command buttons
2) When button 1 is clicked: VARIABLE1 is accessible and has the correct value in the click module. It also is accessible and has the correct value in sub_in_main_TWO. Based on everything I have read about variable scope, this is what I expected and designed for.
2) When button 2 is clicked:VARIABLE2 is NOT accessible in the click module. It is also NOT accessible in sub_in_main_THREE. This is not what I was expecting AND it is inconsistent with behaviour for BUTTON 1.
4) When sub_in_main_THREE is called from sub_in_main_ONE: VARIABLE 2 is accessible and has the correct value. This is what I expect from my understanding of variable scope.
I don't understand what I am doing wrong for BUTTON 2 because everything is fine for BUTTON 1 and it seems be just the same. Am I declaring the global variables in the wrong place or in the wrong way?
I did not expect to find that access to public variables within sub_in_main_THREE would depend on where it was called from.
Can someone guide me on why I see the problem I am encountering and how to fix it
Thanks in advance.
Geoff
Without dumping lots of code, the structure is as in the image with a description of the behaviour I am seeing after that.
The function of the code is to display a bunch of data and wait while the user decides what actions to take to change how it is displayed or to edit the data in different ways by using the command buttons.
1) sub_in_main_ONE: Sets the values of the public variables and dynamically creates the command buttons
2) When button 1 is clicked: VARIABLE1 is accessible and has the correct value in the click module. It also is accessible and has the correct value in sub_in_main_TWO. Based on everything I have read about variable scope, this is what I expected and designed for.
2) When button 2 is clicked:VARIABLE2 is NOT accessible in the click module. It is also NOT accessible in sub_in_main_THREE. This is not what I was expecting AND it is inconsistent with behaviour for BUTTON 1.
4) When sub_in_main_THREE is called from sub_in_main_ONE: VARIABLE 2 is accessible and has the correct value. This is what I expect from my understanding of variable scope.
I don't understand what I am doing wrong for BUTTON 2 because everything is fine for BUTTON 1 and it seems be just the same. Am I declaring the global variables in the wrong place or in the wrong way?
I did not expect to find that access to public variables within sub_in_main_THREE would depend on where it was called from.
Can someone guide me on why I see the problem I am encountering and how to fix it
Thanks in advance.
Geoff