Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Global Variables

Global Variables

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Emile Jacobs
    wrote on last edited by
    #1

    How does one declare a variable that is available for any form in the project?

    X M L 3 Replies Last reply
    0
    • E Emile Jacobs

      How does one declare a variable that is available for any form in the project?

      X Offline
      X Offline
      Xiangyang Liu
      wrote on last edited by
      #2

      Emile Jacobs wrote: How does one declare a variable that is available for any form in the project? Declare a shared public variable in your class, access this variable via MyClassName.MyVariableName. Click here to see my articles and software tools

      E 1 Reply Last reply
      0
      • X Xiangyang Liu

        Emile Jacobs wrote: How does one declare a variable that is available for any form in the project? Declare a shared public variable in your class, access this variable via MyClassName.MyVariableName. Click here to see my articles and software tools

        E Offline
        E Offline
        Emile Jacobs
        wrote on last edited by
        #3

        We created a shared variable in the class, but we do not know how to declare the class in the different forms!

        X 1 Reply Last reply
        0
        • E Emile Jacobs

          We created a shared variable in the class, but we do not know how to declare the class in the different forms!

          X Offline
          X Offline
          Xiangyang Liu
          wrote on last edited by
          #4

          The class has to be in the same the project, you don't need to declare it. If the class is only visible in a different name space, then you need to access it via MyNameSpace.MyClassName.MyVariableName. If multiple threads are accessing this variable, make sure thread-safety. Click here to see my articles and software tools

          E 1 Reply Last reply
          0
          • X Xiangyang Liu

            The class has to be in the same the project, you don't need to declare it. If the class is only visible in a different name space, then you need to access it via MyNameSpace.MyClassName.MyVariableName. If multiple threads are accessing this variable, make sure thread-safety. Click here to see my articles and software tools

            E Offline
            E Offline
            Emile Jacobs
            wrote on last edited by
            #5

            Thanx for the great advice! Everything works perfectly! :laugh::laugh:

            1 Reply Last reply
            0
            • E Emile Jacobs

              How does one declare a variable that is available for any form in the project?

              M Offline
              M Offline
              Martin Cross
              wrote on last edited by
              #6

              Add a new module, such as modMain.vb and in there declare a variable as Public, i.e: Public iMyGlobalVariable as Integer This will give it a global scope.

              1 Reply Last reply
              0
              • E Emile Jacobs

                How does one declare a variable that is available for any form in the project?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                create a new class called GlobalVariables or what ever you like Then put the variables that you would like to call this is C# code I created a new Class called GlobalVariables.cs on that page the only code that I have is public class GlobalVariables { public string ReportSection = ""; public GlobalVariables() { } } just because I didnt heed it to do anything else. Now on any page that I like I can do this: create an instance of that class GlobalVariables MyVariables = new GlobalVariables(); now assign the values MyVariables.ReportSection = ""; that should do it, William O'Malley

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups