Solved

wsTCP.SendData does not send Chr(13) as Carriage Return

Posted on 2010-08-17
5
535 Views
Last Modified: 2012-05-10
Sending Chr(13) is supposed to be equivalent to pressing 'Enter' on the keyboard. However, the program thinks that I am trying to send the string "Chr(13)". How can I go about this problem? Thanks.
Private Sub cmdLogin_Click()
    If Run.Value Then
        progctrfinal = TextBox1.Value
        For progctr = 1 To progctrfinal Step 1
            Call optionStatus(progctr)
        Next progctr
    End If
End Sub

Function CommandCode(PC As Long)
    Dim command As String
    Dim argPassedIn As String

    Debug.Print progctr
    command = Worksheets("GUI").Cells(PC + 1, 2).Value
    argPassedIn = Worksheets("GUI").Cells(PC + 1, 3).Value
    Debug.Print command & " " & (argPassedIn)
    If command = "MySend" Then Call MySend(argPassedIn)

End Function

Function MySend(ByVal data As String)
    DoEvents
    wsTCP.SendData data
End Function

Private Sub optionStatus(ByVal progctr As Long)
    Select Case progctr
        Case 1      
            Login
            Call WaitCurs(20, 51)
            If Not CurPos Then Exit Sub
            
        Case 2
            Call CommandCode(progctr)
          
        Case 3
            CommandCode progctr
'
        Case 4
            CommandCode progctr
            
        Case 5
            Debug.Print "Case 5"
            CommandCode progctr
        
        Case Else
            Debug.Print "No match"
            'Code for any nonmatch
    End Select
End Sub

Open in new window

main-menu.JPG
0
Comment
Question by:teeling
  • 4
5 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33461468
Is data the string "Chr(13)"? If so, that will be why.

Try

Function MySend(ByVal data As String)
    DoEvents
    If LCase(data)="chr(13)" Then data = Chr(13)
    wsTCP.SendData data
End Function

or some sort of replace if the string can contain other chars + chr(13)
0
 

Author Comment

by:teeling
ID: 33461526
I am not sure whether it's sending the 'Enter' key because it's coming up with some error prompt in the excel sheet.

If I were to do this manually, pressing enter sends me straight to another menu.

Thanks.
Selection-0.JPG
0
 

Author Comment

by:teeling
ID: 33461648
I found out what's the problem. I have sent an extra sets of "". Thanks for the help :)
0
 

Author Closing Comment

by:teeling
ID: 33461650
Prompt reply.
0
 

Author Comment

by:teeling
ID: 33461668
Another related question, what if I'm trying to send the key F1, which is a combination of several characters, i.e. Chr(27) & "O" & "P"?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now