Grr, I recently noticed that my bot when people leave the channel. Their Username sometimes stays on the list even though their not there.. Anyidea why exactly? Here is the Leave code..
Private Sub JaqBot_OnLeave(ByVal Username As String, ByVal Flags As Long)
'Debug.Print vbCrLf
'Debug.Print "------JaqBot_OnLeave------"
'Debug.Print "Username:" & Username
'Debug.Print "Flags:" & Flags
'Debug.Print "---------------------------"
On Error Resume Next
With frmMain
.lstChannel.ListItems.Remove .lstChannel.FindItem(Username).Index
.lblChannelInfo.Caption = BNET.CurrentChan & " (" & .lstChannel.ListItems.Count & ")"
.Caption = BotName & " v" & VerNum & " - Connected as " & BNET.Username & " in channel " & BNET.CurrentChan
End With
AddChat vbLtGreen, Username & " has left the channel."
End Sub
Now their username should go away.. But it's not..
Oh yea, this only happens when logged in on D2DV or D2XP.
QuoteOh yea, this only happens when logged in on D2DV or D2XP.
That's a good clue. Remember, when you're logged on diablo 2 (and the expansion) that usernames are prepended with an '*'.
Quote from: warz on February 27, 2006, 12:53 AM
QuoteOh yea, this only happens when logged in on D2DV or D2XP.
That's a good clue. Remember, when you're logged on diablo 2 (and the expansion) that usernames are prepended with an '*'.
Yes I know, I have the remove all the '*' from the usernames when they enter the channel. When they leave, I have the bot replace the '*' before the usersname.
Quote from: Jaquio on February 27, 2006, 01:09 AM
Yes I know, I have the remove all the '*' from the usernames when they enter the channel. When they leave, I have the bot replace the '*' before the usersname.
*Looks at code* Where?
Also throw in a
.lstChannel.ListItems.refresh
Usually fixes errors of information left in lists.
~-~(HDX)~-~
1. Take "On Error Resume Next" out of your code. It's not helping, because if the event fires with an incorrect username that isn't actually on the list, then this line of code:
.lstChannel.ListItems.Remove .lstChannel.FindItem(Username).Index
will throw a runtime error, probably 91. On Error Resume Next will summarily IGNORE that error and you'll never know it happened, then you notice people aren't being properly removed from the userlist.
2. Replace that silly error ignorer in your code with real error handling, something like this:
' Pseudocode
Dim x as ListItem
Set x = .lstChannel.FindItem(Username) ' Set is required because this is an object
If Not (X Is Nothing) Then ' The object exists! We can remove the user from the list.
.lstChannel.ListItems.Remove x.Index
.lblChannelInfo.Caption = BNET.CurrentChan & " (" & .lstChannel.ListItems.Count & ")"
.Caption = BotName & " v" & VerNum & " - Connected as " & BNET.Username & " in channel " & BNET.CurrentChan
AddChat vbLtGreen, Username & " has left the channel."
Else
Debug.Print "Warning: _OnLeave() tried to remove user " & Username & " and they weren't in the ListView!"
End If
That way, you will avoid runtime error 91, and be informed (only when running in the debugger) when the code tries to remove invalid users. You can see why the username was invalid [perhaps you aren't processing out a star, or you're not getting the username into the event properly so it has extra formatting or something] and fix the problem.
Alright thanks for the help, I haven't seen a user still be in channel after they have left. Stealth you have been credited in my source code whenever I realease it. Just so you know, lol.