i have 3 chat clients open and connected but on 1 of them when i disconnect & connect again i get this error
run-time error '360':
object already loaded
:(please tell me how to fix this:(
run-time error '360':
object already loaded
Code:
Private Function GetAvailableSocketIndex() As Integer
Dim AvailIndex As Integer
Dim SocketElement As Variant
AvailIndex = 0
' First check for available sockets
For Each SocketElement In AcceptedSocket
If AcceptedSocket(SocketElement.Index).State = sckClosed Then
If SocketElement.Index <> 0 Then AvailIndex = SocketElement.Index
End If
Next SocketElement
' Next, if AvailIndex is 0 at this point, then we either don't have a created
' winsock that is closed, or we only have the original winsock, which we don't
' want to use. Therefore, we need to create a winsock and pass out it's index.
If AvailIndex = 0 Then
AvailIndex = AcceptedSocket.Count
Load AcceptedSocket(AvailIndex) <<< debug gets me here
End If
GetAvailableSocketIndex = AvailIndex
End Function
Code:
Private Sub ListenSocket_ConnectionRequest(ByVal requestID As Long)
' Create a user to add to the collection
Dim NewSocketIndex As Integer
Dim NewUser As New User
' Find the first available socket index, and load a new
' socket into it
NewSocketIndex = GetAvailableSocketIndex
' Use the new socket to accept the incoming connection
AcceptedSocket(NewSocketIndex).accept requestID
' Set the user's socket index value to the one we just
' created, so it can reference it from inside the user
' instance
NewUser.SocketIndex = NewSocketIndex
' Add the user to the collection with the socket
' index as the key to the user
Users.Add NewUser, Str(NewSocketIndex)
UpdateConnUsersList
' Send the init message to the newbie
SendInitMessage NewSocketIndex
' Send the ChatRoom list to the newbie
UpdateChatRoomListSingle NewSocketIndex
End Sub
Code:
Public Sub AcceptedSocket_Close(Index As Integer)
'What to do when a client disconnects
Dim ChatRoomName As String
Dim WelcomeMessage As String
Dim strValue() As String
'Go ahead and close the socket, if not done already
'Not sure if this is necessary, but what the hay.
'Get the appropriate user's chat room
ChatRoomName = Users(Str(Index)).ChatRoom
AdjustUserCount ChatRoomName, vbNullString, True
'Destroy the invalid user!
Users.Remove Str(Index)
AcceptedSocket(Index).Close
Dim strAdminMsg As String
Dim strSend As String
Dim UserElement As User
strAdminMsg = Text4.Text & "Left The Room" & Text5.Text
strSend = "#" & INCOMING_MESSAGE & COMMAND_SEPARATOR & lstAllUsers.List(i) & _
VALUE_SEPARATOR & strAdminMsg
If Not strSend = "" Then
For Each UserElement In Users
NotifyUserMessageSingle UserElement.SocketIndex, strSend
Next UserElement
End If
'Get rid of the Winsock OCX instance
If Not Index = 0 Then Unload AcceptedSocket(Index)
'Tell everyone in the defunct user's chat room (subtly)
'that they have been downsized
NotifyUpdateUserList ChatRoomName
'Update our own list of connected users.
UpdateConnUsersList
End Sub
:(please tell me how to fix this:(