Jump to content
hmdan2

Entering data from 5 text files into GUI, one line of each file per loop. I'm stuck.

Recommended Posts

hmdan2

Hello everyone,

I am quite new to AutoIT and scripting, so I apologize in advance if my question is dumb. I hope I can explain it well.

I am working with BrainVoyager, software for MRI data analysis. I need to automate a process with AutoIT that requires manual selection of 5 different files for each subject, 80+ subjects in total. The analysis needs to run for each subject separately. I am attaching the GUIs for clarity. 
 
What I want to achieve is have AutoIT click on the "Browse..." and "Add" buttons, and enter each file path for me. 
 
My idea was to have 5 separate txt files. Each of them has 80 lines, and each line contains the path to one subject's data. I wanted to make it so for each loop, only the first line from the 5 txt files is entered in the system dialogue, then only the second, then the third, until it reaches the end. 
 
I got stuck on figuring out how to do this with more than one file. I've previously used the below code to do the same for just one txt file, and I don't quite know how to modify it. I would very much appreciate your guidance, and thank you so much in advance!
 
$file = "D:\AutoIT\data.txt"


FileOpen($file, 0)
Global $filenames[_FileCountLines($file)
For $ii = 1 to _FileCountLines($file)
    $filenames[$ii-1] = FileReadLine($file, $ii)
Next
FileClose($file) 


for $fc= 0 To (UBound($filenames)-1)


Next
 

 

1.png

2.png

Share this post


Link to post
Share on other sites
Deye

Welcome to the autoit forum

Do you need to process 5 paths at each run ?
Please give an example of five paths in two or three lines, so we can see a pattern or the relation

path1, path2, path3, path4, path5
path1 ...

 

Edited by Deye

Share this post


Link to post
Share on other sites
kylomas

hmdan2,

The code you posted does not do anything.  Also the array declaration is wrong.  Here is an example of populating 5 controls on a gui from 5 different files...

#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

; create test files

Local $str
For $1 = 1 To 5
    For $2 = 1 To 80
        $str &= 'File ' & $1 & ' line ' & StringFormat('%02i', $2) & @CRLF
    Next
    FileWrite(@ScriptDir & '\test file #' & $1 & '.txt', $str)
    $str = ''
Next

; create a gui with 5 edit controls for display purposes

Local $left = 10
Local $gui010 = GUICreate('5 file test', 570)

Local $actlids[5]
For $1 = 0 To 4
    $actlids[$1] = GUICtrlCreateEdit('', $left, 10, 110, 300)
    $left += 110
Next

GUISetState()

; read each file to an edit control

For $1 = 1 To 5
    GUICtrlSetData($actlids[$1 - 1], FileRead(@ScriptDir & '\test file #' & $1 & '.txt'))
Next

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
    EndSwitch
WEnd

Needless to say, this is one of many ways to do this, if this is what you want.  If not, it may give you some ideas.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
gruntydatsun

here's another way...
 

#include <file.au3>
#include <array.au3>

$Form1 = GUICreate("Form1", 320, 133, 192, 124)
$txt1 = GUICtrlCreateInput("field1", 16, 8, 289, 21)
$txt2 = GUICtrlCreateInput("field2", 16, 32, 289, 21)
$txt3 = GUICtrlCreateInput("field3", 16, 56, 289, 21)
$txt4 = GUICtrlCreateInput("field4", 16, 80, 289, 21)
$txt5 = GUICtrlCreateInput("field5", 16, 104, 289, 21)
GUISetState(@SW_SHOW)

MakeDataFiles()

;arrays to hold contents of files
Dim $aF1, $aF2, $aF3, $aF4, $aF5

;read files to array
_FileReadToArray(@ScriptDir & "\file1.txt",$aF1)
_FileReadToArray(@ScriptDir & "\file2.txt",$aF2)
_FileReadToArray(@ScriptDir & "\file3.txt",$aF3)
_FileReadToArray(@ScriptDir & "\file4.txt",$aF4)
_FileReadToArray(@ScriptDir & "\file5.txt",$aF5)

;write a line from each file to gui
for $x = 1 to 80
    for $y = 1 to 5
        GUICtrlSetData($txt1,$aF1[$x])
        GUICtrlSetData($txt2,$aF2[$x])
        GUICtrlSetData($txt3,$aF3[$x])
        GUICtrlSetData($txt4,$aF4[$x])
        GUICtrlSetData($txt5,$aF5[$x])
    Next
    Sleep(100)
Next

;delete data files
for $x = 1 to 5
    FileDelete(@ScriptDir & "\file" & $x & ".txt")
Next


;like it says
Func MakeDataFiles()
    for $x = 1 to 5
        if FileExists(@ScriptDir & "\file" & $x & ".txt") then return 0
    next

    local $filecontents
    for $y = 1 to 5                         ;file number
        $filecontents = ""
        for $x = 1 to 80                    ;line number
            $filecontents &= "File " & $y & "  -  Line " & $x & @CRLF
        Next
        FileWrite(@ScriptDir & "\file" & $y & ".txt",$filecontents)
    Next
    Return 1
EndFunc

 

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.