[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB6 Winsock Telnet Recieve Problem

Posted on 2010-08-20
5
Medium Priority
?
742 Views
Last Modified: 2013-12-26
Using VB6 and winsock to connect to a router and issue a command, currently I can -

1) Connect to a router
2) Issue a command
3) Disconnect

But what I would like to do it -

1) Connect to a router
2) Issue a command
3) Output the routers response to textfile1
4) Issue another command
5) Output the routers response to textfile2
6) Disconnect

Any ideas???????????
0
Comment
Question by:souldigital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33485398
Try this code (not tested), but logic should work:


Private bSecond As Boolean

Private Sub Command1_Click()
    bSecond = False
    Winsock1.Close
    Winsock1.Connect "10.10.0.60", 23
End Sub

Private Sub Winsock1_Connect()
    If bSecond = False Then
        Winsock1.SendData "strdata1"
    End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String, strFile As String
    strData = String(bytesTotal, Chr$(0))
    Winsock1.GetData strData, vbString, bytesTotal
    If bSecond = False Then
        strFile = "c:\test1.txt"
    Else
        strFile = "c:\test2.txt"
    End If
    WriteToFile strFile, strData
End Sub

Private Sub WriteToFile(strFile As String, strData As String)
    Dim oFSO As New Scripting.FileSystemObject
    Dim oStream As TextStream
    Set oStream = oFSO.OpenTextFile(strFile, ForWriting)
    oStream.Write strData
    oStream.Close
    If bSecond = False Then
        Winsock1.SendData "strdata2"
        bSecond = True
    Else
        Winsock1.Close
    End If
    Set oFSO = Nothing
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

Open in new window

0
 

Author Comment

by:souldigital
ID: 33495197
No does not seem to work, I get the error sub or function not defined.
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33495458
Which sub or function not defined?
0
 

Author Comment

by:souldigital
ID: 33495710
Private Sub WriteToFile(strFile As String, strData As String)
   
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 2000 total points
ID: 33496867
Try this:

Private Sub WriteToFile(strFile As String, strData As String)
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Dim oStream As Object
    Set oStream = oFSO.OpenTextFile(strFile, 2)
    oStream.Write strData
    oStream.Close
    If bSecond = False Then
        Winsock1.SendData "strdata2"
        bSecond = True
    Else
        Winsock1.Close
    End If
    Set oFSO = Nothing
End Sub

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question