[RESOLVED] Adding a User list to chat program
Searched quite abit for some info that is pertinent to adding a User list to a chat program and coming up pretty much empty. Found a chat program that uses a list box and lists users, but wasn't able to figure out how he was doin what he was doin.
What I want to do is add a list box and then when people connect have it display their name in the list box and when they disconn remove that name from list.
So far I have the list box made and can get the user name to appear on the local machine, but not the remote machine.
What I need is a starting point to learn this, I am hoping that someone more familiar with the search terms and such used might be able to do a better search than I can and help me with that starting point. I have been following along with tutorials but can't find one that deals with this. Hope Im not asking to much, thanks for any replies.
Bry
Re: Adding a User list to chat program
'this was taken straight out of a game, but it may help u
'to remove ppl from the userlist on the servers end..if it has one.
Public Sub CloseSocket(Index As Integer)
On Error Resume Next
frmMain.wsk(Index).Close
Call UpdatePlayerList
frmMain.lstUsers.List(Index - 1) = "<Waiting>"
End Sub
------
'once this sub is called basically it sends each name from the serverlist one by one to the client.
Public Sub UpdatePlayerList()
On Error Resume Next
Dim a As Integer
Dim Msg As String
Msg = Chr$(254) & Chr$(3)
For a = 1 To MaxUsers
If User(a).Status = "Playing" And _
User(a).UserGUID <> "" Then
Msg = Msg & User(a).HomeAbv & "<" & User(a).UName & ">" & Chr$(1)
End If
Next a
For a = 1 To MaxUsers
If User(a).Status = "Playing" Then
frmMain.wsk(a).SendData Msg & Chr$(0)
DoEvents
End If
Next a
End Sub
Re: Adding a User list to chat program
'this is how the client works, in the wsk_dataarrival sub i got
Case Chr$(254) & Chr$(3)
Call UpdatePlayerList(Mid$(SplitMsg(a), 3))
'this to display on the client
Public Sub UpdatePlayerList(Msg As String)
Dim a As Integer
Dim SplitMsg() As String
SplitMsg = Split(Msg, Chr$(1))
frmMain.lstUsers.Clear
For a = 0 To UBound(SplitMsg) - 1
frmMain.lstUsers.AddItem SplitMsg(a)
Next a
End Sub
'anyway, hope it helped if not..maybe best to post in the winsock section or to check out the hundreds of examples from pscode.com/vb
Re: Adding a User list to chat program
ok here i just made a chatroom program that should help you a little to get an idea of how to make a userlist ok heres the link look at bottom replies and download the zip .
http://vbforums.com/showthread.php?t=413306
1 Attachment(s)
Re: Adding a User list to chat program
Thanks for the replies guys, not having much luck with anything so far. I'm going to attach what I have and maybe some one is bored enough to take a look at it and provide some feedback. **WARNING**It's not pretty code... ;)
Bry
Re: Adding a User list to chat program
here ill ad the userlist to your project and ill make sure it works good! :)
Re: Adding a User list to chat program
Quote:
Originally Posted by g4hsean
here ill ad the userlist to your project and ill make sure it works good! :)
You take as much time as you like Sean, I really appreciate the extra effort on your part. I think you should prob be able to follow the logic up until the part where I tried to handle the list names part.
I have very thick skin so please feel free to let me know what I need to improve on. I would rather start doing it the right way as opposed to pickin up bad programming habits and then trying to relearn the "right" way to code. Most the code isn't mine, it was copied from different tutorials and source code I have found on the net and then tweaked to work for me. Thnx again fer the time yer spending on this, looking forward to finding out how to do the list name thingy. :wave:
1 Attachment(s)
Re: Adding a User list to chat program
I've added a fully functional user list that updates and lists all users connected.
you may need to fix some connection things but i only added and didn't take things out. Hope you like the help.
P.S Please rate my for i have never been rated for my help. :P
Re: Adding a User list to chat program
On by the way nice coding you code like a pro! I like the neatness of the code and the utilisation of all the functions used. A++ on the code.
Re: Adding a User list to chat program