Jump to content

Reading from a text file - many lines


 Share

Recommended Posts

Hi,

Does anyone have a more efficient way of doing this?

CODE

$line1 = FileReadLine($file, 1)

$line2 = FileReadLine($file, 2)

$line3 = FileReadLine($file, 3)

$line4 = FileReadLine($file, 4)

$line5 = FileReadLine($file, 5)

$line6 = FileReadLine($file, 6)

$line7 = FileReadLine($file, 7)

$line8 = FileReadLine($file, 8)

$line9 = FileReadLine($file, 9)

$line10 = FileReadLine($file, 10)

$line11 = FileReadLine($file, 11)

$line12 = FileReadLine($file, 12)

$line13 = FileReadLine($file, 13)

$line14 = FileReadLine($file, 14)

$start = GUICtrlCreateLabel('School Diary' & @LF & $line1 & @LF & $line2 & @LF & $line3 & @LF & $line4 & @LF & $line5 & @LF & $line6 & @LF & $line7 & @LF & $line8 & @LF & $line9 & @LF & $line10 & @LF & $line11 & @LF & $line12 & @LF & $line13 & @LF & $line14 & @LF & $line15 & @LF & $line16 & @LF & $line17 & @LF & $line18 & @LF & $line19 & @LF & $line20 & @LF & $line21 & @LF & $line22 & @LF & $line23 & @LF & $line24 & @LF & $line25 & @LF & $line26 & @LF & $line27 & @LF & $line28 & @LF & $line29 & @LF & $line30 & @LF & $line31 & @LF & $line32 & @LF & $line33 & @LF & $line34 & @LF & $line35 & @LF & $line36 & @LF & $line37 & @LF & $line38 & @LF & $line39 & @LF & $line40,5,3,200,1000)

I read in the functions descriptions that to loop through increasing the ReadLine variable was inefficient as it always reads from the first line, have I got the wrong end of the stick?

Thanks

Edited by icedearth
Link to comment
Share on other sites

Thanks for that,

But how would I iterate through the array inside the GuiCreateLabel ???

Im a bit new to AutoIT, coming from PHP, i know what I want to do, but it takes me ages to get there!

Thanks again!

Dim $array[15]

For $i = 0 To 14
    
    $array[$i] = FileReadLine("file.txt", $i+1)
    
Next

this way maybe

Link to comment
Share on other sites

See _FileReadToArray() function

$array = ""
_FileReadToArray("somepath|somefile.txt", $array)
For $I = 1 to 14;; or whatever number of lines or Ubound($array) -1
   MsgBox(4096, "Array Output", $array[$I])
Next

And Yes, FileReadLine is the least efficient of all the methods for the reason that you outlined.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Cheers thats nice and efficient for filling the array with the lines in the text file, the only problem I have now is iterating through the array inside the GUICtrlCreateLabel. I tried this, but I was just grasping at straws as I knew it wouldnt work.

$array = ""

_FileReadToArray("calender.txt", $array)

For $I = 1 to 31;; or whatever number of lines or Ubound($array) -1

$start = GUICtrlCreateLabel('School Diary' & @LF & $array[$I] ,5,3,200,1000)

Next

Is there any other functions that would do this sort of thing?

See _FileReadToArray() function

$array = ""
_FileReadToArray("somepath|somefile.txt", $array)
For $I = 1 to 14;; or whatever number of lines or Ubound($array) -1
   MsgBox(4096, "Array Output", $array[$I])
Next

And Yes, FileReadLine is the least efficient of all the methods for the reason that you outlined.

Link to comment
Share on other sites

From your example you are just puting text into the label in the order as it's read from the file. Providing its not too many lines, what about just doing this

#include <GUIConstants.au3>
GUICreate("", 600, 600)  
GUICtrlCreateLabel("Some Text" & @CRLF & FileRead("c:\some.txt"), 10, 10, 580, 580)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Link to comment
Share on other sites

Perfect!!

Thanks, that did the trick great!

Thanks for all your input guys, appreciate it.

AutoIT is very addictive!!

From your example you are just puting text into the label in the order as it's read from the file. Providing its not too many lines, what about just doing this

#include <GUIConstants.au3>
GUICreate("", 600, 600)  
GUICtrlCreateLabel("Some Text" & @CRLF & FileRead("c:\some.txt"), 10, 10, 580, 580)
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Link to comment
Share on other sites

Cheers thats nice and efficient for filling the array with the lines in the text file, the only problem I have now is iterating through the array inside the GUICtrlCreateLabel. I tried this, but I was just grasping at straws as I knew it wouldnt work.

$array = ""

_FileReadToArray("calender.txt", $array)

For $I = 1 to 31;; or whatever number of lines or Ubound($array) -1

$start = GUICtrlCreateLabel('School Diary' & @LF & $array[$I] ,5,3,200,1000)

Next

Is there any other functions that would do this sort of thing?

$array = ""
$lblTxt = ""
_FileReadToArray("calender.txt", $array)
For $I = 1 to 31;; or whatever number of lines or Ubound($array) -1
  $lblTxt &= $array[$I]
Next
$start = GUICtrlCreateLabel('School Diary' & @LF & $lblTxt ,5,3,200,1000)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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

  • Recently Browsing   0 members

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