Sign in to follow this  
Followers 0
Particle

Reading files to listviews help

3 posts in this topic

I am writing a program for a friend and when I do a test run I get this error:

D:\Source\Au3 Files\l3lade.au3 (51) : ==> Subscript used with non-Array variable.:

For $x = 1 To $fArray[0]

For $x = 1 To $fArray^ ERROR

Here is the code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <File.au3>
#include <IE.au3>

$Form1 = GUICreate("Multi-Zip", 233, 226, 575, 174)
$ListView1 = GUICtrlCreateListView("Zip Codes|Income", 80, 8, 146, 190, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 65)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 75)
$Button1 = GUICtrlCreateButton("Load", 8, 16, 67, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Clear", 8, 48, 67, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Save", 8, 80, 67, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Run", 8, 112, 67, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Stop", 8, 144, 67, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("Exit", 8, 176, 67, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Notify upon Completion", 86, 201, 137, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button6
            Exit
        Case $Button1
            $Open = FileOpenDialog("Open Txt File", @DesktopDir, "Text Files (*.txt)|All Files (*.*)", 3, "", $Form1)
            If Not @error Then
                Dim $fArray
                $TXT = FileOpen($Open,0)
                _FileReadToArray($TXT,$fArray)
                For $x = 1 To $fArray[0]
                    _GUICtrlListView_AddItem($ListView1,$fArray[$x])
                Next
                FileClose($TXT)
            EndIf
    EndSwitch
WEnd

and the text file i try to load:

95108

95109

95110

95111

95112

95128

What am I doing wrong?

Share this post


Link to post
Share on other sites



$TXT = FileOpen($Open,0) <- You don't need to open the file, you locked it and FileReadToArray can't read it now.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Replace by For $x = 1 To UBound ( $fArray ) -1 Posted Image

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <File.au3>
#include <IE.au3>

$Form1 = GUICreate("Multi-Zip", 233, 226, 575, 174)
$ListView1 = GUICtrlCreateListView("Zip Codes|Income", 80, 8, 146, 190, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 65)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 75)
$Button1 = GUICtrlCreateButton("Load", 8, 16, 67, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Clear", 8, 48, 67, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Save", 8, 80, 67, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Run", 8, 112, 67, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Stop", 8, 144, 67, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("Exit", 8, 176, 67, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Notify upon Completion", 86, 201, 137, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button6
            Exit
        Case $Button1
            $TXT = FileOpenDialog("Open Txt File", @DesktopDir, "Text Files (*.txt)|All Files (*.*)", 3, "", $Form1)
            If Not @error Then
                Dim $fArray
                _FileReadToArray($TXT,$fArray)
                For $x = 1 To UBound ( $fArray ) -1
                    _GUICtrlListView_AddItem($ListView1,$fArray[$x])
                Next
            EndIf
    EndSwitch
WEnd
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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