Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

10 Experts available now in Live!

Get 1:1 Help Now