Jump to content

Read .ini for combo box information


Recommended Posts

I am attempting to read an ini file and input the data into a combo box.. this is all fine and dandy but - Arrays kick my butt up and down the street.

I still don't get them yet. How would one input 100 different values into an ini then have those values be input to a combo box without writing one line of code for each value input?

I know you use an array, which is why I chose to put this in general help instead of GUI help.

This is what I have:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $var

Example()

Func Example()
    Local $msg
    GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered
    For $i = 1 To $var[0][0]
        GUICtrlCreateCombo($var[$i][1], 10, 10); create first item
    Next
    GUISetState()

   ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc  ;==>Example


$var = IniReadSection("C:\myfile.ini", "section1")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
EndIf

I guess what I'm really asking is this:

Can someone explain array's to me? I must have skipped trig to smoke cigs and rebel when this lesson was being taught. :)

children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)
Link to comment
Share on other sites

I am attempting to read an ini file and input the data into a combo box.. this is all fine and dandy but - Arrays kick my butt up and down the street.

I still don't get them yet. How would one input 100 different values into an ini then have those values be input to a combo box without writing one line of code for each value input?

I know you use an array, which is why I chose to put this in general help instead of GUI help.

This is what I have:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $var

Example()

Func Example()
    Local $msg
    GUICreate("My GUI combo"); will create a dialog box that when displayed is centered
    For $i = 1 To $var[0][0]
        GUICtrlCreateCombo($var[$i][1], 10, 10); create first item
    Next
    GUISetState()

 ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc;==>Example


$var = IniReadSection("C:\myfile.ini", "section1")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
EndIf

I guess what I'm really asking is this:

Can someone explain array's to me? I must have skipped trig to smoke cigs and rebel when this lesson was being taught. :)

this line here....

For $i = 1 To $var[0][0]
        GUICtrlCreateCombo($var[$i][1], 10, 10); create first item
    Next

will make X amount of combo boxes in 1 spot, not add to an already existing combo box.

also, you haven't made $var an array, you didnt add any info to the array @ all

Edited by ReaImDown
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

this line here....

For $i = 1 To $var[0][0]
        GUICtrlCreateCombo($var[$i][1], 10, 10); create first item
    Next

will make X amount of combo boxes in 1 spot, not add to an already existing combo box.

also, you haven't made $var an array, you didnt add any info to the array @ all

then why does this work?

$var = IniReadSection("C:\Temp\myfile.ini", "section2")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf

This is what my problem is, why does it work one way but not the other? I told you I don't understand array's.. :)

I understand that I'm wrong :P But can you tell me why or how I'm wrong in greater detail, please?

[edit] Why I thought I was doing it right, example via help file, also - I understand why I'm wrong with amount... but I still don't get how to do it right[/edit]

Edited by Anonymouse
children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)
Link to comment
Share on other sites

Without knowing the content of you .ini, I cannot give you a specific solution. All I can do is point you to the right direction.

1) Use _FileReadToArray() Function

2) Then you need to clean up your array

If you have a key=value setup, then you'll need StringSplit() and _ArrayDelete() to clean your array.

Once you've cleaned your array and all the thing in it is the values you want to show up in your combobox, simply run the following;

$iniList = ""
For $i = 0 To Ubound($vArray) - 1
    If $i = Ubound($vArray) - 1
        $iniList &= $iniList & $vArray[$i]
    Else
        $iniList &= $iniList & $vArray[$i] & "|"
    EndIf
Next
GUICtrlSetData($cBox,$iniList)

(I haven't tested the codes above, so you might need to tweak it.)

There you go.

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

Link to comment
Share on other sites

then why does this work?

Because that code is right but the one in your first post ic completely wrong, they are so far from each other that they could be. Also your GUICtrlCreateCombo in the wrong place doing the wrong thing. I created a shorter and working version=

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $var, $msg, $combo

GUICreate("My GUI combo")
$var = IniReadSection("C:\Documents and Settings\Ärkeskäggot\Mina dokument\Mina AutoIt\Mina Program\Platformerious\test3,1.pmap", "Mapping")
If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.")
$combo = GUICtrlCreateCombo("", 10, 10)
For $i = 1 To $var[0][0]
    GUICtrlSetData($combo, $var[$i][1])
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Link to comment
Share on other sites

Because that code is right but the one in your first post ic completely wrong, they are so far from each other that they could be. Also your GUICtrlCreateCombo in the wrong place doing the wrong thing. I created a shorter and working version=

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Global $var, $msg, $combo

GUICreate("My GUI combo")
$var = IniReadSection("C:\Documents and Settings\Ärkeskäggot\Mina dokument\Mina AutoIt\Mina Program\Platformerious\test3,1.pmap", "Mapping")
If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.")
$combo = GUICtrlCreateCombo("", 10, 10)
For $i = 1 To $var[0][0]
    GUICtrlSetData($combo, $var[$i][1])
Next
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Ah.. thank you. Now I can go look up everything in the helpfile and see where the hell my head was, and if I can pull it back into sunlight. This makes much more sense to me.

children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)
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...