Results 1 to 22 of 22

Thread: why cannot display message in form?[vb.net]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Resolved 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.

  2. #2
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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:
    1. Private _strMessage As String
    2.  
    3. Public Sub New(ByVal msg As String)
    4.  
    5. Me.New() 'Calls the original New sub that has InitializeComponent
    6.  
    7. _strMessage = msg
    8.  
    9. txtMessageList.Text = _strMessage & vbCrLf
    10.  
    11. End Sub

    Create your new 'Form A' like this
    VB Code:
    1. Private Sub loadMessage(ByVal message As System.String) Handles client1.displayMessage
    2.  
    3. Dim frmMessage As New FrmInstantMessage(message)
    4. frmMessage.Show()
    5.  
    6.  End Sub

    I hope that helps you out.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    problem stil exits........do u mind i send my application to u?

  4. #4
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: why cannot display message in form?[vb.net]

    Yes, ok. PM you my email
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    i didnt receive ur message..send to this [email protected]

  6. #6
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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:
    1. Public Sub ReceiveMessage()
    2.  
    3.     'client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
    4.     Dim message As String = "abc"
    5.     RaiseEvent displayMessage(message)
    6.  
    7. 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.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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........

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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....!!

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    Andy_p did u receive my application? the application can run?

  10. #10
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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!
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    the server aplication is vb6 project.........

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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?

  13. #13
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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:
    1. Public Sub ReceiveMessage()
    2.  
    3.         Static onceOnly As Boolean
    4.  
    5.         If Not onceOnly Then
    6.  
    7.             onceOnly = True
    8.             client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
    9.        
    10.         End If
    11.  
    12. End Sub
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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?

  15. #15
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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:
    1. Private f As FrmInstantMessage
    Change the 'loadmessage' to this:
    VB Code:
    1. Private Sub loadMessage(ByVal IncomingMessage As String) Handles client.displayMessage
    2.  
    3.     If f Is Nothing Then
    4.         f = New FrmInstantMessage(IncomingMessage)
    5.     Else
    6.         f.txtMessageList.Text = IncomingMessage
    7.     End If
    8.  
    9.     f.Show()
    10.  
    11. End Sub
    Try that, and see what happens.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    the new of frminstantmessage got argument?

  17. #17
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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:
    1. Private Sub loadMessage(ByVal IncomingMessage As String) Handles client.displayMessage
    2.  
    3.     If f Is Nothing Then
    4.         f = New FrmInstantMessage
    5.         f.txtMessageList.Text = IncomingMessage
    6.     Else
    7.         f.txtMessageList.Text = IncomingMessage
    8.     End If
    9.  
    10.     f.Show()
    11.  
    12. End Sub
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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()

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: why cannot display message in form?[vb.net]

    VB Code:
    1. Private Sub FrmInstantMessage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         TabControl1.SelectedIndex = 0
    4.         btnSend.Enabled = False
    5.  
    6.         Me.Opacity = 0
    7.         Me.timer = New Timer
    8.         Me.timer.Interval = 50
    9.         AddHandler timer.Tick, AddressOf formAppear
    10.  
    11.         Me.timer.Start()
    12.  
    13. End Sub

    in the form_load event for frminstantmessage, is it any thing that is possible to cause the problem?

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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:
    1. Option Explicit
    2.  
    3. Private ClientConnect
    4.  
    5. Private Sub Command1_Click()
    6.     Winsock(ClientConnect).SendData (txtIncomingConnection.Text)
    7. End Sub
    8.  
    9. Private Sub Form_Load()
    10.     ClientConnect = 0
    11.     Winsock(0).LocalPort = 8080
    12.     Winsock(0).Listen
    13.     txtIncomingConnection.Text = "Waiting Connection........"
    14. End Sub
    15.  
    16. Private Sub Winsock_ConnectionRequest(index As Integer, ByVal requestID As Long)
    17.    
    18.     ClientConnect = ClientConnect + 1
    19.  
    20.     Load Winsock(ClientConnect)
    21.     Winsock(ClientConnect).Close
    22.     Winsock(ClientConnect).Accept requestID
    23.    
    24.     txtIncomingConnection.Text = "Connected"
    25.     List1.AddItem (Winsock(ClientConnect).RemoteHostIP & vbTab & requestID & vbCrLf)
    26.  
    27. End Sub
    28.  
    29. Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
    30.    
    31.     Dim incomingdata As String
    32.    
    33.     Winsock(index).GetData incomingdata
    34.     MsgBox bytesTotal
    35.     Winsock(index).SendData (incomingdata & Winsock(index).LocalIP)
    36.     txtIncomingConnection.Text = Now & ":" & "  " & incomingdata & vbNewLine
    37.  
    38. End Sub
    39.  
    40. Private Sub Winsock_SendComplete(index As Integer)
    41.     MsgBox "Complete"
    42. End Sub

  21. #21
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    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:
    1. Public Sub ReceiveMessage()
    2.             client.GetStream.BeginRead(rBuffer, 0, rBufferSize, AddressOf read, Nothing)
    3. End Sub
    4.  
    5. Public Sub read(ByVal dataIn As IAsyncResult)
    6.  
    7.  
    8.         Dim ByteRead As Integer
    9.         Dim message As String
    10.  
    11.         Try
    12.  
    13.             ByteRead = client.GetStream.EndRead(dataIn)
    14.  
    15.             If ByteRead < 1 Then
    16.                 Exit Sub
    17.             End If
    18.  
    19.             message = Encoding.ASCII.GetString(rBuffer, 0, ByteRead)
    20.  
    21.             getMessage = True
    22.  
    23.             If getMessage = True Then
    24.                 RaiseEvent displayMessage(message)
    25.             End If
    26.  
    27.         Catch
    28.         End Try
    29.  
    30.     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
  •  



Click Here to Expand Forum to Full Width