Jump to content

ReadLines of txt file and assign values for each line one at a time

Recommended Posts

Hey Everybody, So I am currently writing a script to help determine outcome probabilities I have most of the script written but where i seem to be running into the difficulties is when trying to read a txt file one line at a time where each line will return the txt from the file and then depending on the number i have if then statements for the script to play out. I have tried every FileReadLine forum post and created a notepad txt file even just for testing called readtest.txt its able to read the first line "13" but then I get ^ Error 1 >Exit code:1 no matter what i do. like I said I've used every test for it that I can find on the forum and still the same happens. I dont even know where to begin at this point because nothing seems to be working. This is where I am at I hope someone can figure out where i go from here or how to accomplish this:

#include <readtest.txt>

$Variable = CurrentLineText

$file = "c:\readtest.txt"


$CurrentLine =1

FileOpen($file, 0)


FileReadLine $CurrentLine

If $Variable = X Then  ;X is any number between 1 and 17

     $Number = X

     $CurrentLine = $CurrentLine + 1

ElseIf $Variable = "Next Set of Actions" Then

     $CurrentLine = $CurrentLine +1

     (Clean Slate) 





           If $Variable = 1 Then

                     $OutCome= thing 

           If $Variable = 17 Then

                     $OutCome = different thing


           FileOpen($file2, 0)

           Type in last line $Outcome

           Send (Enter) for a new line for next scenario to be played out and recorded





     ... : resetting all the other variables back to starting


I Hope this helps and if i need to clarify anything or if i missed something vital in my description then please let me know. thanks in advance.

Link to comment
Share on other sites

Hello @Jecht0dyssey

welcome to the forum.

When you want to process a whole file line by line pls. have a look at the function _FileReadToArray()


When posting code, pls use the according button in the edidor's pane here: Button "< >"

The code you posted has several function declarations nested into each other, which are not closed using "EndFunc". Use the SciTE Autoit customized editor and CTRL+t to bring up the messages poining out the missing function closings.

Functions should (have to?) be written in one block, one by another, not nested.




Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

  • Developers

My suggestion would be to use au3check first before tidy to get better autoit3 issues listed first, like NO Funcs within an Func.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...