Jump to content

Second for loop not working


Recommended Posts

Hi guys 

I am trying to execute each version of a browser (first for loop) and get a version of each of the file database by using SQLite tool. (second loop) 

The first for loop seems to work fine. But when it goes into a second loop, the second for loop seems to stop after like 1~2 times of looping.

I could not find the reason for it.  

If I separate those loops into each au3 files,,then it seems to work fine...I'll show you guys the code..I'd appreciate it if anybody finds a solution

#include <Array.au3>
#include <File.au3>
;#include <MsgBoxConstants.au3>


Opt("WinTitleMatchMode", 2)
Global $result_file1 = "C:\Users\hello\Desktop\result.txt"
Local $sFilePath1 = "C:\test"
Local $sFilePath2 = "C:\test\User Data"

Local $aFileList = _FileListToArray($sFilePath1 , "test*", Default, True) ;get the whole path of files starting with 'test' under C;test  and put it in array
Local $aSaltList = _FileListToArrayRec($sFilePath2,  "file db",1, -2 , 1, 2) ; get the whole path of files named ' file db' under 2 depth of userdata  folder

For $i=1 to UBound($aFileList)-1
   Sleep(3000)
   ShellExecute($aFileList[$i])

   Local $hWnd = WinWait("chrome"," ",10)

   WinActivate($hWnd)

   Sleep(6500)

   WinClose($hWnd)

   Sleep(100)

   ProcessClose ("chrome.exe")


   Sleep(4000)

Next

For $j=2 to UBound($aSaltList)-1
   Sleep(3000)

   ShellExecute($aSaltList[$j]) ;;PROBLEM

   Sleep(2000)

   ;sqlite
   Open()

   Sleep(3000)

  ;run sql
   RunSql()

Next


Func Open() ;open sqlitespy

Sleep(3000)

Send("s")
Sleep(1500)
Send("{ENTER}")

EndFunc

Func RunSql() ;run a sql sentence and save the result in a result.txt file

   ControlClick("[CLASS:TfrmMain]","","[CLASS:TDISynEdit]")
   Send("select * from version {F9}")

   ControlClick("[CLASS:TfrmMain]","","[CLASS:TMemo]","left",2)
   Sleep(1500)
   Send("^c")

   Local $string1 = ClipGet()
   FileWrite($result_file1, $aSaltList[$j])
   FileWrite($result_file1, "    ")
   FileWriteLine($result_file1, $string1)

   ProcessClose ("SQLiteSpy.exe")

EndFunc

 

Edited by cherrylatte
Link to comment
Share on other sites

When posting code, please use AutoIt code tags (that's the "<>" button in the editor). Greatly enhances readability of your code ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The only thing I can see from the code here is that ShellExecute might not be starting the file(s) given to it from the array.

Test if it works on one file...

Find out what program starts/runs the DB ( I assume ) file you are trying to start and write the code accordingly.

Link to comment
Share on other sites

I assume the problem is caused by the Sleep statements followed by Send.
When the application isn't ready after the Sleep the Send statement will never reach the application.

I suggest to use UDFs to automate Chrome and SQLite. You will find them in the wiki:
https://www.autoitscript.com/wiki/User_Defined_Functions

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

On 2016. 8. 10. at 11:44 PM, water said:

I assume the problem is caused by the Sleep statements followed by Send.
When the application isn't ready after the Sleep the Send statement will never reach the application.

I suggest to use UDFs to automate Chrome and SQLite. You will find them in the wiki:
https://www.autoitscript.com/wiki/User_Defined_Functions

 

On 2016. 8. 10. at 8:57 PM, l3ill said:

The only thing I can see from the code here is that ShellExecute might not be starting the file(s) given to it from the array.

Test if it works on one file...

Find out what program starts/runs the DB ( I assume ) file you are trying to start and write the code accordingly.

Hi guys , I found out the reason why the second loop wasn't working.

It's because I miss placed below statement.

Local $aSaltList = _FileListToArrayRec($sFilePath2,  "file db",1, -2 , 1, 2) ; get the whole path of files named ' file db' under 2 depth of userdata  folder

 that statement has to be right after the end of first for_loop because the files supposed to be in aSaltList is not yet in complete state until the first for_loop finishes

anyways I appreciate for the help!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...