Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: AC_Drkan on July 12, 2004, 03:39 PM

Title: Removing a User from a listview
Post by: AC_Drkan on July 12, 2004, 03:39 PM
Help?

Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")
On Error Resume Next
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i) = Username Then
ListView1.ListItems.Remove i
End If
Next i
AddChat rtbChat, Username & " has left the channel.1", vbGreen, vbNewLine

End Sub


Dosen't Generate an error nut it instead add another user with the same name instead of deleting it.
Title: Re:Removing a User from a listview
Post by: AC_Drkan on July 12, 2004, 03:57 PM
Nvm i think i fixed this

Taken from ETH bot
Private Sub Event_Leave(strUser As String, StrFlag)
On Error Resume Next
   Dim strCount As String
   
   strCount = frmMain.RoomList.ListItems.count
   If Err.Number = 0 Then
   frmMain.RoomList.ListItems.Remove frmMain.RoomList.FindItem(strUser).Index
   End If
 
   addText strUser & " has left the channel" & vbNewLine, ID_COLOR_INFO
   frmMain.text1.text = msChannelName & " (" & frmMain.RoomList.ListItems.count & ")"
   
End Sub
Title: Re:Removing a User from a listview
Post by: AC_Drkan on August 02, 2004, 11:02 PM
Quote from: AC_Drkan on July 12, 2004, 03:57 PM
Nvm i think i fixed this

Taken from ETH bot
Private Sub Event_Leave(strUser As String, StrFlag)
On Error Resume Next
   Dim strCount As String
   
   strCount = frmMain.RoomList.ListItems.count
   If Err.Number = 0 Then
   frmMain.RoomList.ListItems.Remove frmMain.RoomList.FindItem(strUser).Index
   End If
 
   addText strUser & " has left the channel" & vbNewLine, ID_COLOR_INFO
   frmMain.text1.text = msChannelName & " (" & frmMain.RoomList.ListItems.count & ")"
   
End Sub


nvm the nvm im lost
Title: Re:Removing a User from a listview
Post by: l)ragon on August 03, 2004, 07:36 AM
look >>here (http://forum.valhallalegends.com/phpbbs/index.php?board=31;action=display;threadid=7743)<<
Title: Re:Removing a User from a listview
Post by: ChR0NiC on August 06, 2004, 02:39 PM
Well you could use a loop like this.


Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")

For i = 1 To ListView1.ListItems.Count
If LCase(ListView1.ListItems(i)) = LCase(Username) Then
ListView1.ListItems.Remove(i)
GoTo ShowMessage
End If
Next i

ShowMessage: 'Jump to this to save time from checking the other users.
AddChat rtbChat, Username & " has left the channel.1", vbGreen, vbNewLine

End Sub


Also your On Error Resume Next might be jumping through an error you are receiving, try removing that and debugging the error.

One other thing, is it adding the users with a * on the listview? Because if it is, your loop won't find a match.
Title: Re:Removing a User from a listview
Post by: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index
Title: Re:Removing a User from a listview
Post by: BaDDBLooD on August 08, 2004, 10:52 PM
Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Took the words right out of my mouth!
Title: Re:Removing a User from a listview
Post by: Adron on August 09, 2004, 05:14 AM
Quote from: BaDDBLooD on August 08, 2004, 10:52 PM
Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Took the words right out of my mouth!

Don't make useless replies - if someone has already given the answer and it's not being disputed by someone else, there's no need to tell everyone that you agree about the answer. If we all did, these topics would all be a dozen pages long in no time, and we don't want that.
Title: Re:Removing a User from a listview
Post by: Grok on August 09, 2004, 06:27 AM
Quote from: Eli_1 on August 08, 2004, 08:26 PM
If it's truly a listview, and not a listbox, you should be able to just simply do:


listview1.ListItems.Remove listview1.FindItem(Username).index


Remember to handle the VB error that will occur if FindItem does not find the name in the ListView and you pass that Index (of a Null object) to the Remove method of ListItems.  In this particular application you are never expecting it, since you will only be removing from the ListView those items which you have added, but half the point of error handlers is for the unexpected, keeping your program from crashing ungracefully.
Title: Re:Removing a User from a listview
Post by: AC_Drkan on August 19, 2004, 09:45 PM
ThY ALL!!!!
fixed the removing and adding, look:

Private Sub CleanSlateBot1_UserLeaves(ByVal Username As String, ByVal Flags As Long, SimulatedEvent As Boolean)
Username = Replace(Username, "*", "")
'Code For Removing a User From a List View Goes Here
   Username = Replace(Username, "*", vbNullString)
   On Error Resume Next
   lvChannel.ListItems.Remove lvChannel.FindItem(Username).Index
   lblChannel.Caption = Channel & " (" & lvChannel.ListItems.Count & ")"

   If mnuToggleJLMessages.Checked = True Then
       AddChat rtbChat, Username & " has left the channel.", vbGreen, vbNewLine
   End If
End Sub
Title: Re:Removing a User from a listview
Post by: ChR0NiC on August 20, 2004, 12:44 PM
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control (http://turbonet.feeblegaming.org/blc/), because it can logon W3 and has a few extra features, check it out :)
Title: Re:Removing a User from a listview
Post by: Eli_1 on August 20, 2004, 01:33 PM
Quote from: ChR0NiC on August 20, 2004, 12:44 PM
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control (http://turbonet.feeblegaming.org/blc/), because it can logon W3 and has a few extra features, check it out :)

IIRC, CSB can log on W3 just fine.
By the way Drkan, On Error Resume Next is a very poor way of "handling" errors.
Title: Re:Removing a User from a listview
Post by: ChR0NiC on August 20, 2004, 04:12 PM
Quote from: Eli_1 on August 20, 2004, 01:33 PM
IIRC, CSB can log on W3 just fine.

It doesn't work correctly anymore, it gets a run time error subscript out of range error when logging on W3, which means it needs to be updated. So you are incorrect Eli >:(
Title: Re:Removing a User from a listview
Post by: AC_Drkan on September 17, 2004, 05:26 AM
Quote from: Eli_1 on August 20, 2004, 01:33 PM
Quote from: ChR0NiC on August 20, 2004, 12:44 PM
Might want to do
lvChannel.ListItems.Refresh after the removal because sometimes things look a little tacky and bits and pieces of icons get stuck, also I notice you are using CSB, and I recommend you actually use my BNLS Logon Control (http://turbonet.feeblegaming.org/blc/), because it can logon W3 and has a few extra features, check it out :)

:'(
i know but thats so much easier

IIRC, CSB can log on W3 just fine.
By the way Drkan, On Error Resume Next is a very poor way of "handling" errors.