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. accessing variables

accessing variables

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdata-structures
4 Posts 2 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.
  • N Offline
    N Offline
    Nadroj
    wrote on last edited by
    #1

    simple question.. using vb.net for a small vb windows app: where is the best place to declare an object variable? i have a custom structure which i have delcared a variable array with.. each method in the program must be able to access this variable (its a simple 1 form, module, class program) thanx in advance. EDIT: i am currently using a module level variable ------------------ Jordan. III

    D 1 Reply Last reply
    0
    • N Nadroj

      simple question.. using vb.net for a small vb windows app: where is the best place to declare an object variable? i have a custom structure which i have delcared a variable array with.. each method in the program must be able to access this variable (its a simple 1 form, module, class program) thanx in advance. EDIT: i am currently using a module level variable ------------------ Jordan. III

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      If your variable is going to be accessed by many of the methods in your class, make it a global variable by putting it just after your class statement.

      Public Class myForm
      Inherits System.Windows.Forms.Form
       
      ' Global Variables go here
      Private myGlobal as Integer
       
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      .
      .
      .

      RageInTheMachine9532

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        If your variable is going to be accessed by many of the methods in your class, make it a global variable by putting it just after your class statement.

        Public Class myForm
        Inherits System.Windows.Forms.Form
         
        ' Global Variables go here
        Private myGlobal as Integer
         
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        .
        .
        .

        RageInTheMachine9532

        N Offline
        N Offline
        Nadroj
        wrote on last edited by
        #3

        ok thats how i am doing it. i was just wondering if this was the most efficient way of attacking this. also, i used 'dim' rather than 'private', in classes they are the same thing, no? are they always the same thing? thanks Dave ------------------------ Jordan. III

        D 1 Reply Last reply
        0
        • N Nadroj

          ok thats how i am doing it. i was just wondering if this was the most efficient way of attacking this. also, i used 'dim' rather than 'private', in classes they are the same thing, no? are they always the same thing? thanks Dave ------------------------ Jordan. III

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          They do the same thing, such that Dim is actually optional. But, the variable visibility changes depending on wether it is declared with Public, Private, Friend, Protected, Protected Friend, Static, Shared, ... Look up 'Dim' in the Visual Studio help for the explanation as to what all of these do, with examples. RageInTheMachine9532

          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