Eru Posted February 23, 2007 Share Posted February 23, 2007 Question 1I'm making a script that is going to use saved variables in a .ini file. It's set up like this:[ColorList] List=Color1|Color2|Color3| Color1=0x000000 Color2=0xFFFFFFF Color3=oxF0F0F0I've made an input box and am using what's typed in that to add new colors. I use the FileWrite command and I can create a new color at the bottom, [i.e. Color4=0xF0F0F0], but I can't seem to figure out how to add it to the List= line. Is there a command that I'm missing?Question 2I'm using a combo box also for selecting the saved color and loading it. Is it possible to use the combo box as the input instead of having it *and* the input box?Thanks for any help. This is my first script and it's turning out to be quite the challenge. Link to comment Share on other sites More sharing options...
BigDod Posted February 23, 2007 Share Posted February 23, 2007 Answer 1FileWriteLine Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Shevilie Posted February 23, 2007 Share Posted February 23, 2007 Well I would use IniWrite Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit Link to comment Share on other sites More sharing options...
Eru Posted February 24, 2007 Author Share Posted February 24, 2007 Hmm. IniWrite will replace everything that is on the List= line when I run it, and FileWriteLine still only adds to the very end of the file. I suppose I could use a combination of the two of them to add the variable to the end of each, but how can I make it add the new color to the end of the List instead of replacing what's on there? The Idea is to keep a running list that I can choose from with a combo box for quick configuration of the main script. Link to comment Share on other sites More sharing options...
MHz Posted February 24, 2007 Share Posted February 24, 2007 You read the list key with IniRead. Use StringSplit to get separate colors. Use the info. Join the colors together again into a string separated with |. IniWrite the string back to the list key with IniWrite. Link to comment Share on other sites More sharing options...
Eru Posted February 24, 2007 Author Share Posted February 24, 2007 *sigh* My knowledge of the autoit options are painfully lacking, but here's what I've gotten so far: Case $MSG = $Save $SaveList = IniRead ("List.ini", "Color", "List", "Not Found") $Savelist = StringSplit ($Savelist, "|") ;Delemiter = | ;What do do here? $IniWrite "List.ini", "Color", "List", $SaveList & GUICtrlRead ($InputBox) Does anyone have an example that I can look at? I seem to be a lot better at learning things if I'm reverse engineering them instead of perusing pages of functions to find what I need. Thanks for all the help guys. Link to comment Share on other sites More sharing options...
Sykeo Posted February 24, 2007 Share Posted February 24, 2007 CODE $path = @ScriptDir & "\color.ini" addColor("0xF1F1F1") addColor("0xF2F2F2") Func addColor($color) $section = IniReadSection($path, "ColorList") IniWrite($path,"ColorList","List", IniRead($path, "ColorList", "List","") & "Color" & $section[0][0] & "|") IniWrite($path,"ColorList","Color" & $section[0][0], $color) EndFunc Link to comment Share on other sites More sharing options...
The Kandie Man Posted February 24, 2007 Share Posted February 24, 2007 ;~ #include <array.au3> Local $s_List = IniRead ("List.ini", "ColorList", "List", "Not Found") Local $as_List = StringSplit ($s_List, "|") ;~ _ArrayDisplay($as_List,"List") Local $i_subtractamount If $as_List[$as_List[0]] = "" Then;checks to see if the last result is erraneous because of a trailing | $i_subtractamount = 1 ConsoleWrite('List = ""' & @LF & 'The above means that there was a trailing "|"' & @LF) Else $i_subtractamount = 0 ConsoleWrite('List <> ""' & @LF & 'The above means that there was no trailing "|"' & @LF) EndIf ConsoleWrite('The last value in the list string is="' & $as_List[Int($as_List[0]) - $i_subtractamount] & "'" & @LF);shows what the last Color# was in the list= string. Local $si_LastColor = StringTrimLeft($as_List[Int($as_List[0]) - $i_subtractamount],5);Trims the word color off the left so that we are just left with the number ConsoleWrite("Last List Color Number=" & $si_LastColor & @LF) Local $s_ColorNumToAdd = String(Int($si_LastColor) + 1);add one to that number so that we can the next Color# to the list ConsoleWrite("Now adding Color"&$s_ColorNumToAdd & " to the list string:" & @LF) IF $i_subtractamount = 1 Then;If there was a trailing | then this is true ConsoleWrite("List=" & $s_List & "Color" & $s_ColorNumToAdd & "|" & @LF) IniWrite("List.ini", "ColorList", "List", $s_List & "Color" & $s_ColorNumToAdd & "|" ) Else;if there wasn't a trailing |, then this will be used instead ConsoleWrite("List=" & $s_List & "|Color" & $s_ColorNumToAdd & "|" & @LF) IniWrite("List.ini", "ColorList", "List", $s_List & "|Color" & $s_ColorNumToAdd & "|" ) EndIf "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Sykeo Posted February 24, 2007 Share Posted February 24, 2007 (edited) hmmmmm why not just do this...? Its reuseable too $path = @ScriptDir & "\color.ini" addColor("0xF1F1F1") addColor("0xF2F2F2") printColors() Func addColor($color) $section = IniReadSection($path, "ColorList") IniWrite($path,"ColorList","List", IniRead($path, "ColorList", "List","") & "Color" & $section[0][0] & "|") IniWrite($path,"ColorList","Color" & $section[0][0], $color) EndFunc Func printColors() $section = IniReadSection($path, "ColorList") ConsoleWrite("===ColorList===" & @CRLF) For $x = 1 to $section[0][0] ConsoleWrite(IniRead($path,"ColorList","Color" & $x,"") & @CRLF) Next EndFuncColor.ini[ColorList]List=Color1|Color2|Color3|Color1=0x000000Color2=0xFFFFFFFColor3=oxF0F0F0 Edited February 24, 2007 by Sykeo Link to comment Share on other sites More sharing options...
Eru Posted February 24, 2007 Author Share Posted February 24, 2007 (edited) Thanks Sykeo! It's working like a charm, except for one problem. It writes sucessfully to a file as long as I use AddColor("Input"), but if I try to change the input to something from my box, it returns a different value. Here's what I've constructed: Func test() Local $Action = GUIGetMsg() Select Case $Action = $runtest Global $path = @ScriptDir & "\Test.ini" AddColor($TestInput) EndSelect EndFunc Func AddColor($Color) $ColorString = StringFormat ("%s", $Color) $section = IniReadSection($path, "ColorList") IniWrite ($path, "ColorList", "List", IniRead($path, "ColorList", "List", "") & "Color" & $section[0][0] & "|") IniWrite ($path,"ColorList","Color" & $section[0][0], $ColorString) EndFunc Edited February 25, 2007 by Eru Link to comment Share on other sites More sharing options...
Eru Posted February 25, 2007 Author Share Posted February 25, 2007 Hmm. That doesn't look as pretty as you guys' posts. Did you use copy/paste to get the pretty colors in your posts or was that manual editing? Link to comment Share on other sites More sharing options...
The Kandie Man Posted February 25, 2007 Share Posted February 25, 2007 You use the AutoIt tag instead of the Code tag to get the color syntax highlighting on the forum. "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Eru Posted February 25, 2007 Author Share Posted February 25, 2007 Func test() Local $Action = GUIGetMsg() Select Case $Action = $runtest Global $path = @ScriptDir & "\Test.ini" AddColor($TestInput) EndSelect EndFunc Func AddColor($Color) $ColorString = StringFormat ("%s", $Color) $section = IniReadSection($path, "ColorList") IniWrite ($path, "ColorList", "List", IniRead($path, "ColorList", "List", "") & "Color" & $section[0][0] & "|") IniWrite ($path,"ColorList","Color" & $section[0][0], $ColorString) EndFunc Nice, thank you. Anyone know how I can get it to get the color value from the input box? Link to comment Share on other sites More sharing options...
Eru Posted February 25, 2007 Author Share Posted February 25, 2007 Eru why don't you talk to Shynd, or Briant?Sorry, I don't know who that is, this is my first topic on these forums. How would I contact them and why do I need to? 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