Uzo Posted April 3, 2022 Share Posted April 3, 2022 Hi, How can I fix the code below so that it runs? Thanks much #include <ScreenCapture.au3> $chartFolder = "C:\Scripts\deepdive\" $tickerFile = "C:\Scripts\tickers.txt" $chartWinTitle = "TC2000 – Naked Charts" $chartWidth = 1280 $chartHeight = 720 ;========================================================================== ; Do not modify code below unless you are sure ; Open ticker file to read Local $hFileOpen = FileOpen($tickerFile, $FO_READ) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the ticker file: " & $tickerFile ) Exit 1 EndIf ; create the chart folder If DirCreate ($chartFolder) = 0 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when creating folder: " & $chartFolder ) Exit 1 EndIf ; read and process ticker one by one $line = FileReadLine($hFileOpen) While Not @error $A = StringLower ($line) $hGUI = WinActivate($chartWinTitle) MsgBox($MB_SYSTEMMODAL, "", "An error occurred when activating window: " & $chartWinTitle) Exit 1 If $hGUI = 0 Then Endif Send($A & "{ENTER}") ; resize the window to specified size for the chart image ; this also slows down the code a bit such that the window is ready for capture $hGUI = WinActivate($chartWinTitle) WinMove($hGUI, "", 0, 0, $chartWidth, $chartHeight) ; avoid mouse on chart $x = MouseGetPos(0) $y = MouseGetPos(1) MouseMove(0, $chartHeight+20) if($x <= $chartWidth and $y <= $chartHeight) Then Endif ; capture window and save to a file $JFile = $chartFolder & $line & ".png" FileDelete($JFile) ; wait for the chart to load. Necessary for slow network ;Sleep(500) _ScreenCapture_CaptureWnd($JFile, $hGUI) If StringLen($line) <> 0 Then Endif $line = FileReadLine($hFileOpen) WEnd Exit 0 Link to comment Share on other sites More sharing options...
jitb Posted April 3, 2022 Share Posted April 3, 2022 The only thing I see is MsgBox($MB_SYSTEMMODAL, "", "An error occurred when activating window: " & $chartWinTitle) Exit 1 should be 2 lines MsgBox($MB_SYSTEMMODAL, "", "An error occurred when activating window: " & $chartWinTitle) Exit 1 Try And Link to comment Share on other sites More sharing options...
Subz Posted April 3, 2022 Share Posted April 3, 2022 Unsure why you have blank if statements, also if @error occurs anytime within the While/Wend it would fail, would be better to use something like: expandcollapse popup#include <ScreenCapture.au3> $chartFolder = "C:\Scripts\deepdive\" $tickerFile = "C:\Scripts\tickers.txt" $chartWinTitle = "TC2000 – Naked Charts" $chartWidth = 1280 $chartHeight = 720 ;========================================================================== ; Do not modify code below unless you are sure ; Open ticker file to read Local $hFileOpen = FileOpen($tickerFile, $FO_READ) If $hFileOpen = -1 Then _Exit(1, "", "An error occurred when reading the ticker file: " & $tickerFile ) ; create the chart folder If DirCreate ($chartFolder) = 0 Then _Exit(1, "", "An error occurred when creating folder: " & $chartFolder) ;~ ; read and process ticker one by one $line = FileReadLine($hFileOpen) Local $iError = @error While Not $iError $A = StringLower ($line) $hGUI = WinActivate($chartWinTitle) If @error Then _Exit(1, "", "An error occurred when activating window: " & $chartWinTitle) Send($A & "{ENTER}") ; resize the window to specified size for the chart image ; this also slows down the code a bit such that the window is ready for capture $hGUI = WinActivate($chartWinTitle) WinMove($hGUI, "", 0, 0, $chartWidth, $chartHeight) ; avoid mouse on chart $x = MouseGetPos(0) $y = MouseGetPos(1) MouseMove(0, $chartHeight+20) ; capture window and save to a file $JFile = $chartFolder & $line & ".png" FileDelete($JFile) ; wait for the chart to load. Necessary for slow network ;Sleep(500) _ScreenCapture_CaptureWnd($JFile, $hGUI) $line = FileReadLine($hFileOpen) $iError = @error WEnd _Exit(0) Func _Exit($_iErrorCode, $_sTitle = "", $_sMessage = "") If $_sMessage <> "" Then MsgBox($MB_SYSTEMMODAL, "", $_sMessage) Exit $_iErrorCode EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now