BUG: Private Variables in a Module Are Public (180494)



The information in this article applies to:

  • Microsoft eMbedded Visual Basic 3.0
  • Microsoft Windows CE Toolkit for Visual Basic 6.0

This article was previously published under Q180494

SYMPTOMS

When a variable is declared in a module as Private, it is seen throughout the project as if it were declared Public.

RESOLUTION

Take care when declaring form variables and module variables so that the wrong variable is not inadvertently addressed.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Windows CE project in either eMbedded Visual Basic or Visual Basic 6.0. Form1 is created by default.
  2. Add a module to the project.
  3. In the module, add the following line of code:
     
          Private myMessage
    						
  4. Add a command button to Form1.
  5. Paste the following code into Form1:
          
          Option Explicit 
          
          Private Sub Command1_Click()
              myMessage = "myMessage is set"
              MsgBox myMessage
          End Sub
    						
  6. Press F5 to run the project and note that the Click event has full access to the module's private variable. The expected behavior is to get the message "Variable not defined."
(c) Microsoft Corporation Mike Dixon, All Rights Reserved. Contributions by 1999, Microsoft Corporation.


Modification Type:MinorLast Reviewed:3/11/2005
Keywords:kbBug kbpending kbToolkit KB180494