Results 1 to 5 of 5

Thread: Run Time Error 40020!! Pls Help!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Question Run Time Error 40020!! Pls Help!

    I have write a simple Client/Server program, for multiple client within my home. But when I run the client program, It give me the following Error.

    Run Time Error 40020!

    My code is below, THanks For your help in advance!
    VB Code:
    1. Option Explicit
    2. Private Sub cmdClose_Click()
    3. Socket1.Close
    4. StatusBar1.Panels(1).Text = "Connection Closed"
    5. End Sub
    6.  
    7. Private Sub cmdConnect_Click()
    8. If Socket1.State <> sckClosed Then
    9.     Socket1.RemoteHost = "192.168.0.4"
    10.     Socket1.RemotePort = 1007
    11.     Socket1.Connect
    12.     txtSend.SetFocus
    13.     StatusBar1.Panels(1).Width = 1000
    14.     StatusBar1.Panels(1).Text = "Connecting to server..."
    15. Else
    16.     MsgBox "Error! Connection already exist, Please Close connection before Connect!"
    17. End If
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21. Socket1.Connect
    22. End Sub
    23.  
    24.  
    25. Private Sub txtSend_KeyPress(KeyAscii As Integer)
    26. Static Last_Line_Feed As Long
    27. If Socket1.State <> sckConnected Then
    28.     Dim NewLine As String
    29.     If txtSend = vbNullString Then Last_Line_Feed = 0
    30.     If KeyAscii = 13 Then
    31.     NewLine = Mid(txtSend, Last_Line_Feed + 1)
    32.     Last_Line_Feed = txtSend.SelStart
    33.     End If
    34.     StatusBar1.Panels(1).Text = "Sending Data..."
    35.     Socket1.SendData txtName.Text & " >" & NewLine
    36.     DoEvents
    37. Else
    38.     StatusBar1.Panels(1).Text = "Not Currently Connected!"
    39. End If
    40. End Sub
    41.  
    42. Private Sub Socket1_DataArrival(ByVal bytesTotal As Long)
    43. Dim data As String
    44. Socket1.GetData data, vbString
    45. txtReceive.SelText = data
    46. End Sub
    47.  
    48. Private Sub Socket1_SendComplete()
    49. StatusBar1.Panels(1).Text = "Complete Sending Process!"
    50. End Sub

    The stops at [Socket1.RemoteHost = "192.168.0.4"]
    anyone can help!!!
    Last edited by Locus; Jan 16th, 2006 at 08:39 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: Run Time Error 40020!! Pls Help!

    In the "Form_Load" Event, I am using "Socket1.Connect"

    Is it because of that?

    But I already inlcude
    "If Socket1.State <> sckClosed" Statement in the "cmdConnect_Click" Event. why still can not?

    Thx!

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Run Time Error 40020!! Pls Help!

    As near as I can tell, when the remote address & port are unknown when the Socket1.Connect line in Form_Load executes. The command may still be trying to complete when you click the Connect button. In that case, the state will not be sckClosed and your code will try to connect again.

    If you want to connect only when the user clicks a button, remove the Socket1.Connect line from Form_Load.

    If you want to connect when the app loads, you can either
    1) change the line Socket1.Connect to cmdConnect_Click in Form_Load, or
    2) move all of the connect code to Form_Load.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    3

    Re: Run Time Error 40020!! Pls Help!

    Thanks, ccoder, I do as you told me and it works.

    thanks for your help!

  5. #5
    New Member
    Join Date
    Feb 2016
    Posts
    1

    Run Time Error 40020....Pls Help

    hello....

    Initially, master and slave communicates nicely but after some query and response i am getting error :run time error 40020...


    please help me...

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