Sign in to follow this  
Followers 0
jezzzzy

Array Functions

12 posts in this topic

This function only produces 3 lines of the text file. Not sure why.

Func LoadFile()
    If Not _FileReadToArray($filepath & GUICtrlRead($dropdown),$listviewcontents) Then
        GUICtrlCreateListViewItem("Error reading log file.",$listview)
    EndIf
    ;MsgBox(0,"ArraySize",$listviewcontents[0])
    For $x = 1 to $listviewcontents[0]
        GUICtrlCreateListViewItem($listviewcontents[$x],$listview)
    Next
EndFunc
oÝ÷ ØX«²ÚZ®Úµìm~)^$²X¤zØb±Êx02±±Ôôãý·ÿm4ïM9óOyón¶÷]zã®=ߢyÞrبK-i¹b²Óößý´Ó½4çÍ=çͼÛÝuë¹÷~|
çyËb¢q,µ¦åÈ^wN?ÛöÓNôÓ6ï8óou×®:ëÝùð*'ç-IJÖ+!yÝ8ÿmÿÛM;ÓN|Û¾|ãݽ×^¸ë¿wçÀ¨w¶*'ËZnX¬çtãý·ÿm4ïM9ónùóv÷]zã¯=ߢyÞrبK-i¹b²Óößý´Ó½4çÎ:çÍuÛÝuë½÷~|
çyËb¢q,µ¦åÈ^(uà%²axX¥x*.Òâëºw-ÛzZ0­ën®{*ºzãyªê-NW¢{Z{5׿%w¬jëh×6
Case $msg = $lblLinecount
    $totallines = _FileCountLines($filepath & GUICtrlRead($dropdown))
    GUICtrlSetData($lbllinecount,$totallines & " Lines")

Share this post


Link to post
Share on other sites



Update:

I thought I would run through my problem again, the way that anyone trying to assist me might. So I copied the text that I posted and made a new text file with it. Then ran my script and it returned everything correctly. So that would indicate that my text file is weird. I am posting the file that I am working with so that someone could at least duplicate my problem.

syslog.2008.06.11.txt

Share this post


Link to post
Share on other sites

Notepad shows ANSI in the 'Save As...' dialog. Also, I have attached the file earlier this thread if it helps.

is the original file saved as unicode?

If you open the original file and do a Save as you should see in the encoding section what it says it is saving as

Share this post


Link to post
Share on other sites

Notepad shows ANSI in the 'Save As...' dialog. Also, I have attached the file earlier this thread if it helps.

But you say the actual file contains 1178 lines, the one you posted only contains 17 so it is not the original file is it?

Share this post


Link to post
Share on other sites

I just tried your attached logfile and _filereadtoarray does screw it up

I think the best way is to do it manually yourself like this example I have done for you..

#include <guiConstants.au3>


Local $fileArray[1];declare the array

;open the file with a file handle as it is quicker to read lots of lines
$file = FileOpen("syslog.2008.06.11.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    
    Redim $fileArray[Ubound($fileArray) + 1];increase the size of the array to accomodate the new value
    $fileArray[Ubound($fileArray) - 1] = $line; add the new value to the end of the array
    
Wend

    $fileArray[0] = Ubound($fileArray);set array[0] value to the total number of elements in the array

;close the file handle
FileClose($file)




_ArrayDisplay2($fileArray);display the results


Func _ArrayDisplay2(Const ByRef $avArray, $sTitle = "");my modified arraydisplay in a listview (work in progress!)
    
    If (Not IsArray($avArray)) Then
        SetError(1)
        Return 0
    EndIf
    
    Local $iRows = 0, $iCols = 0, $cHeaders, $iCnt = 0, $lv ,$lCnt = 0, $tCnt = 0, $rtext, $cButton,$lvGui,$lvGuiMsg

    $iRows = Ubound($avArray) -1
    $icols = Ubound($avArray,2)
    
    $cHeaders = "I/C |0|"
    
    For $iCnt = 1 to $iCols -1
        $cHeaders &= $iCnt & "|"
    Next
    
    $lvGui = GuiCreate($sTitle,400,300)
    $lv= GuiCtrlCreateListview($cHeaders,20,20,360,220)
    
If $icols <> 0 then 
    
    For $lCnt = 0 to $iRows
        $rtext = "[" & $lCnt &"]|"
        For $tCnt = 0 to $icols -1
            $rText &= $avArray[ $lcnt][$tcnt] & "|"
        Next
        GUICtrlCreateListViewItem($rText,$lv)
    Next
    
Else
    
    For $lCnt = 0 to $iRows
        $rtext = "[" & $lCnt &"]|" & $avArray[$lCnt]
        GUICtrlCreateListViewItem($rText,$lv)
    Next
    
    
EndIf


$cButton = GuiCtrlCreateButton("Close", 150, 260, 110, 30)


GuiSetState()

While 1
    $lvGuiMsg = GuiGetMsg(1)
    Select
        Case $lvGuiMsg[0] = $GUI_EVENT_CLOSE or $lvGuiMsg[0] = $cButton
        If $lvGuiMsg[1] = $lvGui then ExitLoop
        
        Case Else
        ;;;
    EndSelect
WEnd
    
    SetError(0)
    Return 1

EndFunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I just tried your attached logfile and _filereadtoarray does screw it up

The file contains a Null character after the end of the first record: 0D 0A 00 Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thank you much. The manual method works.

Edit:

Just read JdeB's post. Is it wise to search the entire text file for null value's or will that generate a significant lag? I would obviously rather use the built-in functions than create a custom function for all of the file to array tasks.

Edited by jezzzzy

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I thought I remembered seeing a post on getting rid of NULL values from strings but now I can't find it. Doesn't look like I can just use StringReplace() to get rid of NULL values.

Actually, the content before the null value is not needed. In fact, I strip it out anyway in my For...Next loop. Is there a way to StringInStr() for a NULL value?

Edited by jezzzzy

Share this post


Link to post
Share on other sites

You can still do it with included functions, you can read each line like I did and if you #include <Array.au3> you could use _ArrayAdd() to build your array although it pretty much does what I did but in an included function. :shocked:

Infact jdeb who replied earlier created the original UDF!

Share this post


Link to post
Share on other sites

You can still do it with included functions, you can read each line like I did and if you #include <Array.au3> you could use _ArrayAdd() to build your array although it pretty much does what I did but in an included function. :shocked:

Infact jdeb who replied earlier created the original UDF!

Try this script with the current Production and Beta versions..

I don't think the current Beta handles the hex 00 correctly:

#include<file.au3>
#include<array.au3>
Dim $aTest
_FileReadToArray("syslog.2008.06.11.txt",$aTest)
_ArrayDisplay($aTest,"test")

---------------------------

test

---------------------------

[0] = 3

[1] = DATE TIME LEVEL EVENT

[2] = -------------------------------------

[3] =

---------------------------

OK

---------------------------

---------------------------

test

---------------------------

[0] = 1

[1] = 0x20202044415445202020202054494D452020204C4556454C2020202020204556454E540D0A2D2D2D2D2D2D2D2D2D2D2D2D

2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D0D0A0030362F31312F323030362031343A31393A3234207B32

7D202D205B393437355D203A20436F6E6E656374696F6E2045737461626C69736865640D0A30362F31312F32303036203134

3A31393A3234207B327D202D205B393437355D203A2057726F6E672070617373776F72643A20616E6F6E796D6F75730D0A30

362F31312F323030362031343A31393A3235207B327D202D205B393437355D203A20436F6E6E656374696F6E20436C6F7365

640D0A30362F31312F323030362031343A31393A3235207B327D202D205B393437365D203A20436F6E6E656374696F6E2045

737461626C69736865640D0A30362F31312F323030362031343A31393A3236207B327D202D205B393437365D203A2057726F

6E672070617373776F72643A20616E6F6E796D6F75730D0A30362F31312F323030362031343A31393A3236207B327D202D20

5B393437365D203A20436F6E6E656374696F6E20436C6F7365640D0A30362F31312F323030362031343A31393A3430207B32

7D202D205B393437375D203A20436F6E6E656374696F6E2045737461626C69736865640D0A30362F31312F32303036203134

3A31393A3430207B327D202D205B393437375D203A2057726F6E672070617373776F72643A20616E6F6E796D6F75730D0A30

362F31312F323030362031343A31393A3431207B327D202D205B393437375D203A20436F6E6E656374696F6E20436C6F7365

640D0A30362F31312F323030362031343A31393A3431207B327D202D205B393437385D203A20436F6E6E656374696F6E2045

737461626C69736865640D0A30362F31312F323030362031343A31393A3431207B327D202D205B393437385D203A2057726F

6E672070617373776F72643A20616E6F6E796D6F75730D0A30362F31312F323030362031343A31393A3431207B327D202D20

5B393437385D203A20436F6E6E656374696F6E20436C6F7365640D0A30362F31312F323030362031343A31393A3439207B32

7D202D205B393437395D203A20436F6E6E656374696F6E2045737461626C69736865640D0A30362F31312F32303036203134

3A31393A3439207B327D202D205B393437395D203A2057726F6E672070617373776F72643A20616E6F6E796D6F75730D0A30

362F31312F323030362031343A31393A3530207B327D202D205B393437395D203A20436F6E6E656374696F6E20436C6F7365

640D0A30362F31312F323030362031353A30373A3539207B327D202D205B393438305D203A20436F6E6E656374696F6E2045

737461626C69736865640D0A30362F31312F323030362031353A30383A3034207B327D202D205B393438305D203A20436F6E

6E656374696F6E20436C6F7365640D0A

---------------------------

OK

---------------------------


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you very much Jdeb. Switching from the Beta fixed all of my issues.

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