cherrylatte

Second for loop not working

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 ;)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.

1 person likes this

Share this post


Link to post
Share on other sites
3 hours ago, water said:

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

thanks I changed it

Share this post


Link to post
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

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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!

Share this post


Link to post
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

  • Similar Content

    • Szmycu
      By Szmycu
      Hello i Have HP Bar in my game and it has 170px of width and then im gonna find start of this by mouse pos then i got $hpStart[0] = 661  $hpStart[1] = 230 ,  $hpEnd[0] = 839
      And there is from $hpStart[0] = 661 the same color - 0xCB423B but depends of my points of hp for example on pixel  $hpStart[0] = 745 would be another color not  0xCB423B and then i will know my my character got 50% of health points.
       
      I encountered problem here - for loop still looping to 839 and not founding this change in color for example on pixel $hpStart[0] = 745
      I would know actual $i counter and $hpEnd[0] then only i can calculate current health percent value 
       
      Please help me how to achieve that! Thanks for any help
       
      Func MouseCord() $MousePos = MouseGetPos() global $hpStart = $MousePos global $hpEnd = $hpStart $hpEnd[0] = $hpEnd[0] + 170 For $i = $hpStart[0] To $hpEnd[0] ; Looping from 661 to 839 $pixel = PixelGetColor($i,$hpStart[1]) If $pixel <> 0xCB423B Then $hpNowPer = ( $hpEnd[0] - $i ) / 170 $hpPoOdjeciu = 1 - $hpNowPer $hpNowPercent = Round($hpPoOdjeciu,2) ExitLoop ; - that not working EndIf Next EndFunc  
       
    • 232showtime
      By 232showtime
      Good day,
      is it possible to make a For Loop infinite,
      ho do i make a for loop infinite??? using the script below
      For $i = 0 To 10 Msgbox(64, "Succes", $i) Next  
    • Relive
      By Relive
      An IE link collection $oLinks is being looped by a $oLink with a for-in loop. An if statement is used such that when the $oLink.href matches a string reg. exp., it will do a set of statements. The set of statements is this:

      $a = 1 do $matchpic = StringRegExp($oLink + $a.href, '(http://t2.imgchili.com/)(\d+)(\/)(\d+)(_)') $a += 1 until $matchpic = 1 But the error is that $a is not an object variable.

      After a match has been found, this $oLink is _paused_ at the current position inside this collection (I believe). How do I loop at the current $oLink?
    • BrewManNH
      By BrewManNH
      Here's a piece of code:

      Global $Array[5] = ["AA", "BB", "CC", "DD", "EE"] For $I = 2 To $Array ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $I = ' & $I & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next The results for this piece of code are very strange:

      Is this a bug with the For code, in that it's acting somewhat like a For/Next loop, and somewhat like a For/In/Next loop? By the way, it doesn't matter what the first number in the loop is, I used 2 as an example, it will always output the same. It takes the number you started the loop at, and then the variable will hold the contents of the second through the last array elements.
      On a 2D array, it still doesn't work as expected, but it works differently than how I'd expect it to.


      Global $Array[5][2] = [["AA", "1"], ["BB", 2], ["CC", 3], ["DD", 4],["EE", 5]] For $I = 10 To $Array ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $I = ' & $I & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next This outputs:

      Which is 5 instances of $ being 10, which seems to be a quick way of looping through an array if you don't need to access the contents of the array.
    • amymichellea
      By amymichellea
      I've been using AutoIt for about the past two weeks. The code I've created is supposed to open an excel file, combine the first two columns of information into a third column. Then take that new information from the third column and input it into a url. Finally, it saves the file as a .csv and closes it. This code is going to be run everyday at the end of the day and that's where my problem starts.

      Currently, I've got a code that works but I've got a For loop right now that has defined parameters and I think what I really want is a While loop. The number of rows that will exist in the excel file will change on a daily basis, and that's why I think I need a While loop so I can tell it to continue combining the information from the first two columns until the rows stop.

      I've tried searching this forum and the rest of the internet for an answer to my problem and all I've found are examples closer to mine from 2007 or 2008. Unfortunately, they mention a function called "_ExcelSheetUsedRangeGet" which when inputted into AutoIt gives me an error about the function not existing. I also can't find the function in a help file, so I don't know where to go from here. And I tried reading up on the post titled "Yet Another -- ExcelCOM UDF" but that didn't help me either.

      Any and all help would be greatly appreciated.

      Here's my code that's working with the For loop:


      ; ***************************************************************
      ; This should open an excel file with "NameCurrentDate."
      ; The excel file starts with two columns, "HobsonsID" and "TourDate"
      ; This creates a third column called "URL Code" that is a combination of Column 1 and 2
      ; Then it creates a fourth column called "URL"
      ; This column contains the URL to the QR Code with the personalized information
      ; Then it saves the file as a .csv.
      ; *****************************************************************

      #include <Excel.au3>

      $today = @MON & "." & @MDAY & "." & @YEAR;
      $sFilePath1 = @ScriptDir & "\TourRecon" & $today & ".xlsx" ;This file should already exist
      $oExcel = _ExcelBookOpen($sFilePath1)

      If @error = 1 Then
      MsgBox(0, "Error!", "Unable to Create the Excel Object")
      Exit
      ElseIf @error = 2 Then
      MsgBox(0, "Error!", "File does not exist - Shame on you! The path you gave me is" & $sFilePath1)
      Exit
      EndIf

      _ExcelWriteCell($oExcel, "URL Code", 1, 3) ;Puts the Column header "URL Code" in the first row, Column 3

      For $i = 2 To 8 ;Loop
      _ExcelWriteCell($oExcel, "=A" & $i & "&-B" & $i, $i, 3) ;Combines Column 1 and Column 2, puts output in Column 3
      Next

      _ExcelWriteCell($oExcel, "URL", 1, 4) ;Puts the Column header "URL" in the first row, Column 4

      For $j = 2 To 8 ;Loop
      _ExcelWriteCell($oExcel, "=CONCATENATE(CONCATENATE(""http://admissions.calpoly.edu/"", C" & $j & "), "".html"")", $j, 4) ;Write to the Cell
      Next ;This puts a URL into Column 4, starting at Row 2

      $sFilePath = @ScriptDir & "\TourRecon" & $today & ".csv";
      $sType = "csv";
      _ExcelBookSaveAs($oExcel, $sFilePath, $sType)
      If Not @error Then MsgBox(0, "Success", "File was Saved!", 3)