Valhalla Legends Forums Archive | Visual Basic Programming | Username staying on list..

AuthorMessageTime
Jaquio
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..

[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[/code]

Now their username should go away.. But it's not..


Oh yea, this only happens when logged in on D2DV or D2XP.
February 27, 2006, 6:42 AM
warz
[quote]Oh yea, this only happens when logged in on D2DV or D2XP.[/quote]

That's a good clue. Remember, when you're logged on diablo 2 (and the expansion) that usernames are prepended with an '*'.
February 27, 2006, 6:53 AM
Jaquio
[quote author=warz link=topic=14381.msg147194#msg147194 date=1141023211]
[quote]Oh yea, this only happens when logged in on D2DV or D2XP.[/quote]

That's a good clue. Remember, when you're logged on diablo 2 (and the expansion) that usernames are prepended with an '*'.
[/quote]

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.
February 27, 2006, 7:09 AM
HdxBmx27
[quote author=Jaquio link=topic=14381.msg147195#msg147195 date=1141024192]
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]
*Looks at code* Where?
Also throw in a [code].lstChannel.ListItems.refresh[/code]
Usually fixes errors of information left in lists.
~-~(HDX)~-~
February 27, 2006, 7:39 AM
Stealth
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:

[code].lstChannel.ListItems.Remove .lstChannel.FindItem(Username).Index[/code]

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:
[code]' 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[/code]

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.
February 27, 2006, 7:54 AM
Jaquio
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.
February 27, 2006, 8:50 PM

Search