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 a variable on another form

Accessing a variable on another form

Scheduled Pinned Locked Moved Visual Basic
6 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.
  • D Offline
    D Offline
    Drew
    wrote on last edited by
    #1

    I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!

    P C 2 Replies Last reply
    0
    • D Drew

      I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!

      P Offline
      P Offline
      penguin5000
      wrote on last edited by
      #2

      The easiest method is to declare the variable on frmMainTools as public.

      D P 2 Replies Last reply
      0
      • D Drew

        I have a variable on another form that I need to read and write to. I know it'll be obvious once someone tells me... Just for the record, the form with the variable I'm trying to access is frmMainTools and the one I'm trying to access from is frmMain. A timely answer would be most helpful. Thanks! --------------------------------------- If it ain't broke, you're not tryin'!

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        The best way to do this is to set up a delegate between the forms that fires the value across when it is changed. This is far cleaner than making variables public.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        • P penguin5000

          The easiest method is to declare the variable on frmMainTools as public.

          D Offline
          D Offline
          Drew
          wrote on last edited by
          #4

          Dim mCurrentForm As Form How would one make that public when it is already declared as a Form?

          D 1 Reply Last reply
          0
          • P penguin5000

            The easiest method is to declare the variable on frmMainTools as public.

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Maybe the easiest, but not the best in terms of OOP. Globals are not good :)

            "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            1 Reply Last reply
            0
            • D Drew

              Dim mCurrentForm As Form How would one make that public when it is already declared as a Form?

              D Offline
              D Offline
              Drew
              wrote on last edited by
              #6

              Looks like I got it figured. Thanks for the help and speedy responses. The fact that this is going to be an app for just this company and it's a rather small app causes me to not worry about messy code. It doesn't need to work fast and besides that, it's only a database front-end, so I'm not going to be too worried if it breaks. Thanks again! -------------------------------- If it ain't broke, break it!

              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