CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    23

    Public Variable help please

    Can anyone PLEASE help with what I am sure is a simple problem! I have a VB6 project where the initial form is called 'menu.frm'. In the 'General Declarations' section of this form I have the following lines :


    option Explicit
    public superpass as string




    In the 'Form Load' event of 'menu.frm' I assign a value of "test" to 'superpass'. If I reference 'superpass' within any code inside 'menu.frm' I get the correct contents (The string "test"). If I reference 'superpass' from code inside another form in the same project it is empty!! Please help - I want to be able to create a global variable at the start of my program that is available anywhere.



  2. #2
    Join Date
    Aug 1999
    Location
    Blue Springs, MO
    Posts
    43

    Re: Public Variable help please

    I believe you need a seperate module to hold the "public superpass as string" and only then does it become truly global.

    I usually make my modile named modGlobals so I know what's stored there...

    As it is now, your variable's scope is limited to your menu.frm.


  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Public Variable help please

    >If I reference 'superpass' from code inside another form [...]
    At the beginning of each form/module do you have the statement "Option Explicit"?
    If no, each time you're referring to a different thing. Correct sintax to access what is a property of the form (=a public variable in a form becomes a property of the form) is FormName.PropertyName
    ie:
    'in Form2
    dim localstring as string
    localstring = Form1.superpass

    Otherwise, you're simply creating each time a new variant variable...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Sooorry!!

    Did not remember I already saw this in another category.
    Sorry, fellow.


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured