Jump to content
Sign in to follow this  
ryoken

Read List Items from Ini File

Recommended Posts

ryoken

Alright, What I'm trying to do here is make it so when my program starts up, it loads items from an ini file to a list.

What i'm exactly trying to do is make it so you save account information in an ini file. Then the names of the saved accounts appear on the list when the program starts up. When you click on the list item, it puts the username and password of that account into the corresponding boxes.

Can anyone help me with this?

Share this post


Link to post
Share on other sites
BrettF
ryoken

Ini File:

[Accounts]

Name = test

Username1 = test

Password1 = test

I've tried setting the data of the list using GUICtrlSetData but that doesen't seem to work properly.

There's really no code to show because all i really have right now is a normal gui with a menu control.

Edited by ryoken

Share this post


Link to post
Share on other sites
Authenticity

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt('GUIOnEventMode', 1)

Global $hGUI = GUICreate('Test', 250, 350)
Global $ListView = GUICtrlCreateListView('Account    |Password   ', 20, 20, 210, 310, BitOR($LVS_DEFAULT, $LVS_NOSORTHEADER), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GetAccounts()

GUISetOnEvent($GUI_EVENT_CLOSE, '_Close')
GUISetState()

While 1
    Sleep(20)
WEnd

Func _GetAccounts()
    Local $aAccounts = IniReadSection(@ScriptDir & '\file.ini', 'Accounts')
    
    If Not @error Then
        For $i = 1 To $aAccounts[0][0]
            GUICtrlCreateListViewItem($aAccounts[$i][0] & '|' & $aAccounts[$i][1], $ListView)
            GUICtrlSetOnEvent(-1, '_ListViewHandler')
        Next
    EndIf
EndFunc

Func _Close()
    GUIDelete()
    Exit
EndFunc

Func _ListViewHandler()
    Local $aPair = StringSplit(StringTrimRight(GUICtrlRead(@GUI_CtrlId), 1), '|', 2)
    If UBound($aPair) = 2 Then MsgBox(0x40, 'Account/Pass', 'Account: ' & $aPair[0] & @CRLF & 'Pass: ' & $aPair[1])
EndFunc

I thought more in this direction, it's quite easy to implement and modify the script to your preferred way:

file.ini:

[Accounts]
ABC=DEF
123=456
leopard=panther
et=cetra

Share this post


Link to post
Share on other sites
BrettF

Share this post


Link to post
Share on other sites
ryoken

whoops forgot to rename the file :)

I'm still having trouble understanding the script itself and how it works but i guess I'll figure that out over time.

Thank you both.

Share this post


Link to post
Share on other sites
BrettF

I hope you've managed to realise that the function _GetAccounts() loads data into the listview.

Local $aAccounts = IniReadSection(@ScriptDir & '\file.ini', 'Accounts')

This reads the entries in the INI file under the section "Accounts" ([Accounts] in the INI file), and outputs a 2D array in the form where element[n][0] is the key and element[n][1] is the value. We then check for errors (first If statement) and

GUICtrlCreateListViewItem($aAccounts[$i][0] & '|' & $aAccounts[$i][1], $ListView)

This sets the data in the listview as per what it returns.

GUICtrlSetOnEvent(-1, '_ListViewHandler')

This sets an even when you click on a listview item.

Cheers,

Brett

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.