Results 1 to 3 of 3

Thread: shared problem (user control)[2005]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    81

    shared problem (user control)[2005]

    hi all. i used key word shared in my control for declaire some variable. when i used this control in form. if i only create a control, it does not matter. But if i create 2 controls(the same form), all of field that i used variable shared, will be same. i mean duplicate data in field. can i avoid this problem?
    many thank for your help

  2. #2

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

    Re: shared problem (user control)[2005]

    A lot of people seem to think that the Shared key word is just a convenience to allow you to access a member without referencing a specific instance. It's not. A Shared member is a member of the class, not an object of that type. There is only ever one class, no matter how many instances you create, so there's only ever one value for a Shared field or property. Do NOT use Shared fields or properties as a convenience. That's a hack. ONLY declare a member Shared if it logically IS a member of the class. If it's not, as yours obviously is not, then don't declare it Shared. Declare it as a regular instance member and access it via a reference to the appropriate instance.
    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

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