[RESOLVED] How to determine a winsock control is loaded?
:wave: 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 :-
:ehh: 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..
Re: How to determine a winsock control is loaded?
Code:
Winsock(Index).State = 7
That is the state of connection.
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.
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.
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?
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
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.
:thumb: Thank you very much.
---
With Regards
GNK_ON_VB
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 :p