Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Form Instances

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Austin, TX
    Posts
    120

    Resolved [RESOLVED] [2005] Form Instances

    Hi,
    Coming from VB6 and eVb, I wrote a program without creating a new instance of each form before I used them (I simply used form1.show). But in realizing the utility of creating instances of forms first, I am changing my program now to do that (ie. dim f_form1 as new form1... f_form1.show).

    My question is: When I am manipulating controls, assigning values, etc., when do I use the class name (form1) and when do I use the instance name (f_form1)??? It seems that I can do either, but I'm sure there is a "correct" way to do it, and any advice will be greatly appreicated!

    My assumption is that if I set
    Code:
    form1.label1.text = "a"
    then this will change label1.text for all instances of this form...

    and if I set
    Code:
    f_form1.label1.text = "a"
    it will only change label1.text for that particular instance.

    Am on the right track here?

    Thank you,
    Corey

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Form Instances

    Using the class name will actually return the default instance, so if you use the class name once you must use it every time. If you need more than one instance of a particular form then you shouldn't use the default instance at all. I wouldn't recommend using the default instance at all anyway. It's a feature that's been added to make VB.NET easier for beginners who don't understand OOP concepts properly. If you do understand OOP then just stick to it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Location
    Austin, TX
    Posts
    120

    Re: [2005] Form Instances

    Thanks for the info. That is what I am doing is changing my code to eliminate all usage of default instances. So what you are saying is that I should ALWAYS use the instance name no matter what? And if I use the class name, VS just creates an instance automatically? (and thus I should never use the class name).

    As always, thank you for your help!!

    -Corey

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