|
-
Sep 21st, 2005, 07:51 PM
#1
Thread Starter
Addicted Member
[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:
Private Sub Message(strName As String, strMsg As String)
Dim frm As Form
Dim blnExist As Boolean
For Each frm In Forms
If UCase(frm.Caption) = UCase(strName) Then
blnExist = True
Exit For
End If
Next frm
If blnExist = False Then
Dim newfrm As New Form2
newfrm.Caption = strName
newfrm.Tag = strName
newfrm.Text1.Text = newfrm.Text1.Text & strName & " - " & strMsg & vbNewLine
newfrm.Show (vbNormal)
End If
If blnExist = True Then
If newfrm.Tag = strName Then
newfrm.Text1.Text = newfrm.Text1.Text & strName & " - " & strMsg & vbNewLine
End If
End If
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.
-
Sep 21st, 2005, 08:11 PM
#2
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 ...
-
Sep 21st, 2005, 08:20 PM
#3
Thread Starter
Addicted Member
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
-
Sep 21st, 2005, 08:25 PM
#4
Re: recive message
Still doesn't make much sense (yet) ... How do you communicate with "Person1" - via what interface?
-
Sep 21st, 2005, 08:31 PM
#5
Thread Starter
Addicted Member
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.
-
Sep 21st, 2005, 08:37 PM
#6
Re: recive message
So why don't you simply use ONE form to display ANY of you new messages:
VB Code:
Private Sub DisplayMessage(strMsg As String)
Dim frm As frmMsg
Set frm = New frmMsg
frm.lbMessage.Caption = strMsg
frm.Show vbModal
End Sub
-
Sep 21st, 2005, 08:48 PM
#7
Thread Starter
Addicted Member
Re: recive message
Because that gets confusing if your getting messages from 5 people in the same window.
-
Sep 21st, 2005, 08:52 PM
#8
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:
Private Sub DisplayMessage(strMsg As String, strUser As String)
Dim frm As frmMsg
Set frm = New frmMsg
frm.lbMessage.Caption = strMsg
frm.Caption = "Message Received From " & strUser
frm.Show vbModal
End Sub
-
Sep 21st, 2005, 09:01 PM
#9
Thread Starter
Addicted Member
Re: recive message
Oooo yeah but is their anyway to put the messages from the same user in the same form?
-
Sep 21st, 2005, 09:17 PM
#10
Re: recive message
In that case search might come handy:
VB Code:
Private Sub DisplayMessage(strMsg As String, strUser As String)
Dim frm As Form
Dim blnExist As Boolean
For Each frm In Forms
If UCase(frm.Tag) = UCase(strUser) Then
blnExist = True
Exit For
End If
Next frm
If Not blnExist Then
Set frm = New frmMsg
frm.Caption = "Message Received From " & strUser
frm.Tag = strUser
End If
frm.lstMsg.AddItem strMsg
frm.Show
frm.ZOrder
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.
Last edited by RhinoBull; Sep 21st, 2005 at 09:24 PM.
-
Sep 21st, 2005, 09:42 PM
#11
Thread Starter
Addicted Member
Re: recive message
That does the same thing but puts the message in a listbox
-
Sep 22nd, 2005, 08:37 AM
#12
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:
Private Sub Command1_Click()
DisplayMessage "hi", "John"
End Sub
Private Sub Command2_Click()
DisplayMessage "hi", "Peter"
End Sub
-
Sep 22nd, 2005, 02:39 PM
#13
Thread Starter
Addicted Member
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.
-
Sep 22nd, 2005, 03:12 PM
#14
Re: recive message
That's what my DisplayMessage procedure is aiming at.
-
Sep 22nd, 2005, 03:34 PM
#15
Thread Starter
Addicted Member
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.
-
Sep 22nd, 2005, 03:57 PM
#16
Re: recive message
 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.
-
Sep 22nd, 2005, 04:00 PM
#17
Thread Starter
Addicted Member
-
Sep 22nd, 2005, 04:25 PM
#18
Re: [RESOLVED] recive message
No problem, enjoy it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|