CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Location
    Bangalore, Karnataka, India
    Posts
    72

    Variable declaration



    Hello,


    It it true that variables declared in main form with Public statement

    should be used with its form name in other succeeding forms or is there

    any other way to call the Public variables just by name.


    What about Global statement, Please help me.


    Waiting for reply


    Thanks in advance


    Prashant.
    Prashant Joshi
    Itreya Technologies Pvt. Ltd.
    www.itreya.com

  2. #2
    Join Date
    Mar 1999
    Posts
    7

    Re: Variable declaration



    Prashant,


    Try putting your public variables in a module file. Global/Public arrays

    can also be put in a module file.


    Good Luck,

    Terry

  3. #3
    Join Date
    May 1999
    Posts
    45

    Re: Variable declaration



    I don't think you can call without formname. I think it becomes kind of property of your form (class).



  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Variable declaration



    Hi


    Since VB4, VB now treats all components as a Class - (except for Code modules).


    You can create instances of Forms and access their properties just like a class module :


    Dim mFrm As Form1


    Set mFrm = New Form1


    MsgBox mFrm.Width


    or


    With mFrm

    MsgBox .Width

    MsgBox .Height

    End With


    If you want to use a global variable - place it in a BAS module using 'Public' as the keyword. This can then be accessed from Forms/Classes/UserControls/Whatever in your project.



    Regards


    Chris Eastwood

    CodeGuru - the website for developers

    http://www.codeguru.com/vb

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