Sign in to follow this  
Followers 0
tarre

Read file over and over again from top to bottom and bottom to top

11 posts in this topic

like the topics says: Read file over and over again from top to bottom and bottom to top.

for example: this is helloWorld.txt

with this i can read each line from top to bottom

$x+=1

$line = FileReadLine($handle,$x)

Return $line

but when there is no more lines @error will turn to 1. in this case i want to FileReadLine but from Bottom to Top.

then i just put this code to do it backwards:

$CountLines = _FileCountLines($pfn)

if @error = 1 then

$x+=1

$line = FileReadLine($handle,$x)

Return $line

endif

here is the part i dont know how to do. when the Bottom to Top reading is over i want to switch back to my first read. with top to bottom.

thx.

Share this post


Link to post
Share on other sites



For $i = 1 To FileCountLines($file)
$line = FileReadLine($file,$i)
Next;read normally

For $i = FileCountLines($file) To 1 Step -1
$line = FileReadLine($file,$i)
Next;read backwards

Share this post


Link to post
Share on other sites

Small edit:

while 1
   For $i = 1 To FileCountLines($file)
      $line = FileReadLine($file,$i)
  Next;read normally

  For $i = FileCountLines($file) To 1 Step -1
    $line = FileReadLine($file,$i)
  Next;read backwards

wend

Now it's reading down,up,down,up,down,up.......


[center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center]

Share this post


Link to post
Share on other sites

For $i = 1 To FileCountLines($file)
$line = FileReadLine($file,$i)
Next;read normally

For $i = FileCountLines($file) To 1 Step -1
$line = FileReadLine($file,$i)
Next;read backwards
damn. forgot to tell that i want to make it read next line evrytime the function is called

;Read the line from top to bottom

$x+=1

$line = FileReadLine($handle,$x)

$value = read_text($line,'<',',')

;No more lines to read

$x-=1

$line = FileReadLine($handle,$x)

$value = read_text($line,'<',',')

return $value[0]

Share this post


Link to post
Share on other sites

damn. forgot to tell that i want to make it read next line evrytime the function is called

;Read the line from top to bottom

$x+=1

$line = FileReadLine($handle,$x)

$value = read_text($line,'<',',')

;No more lines to read

$x-=1

$line = FileReadLine($handle,$x)

$value = read_text($line,'<',',')

return $value[0]

You're making less sense, especially using functions we have no idea of what you're doing with (read_text()).

Also, why would you not just use _FileReadToArray()? Would make life much easier, and the process much faster.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

yeah my last post didnt make any sens to me to ><. read_text reading between text like this

$HowMuch = read_text('Harry got 44 points','Harry got','Points')

msgbox(0,'How much points does harry have?',$HowMuch[0])

yeah _FileReadToarray should use this instead. lol

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

i will try to explain better.

Global $xx,$pfn = 'mytext.txt'

Func _reader_()
    $xx+=1
    $handle = FileOpen($pfn,0)
    $line = FileReadLine($handle,$xx)

;Read between
    $value = read_text($line,'<',',')

if @error = 1 then
;error: no file to read since its end of the file
;somewhere inhere i want to read it from bottom to top
else
    return $value[0];No error and will return the Textline $xx
endif

endfunc

when the filereadLine hits the end i want it to read it from bottom to top instead. and when fileReadLine hits the top again i want it to read from top to bottom. and i just want the $xx to increese evrytime i call the funcion _reader_

did this make it clear how i want it?

Edited by tarre

Share this post


Link to post
Share on other sites
:) darn Anyone?

Share this post


Link to post
Share on other sites

:) darn Anyone?

Your going to have to wait for someone smarter than me. I still don't know what you want to do.

In my mind I see you reading like this (assume there are only 3 lines)

1

2

3

2

3

2

3

2

3

I just see it repeating over and over.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

its like 48 lines. and evrytime i call the function i want to read next line. but when its at the bottom and i call the function again i want to read the last line etc etc. and when its on the top again i want to read down.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

its like 48 lines. and evrytime i call the function i want to read next line. but when its at the bottom and i call the function again i want to read the last line etc etc. and when its on the top again i want to read down.

Local $s_file_location_name = "passlist_checked_old_.txt"
Local $i_count_lines = 1, $f_direction = True, $s_print

; This isn't neccessary to read the file ahead of time, but will save on resources if the file isn't going to change
; If the file is going to change, instead of passing $s_read in the first parameter, put $s_file_location_name there
Local $s_read = FileRead($s_file_location_name)

While 1
    $s_print = _myScrewedUpScenerio($s_read, $i_count_lines, $f_direction)
    ConsoleWrite($s_print & @CRLF)
    Sleep(500)
WEnd

Func _myScrewedUpScenerio($s_file, ByRef $i_line, ByRef $f_down)
    
    If FileExists($s_file) Then $s_file = FileRead($s_file)
    
    Local $a_split = StringSplit(StringStripCR($s_file), @LF)


    If $f_down And $i_line > $a_split[0] Then
        $i_line = $a_split[0]
        $f_down = False
    ElseIf Not $f_down And $i_line < 1 Then
        $f_down = True
        $i_line = 1
    EndIf
    
    Local $i_ret = $i_line
    
    If $f_down Then
        $i_line += 1
        Return $a_split[$i_ret]
    EndIf
    
    $i_line -= 1
    Return $a_split[$i_ret]
EndFunc

Edit:

BTW, would have been easier to say you were going for a scroll effect.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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