Solved

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

Posted on 2010-08-17
5
543 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
[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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

688 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