Jump to content
Sign in to follow this  
telmob

Ini to Combo?

Recommended Posts

telmob

Hello.

I have a .ini file with the following contents:

[Percent1]

20

25

30

35

40

45

[Percent2]

50

100

How can i put it's contents in a combo box? I can't even read the ini :S I'm still a noob, please be gentle :)

Share this post


Link to post
Share on other sites
Melba23

telmob,

It would be much easier if you had a standard key=value ini file format something like this:

[Percent1]
20=20
25=25
30=30
35=35
40=40
45=45

[Percent2]
50=50
100=100

Then you could use IniReadSection to get the values into an array and loop through it. ;)

Can you alter the ini file or are you stuck with what you have? If so, then we will have to look at rather more cumbersome methods. ;)

Let me know and then we can work on it. :)

M23


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
telmob

I'm kinda stuck with that ini, because i need the combo to add new values to the ini, and it seems more difficult to do that with key values.

Share this post


Link to post
Share on other sites
AdmiralAlkex

@telmob

Look at IniWrite() in the helpfile, it's really easy :)

If you have troubles, post a reproducer (short fully working example script) and someone will take a look.

@Melba23

You don't need those extra "values" if you're using IniReadSection ;)

#cs
[Percent1]
20=
25=
30=
[Percent2]   ;To close Percent1 or else $asSection line would be IniRead...
#ce

#include <Array.au3>

$asSection = IniReadSection(@ScriptFullPath, "Percent1")

_ArrayDisplay($asSection)

Share this post


Link to post
Share on other sites
telmob

@AdmiralManHairAlkex

Thanks for the help, but this is not working:

specifics.ini:

[Frequence]

1

2

4

5

10

15

#include <Array.au3>  
$asSection = IniReadSection(@ScriptDir & "\specifics.ini", "Frequence")  
_ArrayDisplay($asSection)

What's wrong with this?

EDIT: Ok, i just saw i need to put those '=' at the end.

Let's hope i won't need to use '=' as new data. :)

BUT..... the problem persists... ;)

How do i get the ini in the combo?

#include <GUIConstants.au3>
 #include <Array.au3>

$asSection = IniReadSection("specifics.ini", "Frequence")

 $Form1 = GUICreate("Form1", 633, 454, 193, 115)
 $Combo1 = GUICtrlCreateCombo("", 184, 72, 145, 25)
 GUICtrlSetData(-1, $asSection)
 GUISetState(@SW_SHOW)

;~ _ArrayDisplay($asSection)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by telmob

Share this post


Link to post
Share on other sites
AdmiralAlkex

Unfortunately GUICtrlSetData doesn't accept an array as "data" (but I see how that would be neat).

Here's one way to do it:

#include <GUIConstants.au3>
#include <Array.au3>

$asSection = IniReadSection("specifics.ini", "Frequence")

$Form1 = GUICreate("Form1", 633, 454, 193, 115)
$Combo1 = GUICtrlCreateCombo("", 184, 72, 145, 25)
For $iX = 1 To $asSection[0][0]
    GUICtrlSetData(-1, $asSection[$iX][0])
Next
;~ GUICtrlSetData(-1, $asSection)
GUISetState(@SW_SHOW)

;~ _ArrayDisplay($asSection)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Make sure you read the page on GUICtrlSetData() so you understands why this works and yours did not.

Combo, List, ListView, ListViewItem: An Opt("GUIDataSeparatorChar",...) separated list of items.

For Combo or List control :

If the "data" corresponds to an already existing entry it is set as the default.

If the "data" starts with GUIDataSeparatorChar or is an empty string "" the previous list is destroyed.

Share this post


Link to post
Share on other sites
telmob

Thanks Admiral!

Sorry i took so long to reply, but the forum security blocks me most of the time. Maybe because i'm using a shared IP in my 3G modem... :S

Edited by telmob

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  

×