Results 1 to 8 of 8

Thread: [RESOLVED] How to determine a winsock control is loaded?

  1. #1

    Thread Starter
    New Member gnk_on_vb's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    14

    Resolved [RESOLVED] How to determine a winsock control is loaded?

    Hi all
    I am new user of this forum and i have checked nearly all FAQ and Networking section in this forum but i am not able to get answer of one question. i am stuck at this point by this problem.

    PROBLEM :-
    I am using array of winsock and loading and unloading a winsock array element dynamically. Due to this some times I am getting error while running the program. ERROR is - "Control array element does not exists". to illuminate this error I need to know that
    "how to determine that a winsock control is loaded in the form or not. ?"
    please help me.
    i am stuck..

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: How to determine a winsock control is loaded?

    Code:
    Winsock(Index).State = 7
    That is the state of connection.

  3. #3

    Thread Starter
    New Member gnk_on_vb's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    14

    Re: How to determine a winsock control is loaded?

    To Hell-Lord
    As you suggested.
    Winsock(Index).State = 7
    is not the correct method or what i aspect to do.

    The code statement you suggested is also leads to the same error "Control array element does not exists"

    Since if the Winsocke(Index) is not loaded in the form then how you can check the state of the Winsock(Index) {It dose not matter whatever array element is i.e. Index}


    And the Winsock(Index).State = 7 Just tell us about the socket is connected to either remote host or to the client. i does not tell us about that the socket is loaded in form or not.

    What actually i am trying to do is can be simulated by following escudo code

    code:-

    If isloaded(Winsock(Index)) = True Then
    If Winsock(Index).State = 7 Then
    Winsock(Index).SendData " DATA"
    Else
    Unload Winsock(Index)
    End If
    End If

    Now can any one please tell me the answer for this that how to write function that will tell that is the particular Winsock array element is loaded in the form or not.
    If the element is loaded into the form then the function will return True else it will return False.
    Function in green color text is not exists i need to write similar kind of the function.

    Please Help.

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: How to determine a winsock control is loaded?

    You need to keep track of all the elements of your array (of winsocks) that are currently in existance. The problem arrises when you are killing items of that array in middle, you either have to condense the array (in order to have all consecutive indexs used) or maintain a list of the used indexes.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    New Member gnk_on_vb's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    14

    Re: How to determine a winsock control is loaded?

    To opus,
    Yes this can be one of the solution. but this make my code more slower. since already my code is to big this will add more complexity to my code.
    Can't we determine that witch control is loaded in the form?

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

    Re: How to determine a winsock control is loaded?

    Perhaps something like:
    Code:
    Option Explicit
    
    Private Function IsLoaded(ByVal Control As Control) As Boolean
        Dim S As String
        
        On Error Resume Next
        S = Control.Name 'Try to fetch control's name.
        IsLoaded = Err.Number = 0
    End Function
    
    Private Sub Form_Load()
        Load Label1(2)
        MsgBox IsLoaded(Label1(0))
        MsgBox IsLoaded(Label1(1))
        MsgBox IsLoaded(Label1(2))
        
        Unload Me
    End Sub

  7. #7

    Thread Starter
    New Member gnk_on_vb's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    14

    Resolved Re: How to determine a winsock control is loaded?

    Thank You Dilettante and all who helped me.
    This is working.
    This is what i want.

    Thank you very much.


    ---
    With Regards
    GNK_ON_VB

  8. #8
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [RESOLVED] How to determine a winsock control is loaded?

    Sorry gnk i misunderstood your question >.<
    My code just checked if the winsock was connected

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