Dim Public?

Posted on 2006-05-18
Last Modified: 2010-04-23
I set a variable in the top of a form Class but then in another form I can't see it. I thought that if something is public it would be seen everywhere. How can I have it seen in anther form/class?
Question by:szx248
    LVL 69

    Accepted Solution

    Hi szx248,

    It is visible if you own the instance of this other class:

    dim x as new Form1
    'Now you have access to public variables of Form1 using the variable X
    x.PublicVariable = Something

    LVL 28

    Expert Comment

    I belive you want to make it Public Shared. Then to access it in another form you do:


    where fromname is the name of the form where the variable is declared.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now