locked
Global Variable Problem in VB2008 RRS feed

  • Question

  • I have declared two global variables in the first of two forms of my project with the folllowing code:

    Public Shared gintColor1 as Integer

    Public Shared gintColor2 as Integer

    I declared them in the form that assigns them their values, and when I try to use the variable values in my second form, I get an error message claiming that I did not declare the variables. Am I declaring them incorrectly, or do I have another problem with my project?

    • Moved by Youen Zen Monday, January 21, 2013 2:23 AM forums restructure
    Sunday, January 20, 2013 11:18 PM

Answers

  • Dimension global variables in a module. [Project] >> [Add Class] >> Choose Module

    Module Module1
        Public G As Integer
    
    End Module


    Leon C Stanley - - A dinky di VB'er - -

    • Marked as answer by Paul Ishak Sunday, January 27, 2013 3:08 PM
    Monday, January 21, 2013 1:34 AM
  • Hi LTHS,

    In your second form, (I'm presuming your forms are Form1 and Form2), you can refer to the variable declared in Form1 by using  "newVar = Form1.gintColor1."

    Ron

    • Proposed as answer by Devon_Nullman Tuesday, January 22, 2013 3:46 AM
    • Marked as answer by Paul Ishak Sunday, January 27, 2013 3:08 PM
    Monday, January 21, 2013 4:11 AM

All replies

  • Dimension global variables in a module. [Project] >> [Add Class] >> Choose Module

    Module Module1
        Public G As Integer
    
    End Module


    Leon C Stanley - - A dinky di VB'er - -

    • Marked as answer by Paul Ishak Sunday, January 27, 2013 3:08 PM
    Monday, January 21, 2013 1:34 AM
  • Hi LTHS,

    In your second form, (I'm presuming your forms are Form1 and Form2), you can refer to the variable declared in Form1 by using  "newVar = Form1.gintColor1."

    Ron

    • Proposed as answer by Devon_Nullman Tuesday, January 22, 2013 3:46 AM
    • Marked as answer by Paul Ishak Sunday, January 27, 2013 3:08 PM
    Monday, January 21, 2013 4:11 AM