Results 1 to 2 of 2

Thread: Shared Functions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Thailand
    Posts
    221

    Shared Functions

    Now I'm developing class that use to communicate with SQL Server. In class, I have used "Public Shared" for function which I need others able to call. In that function, code need to call another private procedure. At first IDE did not allow me to call private procedure unless instanciate the object. I put "Shared" keyword to that private procedure, so I can call without instanciation. The problem is what is best way to do between putting "Shared" keyword to private procedure which another public procedure call or instanciating the object before call private procedure and refer to the object to call private procedure? I have not much experience with VB.NET. Now, I'm very confuse with new features of VB.NET. Any comments and advices are welcome to post.

    Thank you,
    Teeravee Sirinapasawasdee
    Gestalt IT Consulting Group
    Growth Your Business With e-Process

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You have to decide which is the best way and to do so you should read the help files on what Shared does. Shared makes the method a non-instance method which means you don't need to create an instance of the object to use it. Shared methods are generally used for things that are some what generic and don't require state information that can't be passed in. You may also want to ask yourself why you have the method it calls as private? And does the method need to reference the current instance? This questions should help you decide whats best.

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