Loop Pulling 1st Variable's Data Into 2nd Iteration

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Trippet
Posts: 16
Joined: 08 Mar 2018, 13:37

Loop Pulling 1st Variable's Data Into 2nd Iteration

08 Mar 2018, 14:26

The first set kicks off when I press Ctl Alt C, and copies across 5 fields in Excel, assigning each field to a variable, for as many loops as I designate. No problems there, working great.

The second set kicks off with Ctl Alt V and it enters the variables into QuickBooks. It's working Except for the "qbacct" variable. For some reason that I can't figure out it reuses the first iteration for the 2nd iteration's "qbacct" value. It's only the 2nd iteration. Everything else works fine, and that's what's perplexing. Usually it's a nothing works or everything works deal, not an arbitrary, just this guy doesn't work.

I did my best to show the Excel set up and the AHK result below, and attached a sample of my Excel file just in case. The second line in the result should be "02.10 Fill Dirt", but instead it's returning "02.30". Any ideas?

From Excel:

[The extension xlsx has been deactivated and can no longer be displayed.]

  • Pro Touch A-02 02.30 Land Clearing Inv 6494 2100.00
    Pro A-02 02.10 Fill Dirt Inv 6494 2700.00
    Pro Touch A-02 02.30 Land Clearing Inv 6494 650.00
    Pro Touch A-02 02.40 Grade Pad Inv 6494 350.00
    Pro Touch I-18 02.60 Rough Grade Inv 6493 200.00
    Pro Touch R-01 02.60 Rough Grade Inv 6495 200.00
AHK Output to QuickBooks:
  • 02.30 A-02: Inv 6494 - 02.30 Land Clearing 2100.00 A-02
    02.30 A-02: Inv 6494 - 02.30 2700.00 A-02
    02.30 A-02: Inv 6494 - 02.30 Land Clearing 650.00 A-02
    02.40 A-02: Inv 6494 - 02.40 Grade Pad 350.00 A-02
    02.60 I-18: Inv 6493 - 02.60 Rough Grade 200.00 I-18

Code: Select all

^!C::
	InputBox, copies,Bills Register Copier,How many lines need to be copied?`nCursor goes on the vendor name.
		Loop, %copies%
		{
			clipboard =
			Send, ^c
			ClipWait, 100
			vendor%A_Index% := RegExReplace(Clipboard,"\s*$")
			clipboard =
			sleep, 100
			
			send, {tab}^c
			ClipWait, 100
			jobnum%A_Index% := RegExReplace(Clipboard,"\s*$")
			clipboard =
			sleep, 100

			send, {tab}^c
			ClipWait, 100
			qbacct%A_Index% := RegExReplace(Clipboard,"\s*$")
			clipboard =
			sleep, 100
			
			send, {tab}^c
			ClipWait, 100
			Invoice%A_Index% := RegExReplace(Clipboard,"\s*$")
			clipboard =
			sleep, 100				

			send, {tab}^c
			ClipWait, 100
			amt%A_Index% := RegExReplace(Clipboard,"\s*$")
			clipboard =
			sleep, 100
			
			Send, {tab}{enter}
				if (a_index = copies)
					break
		}
return

Code: Select all

^!V::
	Loop, %copies%
	{
		amt := amt%a_index%
		invoice := invoice%a_index%
		jobnum := jobnum%a_index%
		qbacct := qbacct%a_index%
		StringLeft,qbacct2,qbacct,5
		sendinput, %qbacct2%
		sleep, 550
		SendInput,{tab}%jobnum%:  %invoice% - %qbacct%
		Sleep, 650
		SendInput, {tab}%amt%{Tab}%jobnum%
		Sleep, 550 
		SendInput,{tab}
		if (a_index = copies)
			break
	}
return
Trippet
Posts: 16
Joined: 08 Mar 2018, 13:37

Re: Loop Pulling 1st Variable's Data Into 2nd Iteration

08 Mar 2018, 23:36

Duh. Using qbacct2 as a variable kind of sort of breaks the script's a_index value's ability to work when I'm already using qbacct as a variable. By renaming qbacct2 to qbcat or Anything else that doesn't end in a number I will correct the issue. I needed a few hours away from the computer to let the brain rejuice. Hopefully this will help someone else have a V-8 moment in the future.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Joey5 and 171 guests