Anonymouse Posted June 18, 2008 Share Posted June 18, 2008 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 More sharing options...
ReaImDown Posted June 18, 2008 Share Posted June 18, 2008 (edited) 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 June 18, 2008 by ReaImDown [u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u] Link to comment Share on other sites More sharing options...
Anonymouse Posted June 18, 2008 Author Share Posted June 18, 2008 (edited) 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 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 June 18, 2008 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 More sharing options...
aslani Posted June 18, 2008 Share Posted June 18, 2008 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 More sharing options...
AdmiralAlkex Posted June 18, 2008 Share Posted June 18, 2008 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 .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Anonymouse Posted June 18, 2008 Author Share Posted June 18, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now