|
-
Sep 4th, 2005, 09:24 AM
#1
Thread Starter
Fanatic Member
why cannot display message in form?[vb.net]
the code pls refer here . i hv spend two week try to solve this problem but stil cannot solve the problem............the main problem is when the message receive want to display on the form, but the form appear and hanging halfway.......pls help solve the problem, my home work deadline is at the end of this week....pls
Last edited by kenny_oh; Sep 30th, 2005 at 06:43 AM.
-
Sep 4th, 2005, 10:03 AM
#2
Re: why cannot display message in form?[vb.net]
Firstly, this should probably be posted in the VB.NET forum, but try this:
Put this code in your 'Form A'
VB Code:
Private _strMessage As String
Public Sub New(ByVal msg As String)
Me.New() 'Calls the original New sub that has InitializeComponent
_strMessage = msg
txtMessageList.Text = _strMessage & vbCrLf
End Sub
Create your new 'Form A' like this
VB Code:
Private Sub loadMessage(ByVal message As System.String) Handles client1.displayMessage
Dim frmMessage As New FrmInstantMessage(message)
frmMessage.Show()
End Sub
I hope that helps you out.
-
Sep 4th, 2005, 11:34 AM
#3
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
problem stil exits........do u mind i send my application to u?
-
Sep 4th, 2005, 12:06 PM
#4
Re: why cannot display message in form?[vb.net]
-
Sep 4th, 2005, 12:13 PM
#5
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
i didnt receive ur message..send to this [email protected]
-
Sep 4th, 2005, 01:14 PM
#6
Re: why cannot display message in form?[vb.net]
Well I am not sure because I can't run the app properly because I can't do the net, and sockets stuff. Because I have VB.NET Standard maybe?
But, if I bypass the part of the app that involves this and just give a fixed string to the ReceiveMessage() method, it appears that it works. The InstantMessage form opens and contains the message that I supplied to it:
VB Code:
Public Sub ReceiveMessage()
'client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
Dim message As String = "abc"
RaiseEvent displayMessage(message)
End Sub
I would suggest thet you fade the opening of this form a bit quicker because it takes longer than one second, which is the time you have set in the main form timer. It might be causing a problem?
So, it apears to me that the problem may lie in the part of the app dealing with connection etc to the net, and sockets etc. Afraid I can't help you with any of that.
-
Sep 4th, 2005, 08:38 PM
#7
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
hmmm....i try to do some change on what u said.......did u run the server application? u run the server application first.......then run the client application...if not i appear the messagebox said that cannot work without socket........
-
Sep 4th, 2005, 08:59 PM
#8
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
i hv increase the timer interval but the same problem exist......can u run again my system.....i hv send another copy to u........u try to run the server application first bcoz client application connect to server.......in the server app got one button is use to send message to client to test whether it can receive the message or not......pls .....the biggest problem is on the form display there....!!
-
Sep 5th, 2005, 12:06 PM
#9
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
Andy_p did u receive my application? the application can run?
-
Sep 5th, 2005, 12:06 PM
#10
Re: why cannot display message in form?[vb.net]
Kenny, I cannot use the files included with the Server app. Are they VB6 project files or something? I have VB.NET only.
I can only think there is a problem the the GetStream.BeginRead or GetStream.EndRead methods, and I don't know anything about that I am afraid.
In the 'read' sub, you have two Msgbox's showing 'ByteRead' and 'message'. Do these appear and show what you expect to see?
If they do, remove them and don't interrupt the flow of the sub to see if that makes any difference.
That is the best i can suggest. Good luck!
-
Sep 5th, 2005, 12:09 PM
#11
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
the server aplication is vb6 project.........
-
Sep 5th, 2005, 12:14 PM
#12
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
i hv put two msgbox after the frmmessage.show and frmmessage.txtmessagelist.text = message & vbcrlf. this make the form display success but the mouse cursor show that the form stil loading something and never stop..........i realize that two msgbox like push the two lines code execute, if not there will not execute complete...what is ur comment on this?
-
Sep 5th, 2005, 12:35 PM
#13
Re: why cannot display message in form?[vb.net]
My guess is that the BeginRead and EndRead is not completing correctly perhaps.
Try this code to allow only one read, to see if it is multiple calls to the read sub that is causing the problem.
VB Code:
Public Sub ReceiveMessage()
Static onceOnly As Boolean
If Not onceOnly Then
onceOnly = True
client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
End If
End Sub
-
Sep 6th, 2005, 04:06 AM
#14
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
all the change u suggest, i hve done.....but the problem stil exist............really couldnt found the problem?
-
Sep 6th, 2005, 11:45 AM
#15
Re: why cannot display message in form?[vb.net]
OK Kenny, I will give it one more shot...
Put the 'ReceiveMessage()' sub back to how it was.
Add this to the top of the main form:
VB Code:
Private f As FrmInstantMessage
Change the 'loadmessage' to this:
VB Code:
Private Sub loadMessage(ByVal IncomingMessage As String) Handles client.displayMessage
If f Is Nothing Then
f = New FrmInstantMessage(IncomingMessage)
Else
f.txtMessageList.Text = IncomingMessage
End If
f.Show()
End Sub
Try that, and see what happens.
-
Sep 6th, 2005, 11:54 AM
#16
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
the new of frminstantmessage got argument?
-
Sep 6th, 2005, 12:01 PM
#17
Re: why cannot display message in form?[vb.net]
Yes, if you still have the New(ByVal mg as String) sub entered.
Alternatively, you can do this if you prefer, which almost as you had it originally:
VB Code:
Private Sub loadMessage(ByVal IncomingMessage As String) Handles client.displayMessage
If f Is Nothing Then
f = New FrmInstantMessage
f.txtMessageList.Text = IncomingMessage
Else
f.txtMessageList.Text = IncomingMessage
End If
f.Show()
End Sub
-
Sep 6th, 2005, 12:06 PM
#18
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
hmmm....stil same problem.......last night u said that my beginRead and endRead got problem, what is the problem? it should not have probem since the message value can pass to loadmessage()
-
Sep 6th, 2005, 12:11 PM
#19
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
VB Code:
Private Sub FrmInstantMessage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
TabControl1.SelectedIndex = 0
btnSend.Enabled = False
Me.Opacity = 0
Me.timer = New Timer
Me.timer.Interval = 50
AddHandler timer.Tick, AddressOf formAppear
Me.timer.Start()
End Sub
in the form_load event for frminstantmessage, is it any thing that is possible to cause the problem?
-
Sep 6th, 2005, 12:14 PM
#20
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
this is my code for server application using vb6. the command button 1, i was uses to test the client side whether it receive the message....everything i press this button to test the receivemessage() for client
VB Code:
Option Explicit
Private ClientConnect
Private Sub Command1_Click()
Winsock(ClientConnect).SendData (txtIncomingConnection.Text)
End Sub
Private Sub Form_Load()
ClientConnect = 0
Winsock(0).LocalPort = 8080
Winsock(0).Listen
txtIncomingConnection.Text = "Waiting Connection........"
End Sub
Private Sub Winsock_ConnectionRequest(index As Integer, ByVal requestID As Long)
ClientConnect = ClientConnect + 1
Load Winsock(ClientConnect)
Winsock(ClientConnect).Close
Winsock(ClientConnect).Accept requestID
txtIncomingConnection.Text = "Connected"
List1.AddItem (Winsock(ClientConnect).RemoteHostIP & vbTab & requestID & vbCrLf)
End Sub
Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim incomingdata As String
Winsock(index).GetData incomingdata
MsgBox bytesTotal
Winsock(index).SendData (incomingdata & Winsock(index).LocalIP)
txtIncomingConnection.Text = Now & ":" & " " & incomingdata & vbNewLine
End Sub
Private Sub Winsock_SendComplete(index As Integer)
MsgBox "Complete"
End Sub
-
Sep 6th, 2005, 12:15 PM
#21
Re: why cannot display message in form?[vb.net]
This is what I said
My guess is that the BeginRead and EndRead is not completing correctly perhaps
I don't know what is wrong. I can't give you any help with the Network stream stuff because I don't know anything about it. I would suggest that having tried the things with the form, and making things run only once, and the problem still appears, then it is my guess that the problem does lie with the network stream code. BUT, I do not know for sure.
I really don't know what else to suggest, sorry.
-
Sep 6th, 2005, 12:21 PM
#22
Thread Starter
Fanatic Member
Re: why cannot display message in form?[vb.net]
i hv a idea that change the read method to function to return value but the receivemessage() method addressof read cause some problem where procedure doesnt not match with function
VB Code:
Public Sub ReceiveMessage()
client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
End Sub
Public Sub read(ByVal dataIn As IAsyncResult)
Dim ByteRead As Integer
Dim message As String
Try
ByteRead = client.GetStream.EndRead(dataIn)
If ByteRead < 1 Then
Exit Sub
End If
message = Encoding.ASCII.GetString(rBuffer, 0, ByteRead)
getMessage = True
If getMessage = True Then
RaiseEvent displayMessage(message)
End If
Catch
End Try
End Sub
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
|