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.
Does anyone know why this doesn't work, or know a better way to do this?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
Thanks,
Ryan




Reply With Quote