Sign in to follow this  
Followers 0
reecedorward

Return data from text file to list in GUI

2 posts in this topic

The idea is that I want to save user names to a text file.. then be able to recall or 'Load' users saved to that text file in a list..

I need the list to be displayed within the GUICtrlCreateList function..

Here is the code I'm having trouble with, it displays a list of arrays using _arraydisplay BUT I dont want it displayed in columns and rows...

#include

#include

#include

#include

#include

#include

#include

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 277, 254, 192, 124)

$write = GUICtrlCreateInput("", 16, 16, 161, 21)

$enter = GUICtrlCreateButton("Enter", 192, 8, 73, 25)

$names = GUICtrlCreateList("", 24, 56, 209, 175)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

Global $userspath = "C:\Documents and Settings\matthews\My Documents\Reece's Scripts\Users.txt"

$readusers = fileread($userspath)

Local $array

$read = _Filereadtoarray($userspath, $array)

guictrlsetdata($names, $read)

_arraydisplay($array)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $enter

$readwrite = guictrlread($write)

guictrlsetdata($names, $readwrite)

guictrlsetdata($write, "")

filewrite($userspath, $readwrite & @CRLF)

EndSwitch

WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

reecedorward,

Take a look at this - should give you the idea: ;)

#include <GUIConstantsEx.au3>
#include <File.au3>

Global $userspath = "Users.txt"

$Form1 = GUICreate("Form1", 277, 254, 192, 124)
$write = GUICtrlCreateInput("", 16, 16, 161, 21)
$enter = GUICtrlCreateButton("Enter", 192, 8, 73, 25)
$names = GUICtrlCreateList("", 24, 56, 209, 175)
GUISetState(@SW_SHOW)

_Fill_List()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $enter
            ; Read the input
            $readwrite = GUICtrlRead($write)
            ; Add the name to the list
            GUICtrlSetData($names, $readwrite)
            GUICtrlSetData($write, "")
            ; Add the name to the file
            FileWriteLine($userspath, $readwrite)
    EndSwitch
WEnd

Func _Fill_List()

    ; Read the file into an array
    Local $array
    _FileReadToArray($userspath, $array)
    ; Check we read something
    If IsArray($array) Then
        ; Convert to a string with delimiters
        $sList = ""
        For $i = 1 To $array[0]
            $sList &= "|" & $array[$i]
        Next
        ; And fill the list
        GUICtrlSetData($names, $sList)
    EndIf

EndFunc

Please ask if you have any questions. :)

M23

P.S. When you post code, please use Code tags - put [autoit] before and [/autoit] after your posted code. ;)

Edited by Melba23
Added PS

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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