Results 1 to 18 of 18

Thread: [RESOLVED] recive message

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Resolved [RESOLVED] recive message

    I have a program and it recives messages from more than one person. How would I make it so each message pops up in a new form and like messages from the same user go in the same window.

    Here is some code for the message reciveing
    VB Code:
    1. Private Sub Message(strName As String, strMsg As String)
    2. Dim frm As Form
    3. Dim blnExist As Boolean
    4.  
    5. For Each frm In Forms
    6.     If UCase(frm.Caption) = UCase(strName) Then
    7.         blnExist = True
    8.         Exit For
    9.     End If
    10. Next frm
    11.  
    12. If blnExist = False Then
    13. Dim newfrm As New Form2
    14. newfrm.Caption = strName
    15. newfrm.Tag = strName
    16. newfrm.Text1.Text = newfrm.Text1.Text & strName & " - " & strMsg & vbNewLine
    17. newfrm.Show (vbNormal)
    18. End If
    19.  
    20. If blnExist = True Then
    21. If newfrm.Tag = strName Then
    22. newfrm.Text1.Text = newfrm.Text1.Text & strName & " - " & strMsg & vbNewLine
    23. End If
    24. End If
    25.  
    26. End Sub

    That makes it so the new messages show in a new window and everything but only the first message works. Ill try to explain it better if that doesnt make sense.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    That loop to search for a loaded form that I gave you in your other thread doesn't really make any sense in this context. Can you explain what is that you need to do and as clear as possible.

    BTW, you should've just continue in that thread instead ...

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    I was going to continue their but i didnt kno wheter or not to cause the question was answered and yeah.

    So ill get on with explaining. I have a form where the message is recived and when a new message comes in i want it to be in a new window and i figured i could use

    Dim newfrm As New Form2
    newfrm.Show (vbNormal)

    to open each new message but i need the incoming mesages to go into the form that they belong.

    So say person1 sends me a message it should open up a new form2 with the message in it and then if person1 sends another message it should go into the same form. Then if person2 sends a message it should do the same thing into its own form. So how would I do that? and i think if thats not clear i can try to explain a little more again

  4. #4

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    I have all that stuff done and I can make it put all the messages in a listbox or a text box. Its doing it through winsock. Its basically a client server thing. But I need to make it so that the incoming messages are in new windows and so that they have all the messages coming from that person in the same window.

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    So why don't you simply use ONE form to display ANY of you new messages:
    VB Code:
    1. Private Sub DisplayMessage(strMsg As String)
    2. Dim frm As frmMsg
    3.  
    4.     Set frm = New frmMsg
    5.     frm.lbMessage.Caption = strMsg
    6.     frm.Show vbModal
    7.  
    8. End Sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    Because that gets confusing if your getting messages from 5 people in the same window.

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    That WON'T be exactly the same window - for each message a brand NEW instance will be created.
    Also, (if that is really important) you may pass person't name to that procedure and display it in say form's caption so you know who sent it:
    VB Code:
    1. Private Sub DisplayMessage(strMsg As String, strUser As String)
    2. Dim frm As frmMsg
    3.  
    4.     Set frm = New frmMsg
    5.     frm.lbMessage.Caption = strMsg
    6.     frm.Caption = "Message Received From " & strUser
    7.     frm.Show vbModal
    8.  
    9. End Sub

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    Oooo yeah but is their anyway to put the messages from the same user in the same form?

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    In that case search might come handy:
    VB Code:
    1. Private Sub DisplayMessage(strMsg As String, strUser As String)
    2. Dim frm As Form
    3. Dim blnExist As Boolean
    4.  
    5.     For Each frm In Forms
    6.         If UCase(frm.Tag) = UCase(strUser) Then
    7.             blnExist = True
    8.             Exit For
    9.         End If
    10.     Next frm
    11.    
    12.     If Not blnExist Then
    13.         Set frm = New frmMsg
    14.         frm.Caption = "Message Received From " & strUser
    15.         frm.Tag = strUser
    16.     End If
    17.    
    18.     frm.lstMsg.AddItem strMsg
    19.     frm.Show
    20.     frm.ZOrder
    21.  
    22. End Sub

    EDIT: I modified code a little (it wasn't tested) so give it a try and let me know if it works for you this time arround.
    NOTE: also, I used Listbox instead of label so you can identify new message more easily.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    That does the same thing but puts the message in a listbox

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    Sorry for late respond but I couldn't do it last night as VBF became unavailable.
    Anyway, that wouldn't be exactly the same: it'll try to find window first and if doesn't yet exist it will create a brand new instance and then assign Caption/Tag and at the end it will add new item to the list. On the other hand if window already exist then only new item added to the list.

    Here is how to test it:
    - create two forms (say Form1 and frmMsg)
    - copy DisplayMessage procedure to Form1
    - add two buttons to Form1
    - execute the following code for each button and see what happends next:
    VB Code:
    1. Private Sub Command1_Click()
    2.     DisplayMessage "hi", "John"
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     DisplayMessage "hi", "Peter"
    7. End Sub

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    Im trying to make the incoming messages like when u recive a message on aim/msn/yahoo where it opens a new window with the message and every message you get from the same person goes in that window.

  14. #14

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    Ok just making sure that you understand what I was saying.

    Right now the display message opens them in a new window no matter what.

    Could I have it search for the form.tag becuase all the forms have the same name? And then if it finds the form tag it sends it to that form and if it doesnt find it it opens a new form. Is that possible?
    Last edited by andy345; Sep 22nd, 2005 at 03:47 PM.

  16. #16
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: recive message

    Quote Originally Posted by andy345
    ... Could I have it search for the form.tag becuase all the forms have the same name? And then if it finds the form tag it sends it to that form and if it doesnt find it it opens a new form. Is that possible?
    Andy,
    I will say it one more time: THAT IS EXACTLY WHAT MY SAMPLE PROCEDURE DOES so take a good look at it again and then give it the try.
    It's in the post #10.

    Good luck.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Dec 2004
    Posts
    168

    Re: recive message

    Wow im sorry i have been watching tv and responding so I wasnt paying really close attenchion

    Edit: I just put ur code in and every message opens in a new window so I dont think its working still.

    Edit2: Actually I think it is working. Ill post another edit in a minute to tell you if i got it.

    Edit3: Ok it is working I did some tests with sending messages from different names and it works good.

    SO Thank You very much for all your help RhinoBull.
    Last edited by andy345; Sep 22nd, 2005 at 04:17 PM.

  18. #18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width