Results 1 to 33 of 33

Thread: Need to start a command line window and send a string to it

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member BrianPaul's Avatar
    Join Date
    Aug 2007
    Posts
    294

    Re: Need to start a command line window and send a string to it

    Ok, got it... put a sleep statement right after it posts a letter and it fixed the problem. Now it looks like this...

    Code:
    Private Function SendTxt(ByVal Handle As Long, ByVal sText As String) As Boolean
        Dim i As Integer
        Dim lngReturn As Long
        For i = 1 To Len(sText)
            lngReturn = PostMessage(Handle, WM_CHAR, Asc(Mid$(sText, i, 1)), 0&)
            Sleep 25
            If lngReturn <> 1 Then Exit Function ' failed
        Next i
        SendTxt = True ' passed
    End Function

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Need to start a command line window and send a string to it

    Quote Originally Posted by BrianPaul View Post
    Ok, got it... put a sleep statement right after it posts a letter and it fixed the problem.
    You might want to try using SendMessage instead of Postmessage?....

    The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

    PostMessage Function: Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.

    SendMessageTimeOut might also be worth a look as you can set a max wait time to return, Sendmesssage can hang your program (or make it appear hung) if the program the message is sent is busy in say a loop.
    Last edited by Edgemeal; May 18th, 2010 at 02:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width