CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Guest

    Public Variables

    I am cerating a PUBLIC variable as follows:

    public abc as string

    I populate that variable in Form1 and try to access it in a Form2 procedure, but it does not appear to contain any data in Form2....





  2. #2
    Join Date
    Dec 1999
    Location
    Israel
    Posts
    101

    Re: Public Variables

    It is preferrable to define all the public variables, subroutines and functions in the Module level, but it
    doesn't mean that you did something wrong. Check all the subs/functions of Form1 and Form2.
    Maybe, somewhere, by mistake, you define the same variable as Private. That's why your public
    variable didn't receive the desired value. The another reason could be that you loading Form2 before
    giving any value to this variable. If you check everything and still have the same problem, you may
    e-mail me your project and I'll try to help you.

    Good Luck!


  3. #3
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: Public Variables

    May be because you do not refering the form.
    You have declared abc in form1 as public.

    To refer it in form2

    use


    form1.abc = something






    Santulan

  4. #4
    Guest

    Re: Public Variables

    In Form2 I am referring to it as frmForm1.text=abc


  5. #5
    Join Date
    Dec 1999
    Location
    Tel Aviv, Israel, Earth, Solar System
    Posts
    50

    Re: Public Variables

    Then you could try Form1.Text=Form1.Abc from Form2 if both Text and Abc are public (BTW, it's highly recommended not to use reserved words as user defined variables - I mean Text). If I understood you right it must help if not. . . I tried. Good luck.

    Jean Spector
    Tech Support Team Leader, CET
    [email protected]
    (in VB from 11/1999)

  6. #6
    Guest

    Re: Public Variables

    hi
    see pal!! u gotta add a module to ur existing project ,right click on the project explorer where form is there then u will find a option add,go and add the option MODULE not anyother.. then declare that varibale in that module
    it will be globally accepted wherever u populate it


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