Jump to content

Ini to Combo?


telmob
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@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)
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
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...