Results 1 to 3 of 3

Thread: Get that text!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    California
    Posts
    115

    Post

    I'm trying to automate another app thru my app, but i've ran into some problems. For some reason, my app wont get the text its suppose to.

    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE
    Dim lCalc As Long
    Dim lTextbox As Long
    Dim lLen As Long
    Dim strBuffer As String
    -----------------------------------------------------
    
    On Error Resume Next
    DoEvents
    
    RetVal = Shell("C:\SomeApp.exe", vbNormalFocus) 'opens app
    AppActivate RetVal
    SendKeys Text2.Text 'sends first string to other apps first textbox
    SendKeys vbTab 'sends tab to goto next textbox
    SendKeys "(16)" 'sends second string to other apps second textbox
    SendKeys vbTab 'sends tab
    SendKeys "(1231231231231231)" 'sends third string to other apps third textbox
    SendKeys vbTab 'sends tab
    SendKeys Chr(13) 'sends enter to press a command button
    
    '#after button is pressed, other app auto puts cursor in the correct textbox
    '#grabs text from textbox on other app
    lCalc = FindWindowEx(0, 0, "ThunderRT5Form", vbNullString)
    lTextbox = FindWindowEx(lCalc, 0, "ThunderRT5TextBox", vbNullString)
    lLen = SendMessage(lTextbox, WM_GETTEXTLENGTH, 0, 0) + 1
    strBuffer = Space(lLen)
    Call SendMessageStr(lTextbox, WM_GETTEXT, lLen, ByVal strBuffer)
    Text1.Text = Text1.Text & strBuffer & Chr(13) & "1"
    
    SendKeys "%" 'sends alt to the app
    SendKeys "{DOWN}" 'sends down on menu
    SendKeys "{DOWN}" '""
    SendKeys "{ENTER}" 'sends enter to exit out of program
    Does anyone know why this doesn't work, or know a better way to do this?

    Thanks,
    Ryan

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Fort Lauderdale, FL USA
    Posts
    112
    Try putting "True" after the sendkeys function.

    Sendkeys "A", True

    Also, you may want to put a FindWindow API just after your Shell function to make sure the application is loaded before you start sending it information. Chris gives and example of this in the link below.

    http://www.vbforums.com/showthread.php?threadid=18327

    Damonous

  3. #3
    Guest
    Try removing the On Error Resume Next and see if you get an error. If you do, you can pin point the problem.

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