BUG: Private Variables in a Module Are Public

ID: Q180494


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 6.0
  • Microsoft Windows CE Toolkit for Visual Basic 5.0


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 (HPC) Project in Visual Basic. 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 the following code to the General Declarations section of Form1:
          
          Option Explicit 


  5. Place a CommandButton on the form and add the following code to its Click event:
          
          Private Sub Command1_Click()
              myMessage = "myMessage is set"
              MsgBox myMessage
          End SuB 


  6. Press the F5 key 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.

Additional query words: wince vbce vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600bug kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: October 18, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.