Re: How do I go about this?
Create a winsock object on your main form, name it as WinSock, and set its Index property to 0. Create a commandbutton also, name it Command1.. it doesnt count, it just for demonstrating the class object termination.
now, simply include the following.
Code:
Option Explicit
Private cHTTP() As clsHTTP
Private lInstanceIndex As Long
Private Sub Command1_Click()
Call TerminateHTTPInstance(lInstanceIndex)
End Sub
Private Sub Form_Load()
ReDim cHTTP(0)
lInstanceIndex = CreateNewHTTPInstance
End Sub
Private Sub TerminateHTTPInstance(lIndex As Long)
With cHTTP(lIndex)
'execute the closing sequnce here, for example...
End With
Set cHTTP(lIndex) = Nothing
End Sub
Private Function CreateNewHTTPInstance() As Long
Dim lIndex As Long
lIndex = UBound(cHTTP) + 1
CreateNewHTTPInstance = lIndex
ReDim Preserve cHTTP(lIndex)
Set cHTTP(lIndex) = New clsHTTP
With cHTTP(lIndex)
.SetParent Me, lIndex
'Now you can configure and execute things from this point ....
End With
End Function
The class object (clsHTTP) should look alike this.
Code:
Option Explicit
Private fParentForm As Form, lMyIndex As Long
Public Sub SetParent(ByRef ParentFrm As Form, ByVal lClassIndex As Long)
Randomize Timer
Set fParentForm = ParentFrm
lMyIndex = lClassIndex
Load fParentForm.Winsock(lMyIndex)
End Sub
Private Sub Class_Terminate()
Unload fParentForm.Winsock(lMyIndex)
Debug.Print "WinSock object removed."
End Sub
Now, you can see, that you can easily create a new instance of clsHTTP, by using the CreateNewHTTPInstance. The return value of CreateNewHTTPInstance will be the control array index that you have to store, for later usage. The class creates a new instance of WinSock on your mainform, when calling the SetParent Method.
You have to extend the class clsHTTP to, with your methods from your module. Dont forget to replace the callings, to point the appropirate winsock object!
An example:
Code:
Sub GetData()
Dim strIncomming As String
If fParentForm.Winsock(lMyIndex).State = 7 Then
fParentForm.Winsock(lMyIndex).GetData strIncomming
strSource = strSource & strIncomming
End If
End Sub
If you dont need this class anymore, just simply call the TerminateHTTPInstance, and provide its index.