View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
-JEFF-[_2_] -JEFF-[_2_] is offline
external usenet poster
 
Posts: 26
Default UNDERSTANDING VARIABLE SCOPE

Thanks everybody for your help. One problem I have corrected is that I was
trying to use input boxes on a userform and have now switched to text boxes
which stores the data to the myBox.text. Much easier to work with.


"-JEFF-" wrote:

I am trying to maintain variables value so when I return to a userform that
has already been used, it will already be filled out (as long as the user has
previously visited it. I thought declaring the variables as public at the
module level would make them visible in all subs but it is not working.

In module 3 I have variables declared as public. In the sub, the variables
are not declared because I want to use to publics but they seem to get over
written when they are assigned a value. ie.

MODULE 3
public v1 as string
public v2 as string

private sub MyButton_click()
v1 = "myValue"
v2 = "myValue"
end sub

The watch window shows <Out of context after values have been assigned
inside the sub.