Jump to content

FileReadLine


 Share

Recommended Posts

I've been using FileReadLine() to read in lines of data that takes user input and compares it to the file being read. I recently updated the file and noticed that I get an array error after having made the file go past 64KB. After Googling for an answer it looks like there was a cap put on older versions but was removed.

I'm wondering if the cap got put back on the latest release, as that is what I've been working with.

The other weird thing is, I've changed my function that reads in the text file to use FileRead() instead, however it stops at the exact same spot.

I'm stumped and any help would be appreciated.

Link to comment
Share on other sites

  • Moderators

autoitFR,

Welcome to the AutoIt forum. :)

If you could post your code (please put [autoit] before and [/autoit] after your posted code) and let us know if there is anything special about the file you are trying to read, we might be able to offer some sensible help. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here's two versions that worked prior to adding more information to the info.txt file I read in. When it stops on the last line, it only displays half of what that line actually contains. There's nothing special about the info.txt file. There's an item name with two item numbers which are separated with |.

ITEMNAME|ITEMNUM1|ITEMNUM2

ITEMNAME|ITEMNUM1|ITEMNUM2

ITEMNAME|ITEMNUM1|ITEMNUM2

Func _findmyitem($x1, $y1, $x2, $y2)
    Local $item_to_check, $file, $line, $result, $CNF
    $CNF = "ITEM NOT FOUND"
    $item_to_check = "ITEM NUMBER"

    $file = FileOpen("info.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open info.txt.")
        Exit
    EndIf

    While 1
        $chars = FileRead($file)
        If @error = -1 Then ExitLoop
        $line = StringSplit($chars, @CRLF, 1)
        If $line[1] = "" Then ExitLoop
        For $x = 1 to $line[0]
            $result = StringSplit($line[$x], "|", 1)
            If StringCompare($result[2], $item_to_check, 2) == 0 OR StringCompare($result[3], $item_to_check, 2) == 0 Then
                FileClose($file)
                Return $result[1]
            EndIf
        Next
    WEnd
    FileClose($file)
    Return $CNF
EndFunc

Func _findmyitem($x1, $y1, $x2, $y2)
    Local $item_to_check, $file, $line, $result, $CNF
    $CNF = "ITEM NOT FOUND"
    $item_to_check = "ITEM NUMBER"

    $file = FileOpen("info.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open info.txt.")
        Exit
    EndIf
    While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        $result = StringSplit($line, "|", 1)
        If StringCompare($result[2], $item_to_check, 2) == 0 OR StringCompare($result[3], $item_to_check, 2) == 0 Then
            FileClose($file)
            Return $result[1]
        EndIf
    WEnd
    FileClose($file)
    Return $CNF
EndFunc
Edited by autoitFR
Link to comment
Share on other sites

  • Moderators

autoitFR,

I created a file in the format you use with this script:

$sContent = ""

For $i = 1 To 99999

    $iNumber = StringFormat("%05i", $i)
    $sContent &= "ITEMNAME_" & $iNumber & "|ITEMNUM1_" & $iNumber & "|ITEMNUM2_" & $iNumber & @CRLF

Next

$hFile = FileOpen(@ScriptDir & "\Item.txt", 2)
FileWrite($hFile, $sContent)
FileClose($hFile)

That gave me a file of over 4.5 Mb. (4,599,954 to be exact :idiot:)

I then ran these scripts which I based on those you posted above on that file and both returned the penultimate entry without problem:

ConsoleWrite(_findmyitem("ITEMNUM1_99998") & @CRLF)

Func _findmyitem($item_to_check)

    $CNF = "ITEM NOT FOUND"

    $file = FileOpen("info.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open info.txt.")
        Exit
    EndIf

    While 1
        $chars = FileRead($file)
        If @error = -1 Then
            ConsoleWrite("No read" & @CRLF)
            ExitLoop
        EndIf
        $line = StringSplit($chars, @CRLF, 1)
        If $line[1] = "" Then
            ConsoleWrite("No Split" & @CRLF)
            ExitLoop
        EndIf

        For $x = 1 to $line[0]

            $result = StringSplit($line[$x], "|", 1)
            If StringCompare($result[2], $item_to_check, 2) == 0 OR StringCompare($result[3], $item_to_check, 2) == 0 Then
                FileClose($file)
                Return $result[1]
            EndIf
        Next

        ExitLoop

    WEnd
    FileClose($file)

    Return $CNF

EndFunc

ConsoleWrite(_findmyitem("ITEMNUM1_99998") & @CRLF)

Func _findmyitem($item_to_check)

    $CNF = "ITEM NOT FOUND"


    $file = FileOpen("info.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open info.txt.")
        Exit
    EndIf
    While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        $result = StringSplit($line, "|", 1)
        If StringCompare($result[2], $item_to_check, 2) == 0 OR StringCompare($result[3], $item_to_check, 2) == 0 Then
            FileClose($file)
            Return $result[1]
        EndIf
    WEnd
    FileClose($file)
    Return $CNF
EndFunc

So I can confidently say that the problem in reading a file over 64kb is one which is within your system, not AutoIt. Are you sure that in updating the Info.txt file you have not altered the format in some way so that you get an incomplete read? :)

Perhaps give it a glance in a hex editor - or post it here so I can take a look. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...