Question : VB6 Telnet Winsock Run-Time Error '40006'

I am using the following code -

Private Sub Connect_Click()
    Winsock1.Connect ("192.168.1.1"), 23
    Winsock1.SendData "admin" & vbCrLf
End Sub

and basically get the error - Run-Time Error '40006'

I can avoid this error by having two seperate buttons, one to connect and one to issue the SendData command, or by using the following function -

Private Sub Winsock1_Connect()
   Winsock1.SendData "admin" & vbCrLf
End Sub

But I do not want to use either of these methods, I just want everything to be included in the one button.

Please help!

Answer : VB6 Telnet Winsock Run-Time Error '40006'

Now I see why you want to have all the code in one sub... But unfortunately that's not the way it designed.
Try the following code:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Private iButton As Integer

Private Sub Command1_Click()
    iButton = 1
    ConnectWinsock
End Sub

Private Sub Command2_Click()
    iButton = 2
    ConnectWinsock
End Sub

Private Sub Command3_Click()
    iButton = 3
    ConnectWinsock
End Sub

Private Sub ConnectWinsock()
    Winsock1.Close
    Winsock1.Connect "192.168.1.1", 23
End Sub

Private Sub Winsock1_Connect()
    Select Case iButton
        Case 1: Winsock1.SendData "admin" & vbCrLf
        Case 2: Winsock1.SendData "tx power" & vbCrLf
        Case 3: Winsock1.SendData "help" & vbCrLf
    End Select
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    MsgBox "Error occurred: " & Description
End Sub
Random Solutions  
 
programming4us programming4us