Results 1 to 6 of 6

Thread: [RESOLVED] Implements question.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,674

    Resolved [RESOLVED] Implements question.

    Using my SimpleServer class, the socket instances are hard coded in the "Declarations" section of the calling program using the "Implements" function.
    Code:
    Const Max_Connect As Long = 5
    Implements SimpleServer
    Private mServer(0 To Max_Connect) As New SimpleServer
    I would like to allow the user to configure the Maximum Connections without having to recompile. Is this possible? VB help isn't much use, as it says "The Implements statement can't appear in a standard module".

    J.A. Coutts

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: Implements question.

    Why the constant must to be 5 and not other values, like 10?

    The Const Max_Connect and mServer() declarations are not part of the Implements, so they can be clanged to:

    Code:
    Private Max_Connect As Long
    Private Const Max_Connect_Default as Long = 5
    Implements SimpleServer
    Private mServer() As New SimpleServer
    
    Private Sub Form_Load() ' Or Class_Initialize()
        MaxConnect = Max_Connect_Default
    End Sub
    
    Pulic Property Let MaxConnect(nValue as Long)
        If nValue <> Max_Connect Then
            Max_Connect = nValue
            ' Code to finish running objects
            Redim Preserve mServer(Max_Connect)
            ' Code to create new objects
        End If
    End Property
    But perhaps I'm not understanding what you are asking.

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Implements question.

    "Implements" statements declare that this module (which must be an object module such as Class, Form, UserControl, etc.) implements a secondary interface. Static "standard" modules cannot implement any interfaces because they are not object definitions.

    What make you think you want to use Implements here?

    But I admit I am also clueless. Why not just have a MaxConnections property?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,674

    Re: Implements question.

    I don't fully understand how or why it works, but the help of Bonnie West I was able to create multiple instances of a class while supporting Events (see following thread). WithEvents doesn't work with Object Arrays.

    http://www.vbforums.com/showthread.p...B6-Simple-Sock

    To do this, I am assuming that the instances have to be declared in the Declarations section in order to create the Events for each instance. 5 is an arbitrary number that I used for development (1 listening socket and 5 connection sockets), but what I would like to do is allow the user to declare as many sockets as he/she requires. I will play around with Eduardo-'s suggestion a little.

    J.A. Coutts

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,674

    Re: Implements question.

    Eduardo-'s suggestion does seem to work. I have adjusted the sample code in post #2 in the above link to allow the user to input the maximum connections.

    J.A. Coutts

  6. #6
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: Implements question.

    Hello couttsj,

    I made a sample project with a suggestion in the case you want to change the interface from using Implements to using WithEvents in your SimpleServer class.

    In the first sample the user must supply an additional parameter "key" when creating a new socket, that key is used to identify the instance.
    I don't know if it would be better to automatically generate the keys, so there is a second sample that does that.

    It has a cSimpleEvents class object instance that both objects, SimpleServer and each instance of SimpleSock have to send the events from one to another.
    It is a way to have WintEvents in collections.
    Attached Files Attached Files
    Last edited by Eduardo-; May 7th, 2017 at 11:02 PM.

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