TylerH Posted June 21, 2016 Posted June 21, 2016 (edited) I have the following code that successfully reads the amount of files in a folder: $hNumberofFiles = 0 Func _UBound($hNumberofFiles) Global $n Global $hPath = "T:\" $hNumberofFiles = _FileListToArray($hPath, "*.tif", 1) For $n=UBound($hNumberofFiles) - 1 to 0 Step -1 If StringLen($hNumberofFiles[$n]) > 0 Then ExitLoop Next Return $n EndFunc $hFileCount = _UBound($hNumberofFiles) (I tested it via a MsgBox returning _UBound($hNumberofFiles), which returned the correct number) However, I can't seem to write a working loop to check for an increase in the number of files: $hFileCountNew = $hFileCount MouseClick("", 280, 420, 1, 10) ;Clicks a button to print files to a virtual printer AKA it writes files to a folder Sleep(700) While $hFileCountNew <= _UBound($hNumberofFiles) ;If the number of files is still the same, then the report is still loading, so just wait and check again in three seconds Sleep(3000) WEnd Specifically, the while loop doesn't seem to be working, so the script just sleeps forever/goes idle. Edited June 21, 2016 by TylerH
TylerH Posted June 21, 2016 Author Posted June 21, 2016 Sorry all, I've solved my own problem by replacing the While Loop with a Do ... Until loop: Do ;If the number of files is still the same, then the report is still loading, so just wait and check again in three seconds Sleep(3000) Until _UBound($hNumberofFiles) > $hFileCount
Moderators JLogan3o13 Posted June 21, 2016 Moderators Posted June 21, 2016 @TylerH another option, fewer lines: #include <File.au3> #include <MsgBoxConstants.au3> While 1 MsgBox($MB_OK, "", _findFileNum()) Sleep(1000) WEnd Func _findFileNum() Local $sPath = @DesktopDir & "\Test" Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES) Return UBound($aFiles) - 1 EndFunc TylerH 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
TylerH Posted June 21, 2016 Author Posted June 21, 2016 1 minute ago, JLogan3o13 said: @TylerH another option, fewer lines: #include <File.au3> #include <MsgBoxConstants.au3> While 1 MsgBox($MB_OK, "", _findFileNum()) Sleep(1000) WEnd Func _findFileNum() Local $sPath = @DesktopDir & "\Test" Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES) Return UBound($aFiles) - 1 EndFunc Wouldn't the While loop have to be after the Func? Otherwise it would be calling an undefined function, no?
Moderators JLogan3o13 Posted June 21, 2016 Moderators Posted June 21, 2016 @TylerH, no AutoIt does not require your funcs to be above the calling point. In fact, as you look through examples in the help file and on the forum you will see most often they are put at the bottom, with your main body of code calling them. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
RyukShini Posted June 21, 2016 Posted June 21, 2016 1 hour ago, JLogan3o13 said: @TylerH, no AutoIt does not require your funcs to be above the calling point. In fact, as you look through examples in the help file and on the forum you will see most often they are put at the bottom, with your main body of code calling them. I can vouch for this! I wrote something once and all my functions were in the bottom of my script.
TylerH Posted June 21, 2016 Author Posted June 21, 2016 1 hour ago, JLogan3o13 said: @TylerH another option, fewer lines: #include <File.au3> #include <MsgBoxConstants.au3> While 1 MsgBox($MB_OK, "", _findFileNum()) Sleep(1000) WEnd Func _findFileNum() Local $sPath = @DesktopDir & "\Test" Local $aFiles = _FileListToArray($sPath, "*.tiff", $FLTA_FILES) Return UBound($aFiles) - 1 EndFunc By the way, I don't need to create a MsgBox; I just need to store the number of files as a variable so that the rest of my code waits until the number of files != the variable stored at the beginning of the snippet.
Moderators JLogan3o13 Posted June 21, 2016 Moderators Posted June 21, 2016 (edited) It was just an example, you can put the value into a var at the beginning, and then constantly check against it in the While loop Edited June 21, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
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