What's wrong with this code?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

What's wrong with this code?

Post by Tourless » Thu Jul 06, 2017 4:10 pm

Hi Folks,

I'm back at it and trying to figure out where I went wrong with this block of code. What I'm trying to accomplish is checking the resulting window for one of two results. Either way I want the text of that windows captured and written to a file. What I'm getting is both scenarios being assumed true and I get a modal message for both QB Info Detected and Warning Detected regardless of the result. What happens is if the QB window is properly detected, the statement should move on bypassing the if statement for the warning but it does not and causes an error that my script can't continue because it didn't find what it thought it was supposed to be looking for, ie the warning window. Any help is greatly appreciated...

Label>ImportLoop
Let>k=0
Repeat>k
Let>k=k+1
Press ALT
Wait>.2
Send>f
Wait>.2
Send>u
Wait>.2
Send>i
Wait>.2
Send>i
Release ALT

WaitWindowOpen>Import
Wait>.3

ExtractFileName>file_names_%k%,TheName
UIFocus>{"Import"},{"File name:"}
UISetValue>Import,File name:,TheName
Press ALT
Wait>.2
Send>o
Release ALT
Wait>2

GetActiveWindow>title,X,Y,W,H
IF>title=QuickBooks Information
GetDate>Date
GetTime>Time
WriteLn>C:\LMQB_In\import.log,result,%Date% - %Time% - %TheName% Successfully Imported.
MessageModal>QB Info Detected
SetFocus>QuickBooks Information
Wait>.2
Press Enter
Wait>.2
IF>title=Warning
GetDate>Date
GetTime>Time
WriteLn>C:\LMQB_In\import.log,result,%TheName% Failed @ %Date%-%Time% with the following warning...
MessageModal>Warning Detected
SetFocus>Warning
Wait>.2
Press Enter
Wait>.2
SetFocus>Warning
GetActiveWindow>title,X,Y,W,H
ScreenCapture>x,Y,{%X%+%W%},{%Y%+%H%},%TEMP_DIR%\~scrn.bmp
//Use OCR to get text from active window
VBEval>DoOCR("%TEMP_DIR%\~scrn.bmp"),TheText
//Display the text
GetDate>Date
GetTime>Time
WriteLn>C:\LMQB_In\import.log,result,%TheText%
MessageModal>TheText
//GetControlText>Warning*,Warning,1,C:\LMQB_In\import.log
ENDIF
ENDIF

MoveFile>file_names_%k%,C:\LMQB_Out\%TheName%

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: What's wrong with this code?

Post by JRL » Thu Jul 06, 2017 6:22 pm

Try adding %title% to your modal message so you know what title is actually being captured. Might give you a clue. Also be aware that the window title must match exactly character for character in your if> statements. No wildcards available and close isn't good enough.

I could see no good reason for the if> statements to be nested so I broke them into two separate blocks.

Also, I assume the Repeat> has an Until> that you left out of the posted code.

And... you seemed to be fairly competent "talking to yourself".

Code: Select all

Label>ImportLoop
Let>k=0
Repeat>k
Let>k=k+1
Press ALT
Wait>.2
Send>f
Wait>.2
Send>u
Wait>.2
Send>i
Wait>.2
Send>i
Release ALT
WaitWindowOpen>Import
Wait>.3
ExtractFileName>file_names_%k%,TheName
UIFocus>{"Import"},{"File name:"}
UISetValue>Import,File name:,TheName
Press ALT
Wait>.2
Send>o
Release ALT
Wait>2

GetActiveWindow>title,X,Y,W,H
IF>title=QuickBooks Information
  GetDate>Date
  GetTime>Time
  WriteLn>C:\LMQB_In\import.log,result,%Date% - %Time% - %TheName% Successfully Imported.
  MessageModal>QB Info Detected%crlf%Window title = %title%
  SetFocus>QuickBooks Information
  Wait>.2
  Press Enter
  Wait>.2
EndIf

IF>title=Warning
  GetDate>Date
  GetTime>Time
  WriteLn>C:\LMQB_In\import.log,result,%TheName% Failed @ %Date%-%Time% with the following warning...
  MessageModal>Warning Detected%crlf%Window title = %title%
  SetFocus>Warning
  Wait>.2
  Press Enter
  Wait>.2
  SetFocus>Warning
  GetActiveWindow>title,X,Y,W,H
  ScreenCapture>x,Y,{%X%+%W%},{%Y%+%H%},%TEMP_DIR%\~scrn.bmp
  //Use OCR to get text from active window
  VBEval>DoOCR("%TEMP_DIR%\~scrn.bmp"),TheText
  //Display the text
  GetDate>Date
  GetTime>Time
  WriteLn>C:\LMQB_In\import.log,result,%TheText%
  MessageModal>TheText
  //GetControlText>Warning*,Warning,1,C:\LMQB_In\import.log
EndIf

MoveFile>file_names_%k%,C:\LMQB_Out\%TheName%

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: What's wrong with this code?

Post by Tourless » Thu Jul 06, 2017 8:16 pm

Try adding %title% to your modal message so you know what title is actually being captured.
I didn't think of that thanks! I guess all the nesting did was confuse the issue. Yeah, the Repeat does have an Until.

And thanks for the vote of competence :wink:

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts