Sign in to follow this  
Followers 0
BoonPek

Reading Items in a List View and saving in an INI

5 posts in this topic

This is a small part of a larger program that I'm working on. Currently, you can set information into the list and remove them. What I want it to do is to read the items in the list, sort them out and put them into an *.ini file. I am struggling to find a way to read the data inside the list, and save them into an ini with this format:

[barcodes]

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

BARCODES=ITEM NAME|PRICE

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <EditConstants.au3>

Global $ConfigCode, $ConfigName, $ConfigDollar, $ConfigCents
Global $ConfigList

ConfigData()

Func ConfigData()
    $ConfigGUI = GUICreate("Database Configuration", 800, 500)

    $ConfigList = GUICtrlCreateListView("Barcode |Item Name |Price", 5, 5, 305, 360, $LVS_REPORT)
    _GUICtrlListView_SetColumnWidth($ConfigList, 0, 70)
    _GUICtrlListView_SetColumnWidth($ConfigList, 1, 160)
    _GUICtrlListView_SetColumnWidth($ConfigList, 2, 70)

    GUICtrlCreateLabel("Item Name:", 5, 380, 60, 20)
    GUICtrlCreateLabel("Barcode:", 5, 410, 60, 20)
    GUICtrlCreateLabel("Price:", 160, 410, 60, 20)

    $ConfigName = GUICtrlCreateInput("", 70, 380, 240, 20)

    $ConfigCode = GUICtrlCreateInput("", 70, 410, 80, 20, $ES_NUMBER)

    $ConfigDollar = GUICtrlCreateInput("", 230, 410, 45, 20, $ES_NUMBER)
    GUICtrlCreateLabel(".", 278, 410, 20, 12)
    $ConfigCents = GUICtrlCreateInput("", 285, 410, 25, 20, $ES_NUMBER)

    GUICtrlSetLimit($ConfigCode, 8, 8)
    GUICtrlSetLimit($ConfigName, 20, 0)
    GUICtrlSetLimit($ConfigDollar, 4, 0)
    GUICtrlSetLimit($ConfigCents, 2, 0)

    $ConfigAdd = GUICtrlCreateButton("Add", 20, 450, 80, 25)
    $ConfigRem = GUICtrlCreateButton("Remove", 115, 450, 80, 25)
    $ConfigClr = GUICtrlCreateButton("Clear", 210, 450, 80, 25)

    GUISetState()

    Do
        $msg = GUIGetMsg()
        Switch $msg
            Case $ConfigAdd
                ConfigAddData()
            Case $ConfigRem
                ConfigRemData()
            Case $ConfigClr
                ConfigClrData()
        EndSwitch
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>ConfigData

Func ConfigAddData()
    $ReadBar = GUICtrlRead($ConfigCode)
    $ReadName = GUICtrlRead($ConfigName)
    $ReadPrice = GUICtrlRead($ConfigDollar) & "." & GUICtrlRead($ConfigCents)

    GUICtrlCreateListViewItem($ReadBar & "|" & $ReadName & "|" & $ReadPrice, $ConfigList)

    GUICtrlSetData($ConfigCode, "")
    GUICtrlSetData($ConfigName, "")
    GUICtrlSetData($ConfigDollar, "")
    GUICtrlSetData($ConfigCents, "")
EndFunc   ;==>ConfigAddData

Func ConfigRemData()
    _GUICtrlListView_DeleteItemsSelected($ConfigList)
EndFunc   ;==>ConfigRemData

Func ConfigClrData()
    _GUICtrlListView_DeleteAllItems($ConfigList)
EndFunc   ;==>ConfigClrData

I really appreciate any help given. Thank you.


Share this post


Link to post
Share on other sites



Bump...


Share this post


Link to post
Share on other sites

How many items are we talking about?

- If the amount of items are static, then simply put each item in the ini.

If not static, then what you may want to look at is setting up an array. Take a look at _ArrayToString. That may do what you need. I would suggest you split up your items into groups and use INIReadSection or INIWriteSection to interact with it. Hope this helps.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_GUICtrlListView_GetItemCount; Once you have that, do a For/Next loop to the end of the count ( remember that indexes start at zero, so you'll have to remove one from the count ).

_GUICtrlListView_GetItemText or _GUICtrlListView_GetItemTextArray or _GUICtrlListView_GetItemTextString; however you wish to extract the data.

pseudo code if I only had one column:

For $i = 0 To _GUICtrlListView_GetItemCount($h_listview) - 1
    IniWrite("myinifile.ini", "mysection", "mykey", _GUICtrlListView_GetItemText($h_listview, $i))
Next

Edit:

I need you to know I only answered this after you bumping your post up within 24 hours because MPH seems to be out to lunch very early this morning.

So a verbal warning to you, do not bump your threads up within 24 hours of your last post.

Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Thank you SmOke_N and MPH, I'm sorry for bumping my post before the 24-hour period.


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