Solved

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

Posted on 2010-08-17
5
540 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 122
Macro which automatically send Excel spreadsheet to Outlook problem 2 76
Validating VB6 Function 19 65
Adding to a VBA? 6 77
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

856 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