Article

From:
To:
Q Correll
Subject:
Re: OT Pasting text into a 3rd party app (Some Progress)
Newsgroup:
nexusdb.public.discussions
URL:
Shortcut to this article
Printer Friendly

Re: OT Pasting text into a 3rd party app (Some Progress)

Q,
Yeah, so far I can't seem to make it work.
BUT, the paste operation seems to be relatively stable.
In fact, I got tired if it failing using Notepad and decided to just 
wing it- let it run and paste the data in the actual accounting system.

Surprisingly, what I cobbled together works great. It is a real time saver since a user can spend 5-10 minutes entering an invoice into the accounting system with 20+ distributions. With this utility- it takes all of 5 seconds to do. This utility literally could save this company about 16 hours/week of data entry work. The gist- utilizing the clipboard can actually work.

FWIW, here is the code that works- I abandoned trying to load this stuff from a file/string list and decided just to iterate through the table since any kind of looping "destabilized" the clipboard. CAUTION: This is experimental code and is not pretty- much to optimize. BUT, again it works. Note I have to work with someone else's MS Access tables. John *** procedure TForm1.FullInvoiceTest1Click(Sender: TObject); var Appwin : hWnd; DistributionTotal: Currency; begin //insert try later   DistributionTotal := 0;   Appwin:= FindWindow(PChar(0),'Accounts Payable');///Enter Invoices if Appwin <> 0 then begin //ADOQuery4- MS Access table which contains distribution amounts,cost //codes for a purchase order- Select //Use,accting,itemNumProspectus,sum(qty * [Unit //Price] * (1+ //tax_rate)) as TaxedTotal from t_Specific_Material //where PONumber = :POVar group by accting,use,ItemNumProspectus order //by accting,ItemNumProspectus,use
while not ADOQuery4.Eof do begin if ADOQuery4.FieldByName('TaxedTotal').value <> 0 then begin //Don't bother with zero distributions      ShowWindow(Appwin,SW_RESTORE);     SetForegroundWindow(Appwin);    Clipboard.AsText:= Trim(Edit2.Text);//contains a jobid, i.e. //"HC-0094" (lot 94 Hunting Creek) constant that the user enters and is //required by the accounting system     keybd_event( VK_CONTROL, 0, 0, 0 );//paste in the first cell     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_TAB, 0, 0, 0 );//tab to the next cell     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );     Sleep(50);///delay seems to add stability     Clipboard.Clear; //for safety sake
    if StrToInt(Trim(ADOQuery4.FieldByName('accting').AsString)) >= 5000   then ///skip entering a code when the distribution is not standard (standard codes are in the range 0-4999)     begin     Clipboard.AsText:= Trim(ADOQuery4.FieldByName('accting').AsString);     keybd_event( VK_CONTROL, 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     end;//account code check     keybd_event( VK_TAB, 0, 0, 0 ); ///tab regardless of whether a code is inserted     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );      Sleep(50);      Clipboard.Clear;    Clipboard.AsText:= Trim(ADOQuery2.FieldByName('Cost_code').AsString);     keybd_event( VK_CONTROL, 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_TAB, 0, 0, 0 );     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );      Sleep(50);      Clipboard.Clear;     Clipboard.AsText:= 'A'; //constant-required     keybd_event( VK_CONTROL, 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_TAB, 0, 0, 0 );     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );
     Sleep(50);      Clipboard.Clear;   Clipboard.AsText := Trim(ADOQuery4.FieldByName('TaxedTotal').AsString);     keybd_event( VK_CONTROL, 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_TAB, 0, 0, 0 );     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );     Sleep(50);     Clipboard.Clear;     Clipboard.AsText := Trim(ADOQuery4.FieldByName('itemNumProspectus').AsString) + ' ' + Trim(Uppercase(ADOQuery4.FieldByName('use').AsString));;     keybd_event( VK_CONTROL, 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, 0, 0 );     keybd_event( VKKeyScan('V'), 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 );     keybd_event( VK_TAB, 0, 0, 0 );     keybd_event( VK_TAB, 0, KEYEVENTF_KEYUP, 0 );     DistributionTotal := DistributionTotal + ADOQuery4.FieldByName('TaxedTotal').value; end; ///taxed total <> 0    ADOQuery4.Next; end;    Label9.Caption := CurrToStrF(DistributionTotal,ffcurrency,2);    if GlobalDistributionTotal <> 0 then GlobalDistributionTotal :=    GlobalDistributionTotal + DistributionTotal;    Application.ProcessMessages; end else showmessage('Launch Timberline Account Payable before continuing.'); //future- launch it for the user?
end;


***
> Eivind,
>
> | You'll likely want to use the win api function WaitForInputIdle in
> | your loop to check that the app is ready.
>
> When it works. <sigh>
>
>
FYI: Phrase searches are enclosed in either single or double quotes
 
 
 
24-Jul 11:00 utc Operating system upgrade in process, expect some down time.
Originally created by
[Tamarack]
Sun, 24 Sep 2017 23:08:55 UTC
Copyright © 2009-2017
HREF Tools Corp.