Sign in to follow this  
Followers 0
DrewSS

Looping logic

4 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm trying to get the second part my script starting with Local $GS1 to loop for the array $aArray, but it is only running once. What is the syntax or formatting i'm getting wrong?

#include <Excel.au3>
#include <Array.au3>
#include <File.au3>

$sFilePath1 = @ScriptDir & "\rebindtest.xls"  ; source targets
$sFilePath2 = @ScriptDir & "\test.txt"        ; destination target
$oExcel = _ExcelBookOpen($sFilePath1)         ; open excel sheet
$aArray = _ExcelReadSheetToArray($oExcel)     ; turns excel content into array

For $results = 0 To UBound($aArray) - 1       ; loops excel columns to copy files from 1 format into .ini format
    $chain = $aArray[$results][1]              ; column 1 is chain names    
    $store = $aArray[$results][2]              ; column 2 is store names    
    FileCopy(@ScriptDir & "\testsource\st" & $store & 'in.' & $chain, @ScriptDir & "\testinis\" & $chain & "-" & $store & ".ini") ;copies stSSSSin.CCC into CCC-SSSS.ini to be used for IniReadSection
Next

Local $GS1 = IniReadSection(@ScriptDir & "\testinis\" & $chain & "-" & $store & ".ini", "Group1") ; copies Group1 section the content from .ini file into a .txt file
    For $Group1 = 1 To $GS1[0][0]    ; Loops the whole Group1 section into 2 colums (key, and value)
    FileWrite($sFilePath2 ,  $GS1[$Group1][0] & " " & $GS1[$Group1][1] & @LF) ; Writes the key and values into a text file.
Next
_ExcelBookClose($oExcel)

The File copy works correctly, but FileWrite only write the last of the .ini files into the text file.

Edited by DrewSS

Share this post


Link to post
Share on other sites



Unless I am misunderstanding, you want to do your IniReadSection on each file, right after you copy it, right? To do so, you would want to add the $GS1 piece into the outer For loop, something like this:

#include <Excel.au3>
#include <Array.au3>
#include <File.au3>

$sFilePath1 = @ScriptDir & "\rebindtest.xls"  ; source targets
$sFilePath2 = @ScriptDir & "\test.txt"        ; destination target
$oExcel = _ExcelBookOpen($sFilePath1)         ; open excel sheet
$aArray = _ExcelReadSheetToArray($oExcel)     ; turns excel content into array

For $results = 0 To UBound($aArray) - 1       ; loops excel columns to copy files from 1 format into .ini format
    $chain = $aArray[$results][1]              ; column 1 is chain names    
    $store = $aArray[$results][2]              ; column 2 is store names    
    FileCopy(@ScriptDir & "\testsource\st" & $store & 'in.' & $chain, @ScriptDir & "\testinis\" & $chain & "-" & $store & ".ini") ;copies stSSSSin.CCC into CCC-SSSS.ini to be used for IniReadSection
        Local $GS1 = IniReadSection(@ScriptDir & "\testinis\" & $chain & "-" & $store & ".ini", "Group1") ; copies Group1 section the content from .ini file into a .txt file
            For $Group1 = 1 To $GS1[0][0]    ; Loops the whole Group1 section into 2 colums (key, and value)
                FileWrite($sFilePath2 ,  $GS1[$Group1][0] & " " & $GS1[$Group1][1] & @LF) ; Writes the key and values into a text file.
            Next
Next

_ExcelBookClose($oExcel)

If this is not correct, can you please explain in more detail what you would like to do step by step?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Is it possible to post the files you are using so I can run this?

Share this post


Link to post
Share on other sites

Hi,

Thanks for taking the time...

I've attached the files, but I had to edit the content to be used for example.

The script should grab a list of "store and chain" numbers as represented in 2 column excel sheet, with the store and chain numbers, it copies files into a .ini format. With the new .ini files, I want it to grab section "group1" and paste it into "test.txt" for each store in the original array (i.e. all the store and chains files).

 

 

test.zip

test2.au3

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
Sign in to follow this  
Followers 0