Jump to content

Using .ini section in listbox - easiest way?


Recommended Posts

Hello All,

I have an .ini file that has several sections which contains data I want to present in a GUI listbox and allow the user to select. An example would be:

[Cities]

Los Angeles = "www.friendly-LA-site.com"

Bakersfield = "www.BuckOwensCountry.com"

What I want to do is read in the cities section into a 2 dimensional array. Sort by the arguement field ("Los Angeles") then place in a listbox showing only "Los Angeles". When the user selects "Los Angeles", I want to be able to access the function field (website - "www.friendly-LA-site.com") for use further in the script.

I want to do this in both single and multiple select listboxes. Whats the easiest way to accomplish this using AutoIt?

I started with:

$CurrCity = IniReadSection(@ScriptDir & "\cities.txt", "Cities")
$lbCities = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))

For $i = 1 To $CurrCity[0][0] 
    $RetCode = _GUICtrlListAddItem($lbCities, $CurrCity[$i][0])
Next

But got stuck.

Any advice?

PokerGuy

Link to comment
Share on other sites

Use this:

$CurrCity = IniReadSection(@ScriptDir & "\cities.txt", "Cities")
$lbCities = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))

For $i = 1 To $CurrCity[0][0]
    $RetCode = _GUICtrlListAddItem($lbCities, $CurrCity[$i][1])
Next

Yes, I see how you are using the function field ("right" side ) to load the listbox, but I want to see the arguement field (left side) in the listbox and when selected, use the www.... from the right side.

Is there a multicolumn listbox that I can load with both values (left & right) and hide the right?

PokerGuy

Link to comment
Share on other sites

If I understand you correctly, this what what you want.

#include <GUIConstants.au3>
#include <GuiList.au3>
#include <IE.au3>

GUICreate("Test Window", 200, 200)
$CurrCity = IniReadSection(@ScriptDir & "\cities.txt", "Cities")

$lbCities = GUICtrlCreateList("", 5, 5, 180, 120)

For $i = 1 To $CurrCity[0][0] 
    _GUICtrlListAddItem($lbCities, $CurrCity[$i][0])
Next

$b_go = GuiCtrlCreateButton("Go Go Go", 5, 150, 80, 25)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $b_go
            $get_city = GUICtrlRead($lbCities)
            $get_Url = IniRead(@ScriptDir & "\cities.txt", "Cities", $get_city, "")
            $oIE = _IECreate ($get_Url)
    EndSelect
WEnd

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

If I understand you correctly, this what what you want.

#include <GUIConstants.au3>
#include <GuiList.au3>
#include <IE.au3>

GUICreate("Test Window", 200, 200)
$CurrCity = IniReadSection(@ScriptDir & "\cities.txt", "Cities")

$lbCities = GUICtrlCreateList("", 5, 5, 180, 120)

For $i = 1 To $CurrCity[0][0] 
    _GUICtrlListAddItem($lbCities, $CurrCity[$i][0])
Next

$b_go = GuiCtrlCreateButton("Go Go Go", 5, 150, 80, 25)

GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $msg = $b_go
            $get_city = GUICtrlRead($lbCities)
            $get_Url = IniRead(@ScriptDir & "\cities.txt", "Cities", $get_city, "")
            $oIE = _IECreate ($get_Url)
    EndSelect
WEnd

Well not quite. I want the user to be able to select multiple cities and then indicate that all selections are done. Then ALL selected cities would be processed as a group.

Thanks for your code. It opened my eyes to another way of utilizing the .ini file for storing and retrieving info. (build the listbox, then read the specifc key and value).

PokerGuy

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...