kttenneb Posted June 29, 2009 Share Posted June 29, 2009 (edited) Hi, Thanks in advance for help. I have included a very simplistic example of what I am trying to make. I have a series of buttons when you click on the buttons it displays information about the button pressed as read from the menu.ini I would like it to also write to a second ini --Pr.ini (the Print_ini() function in the example) Which will then be used as a dynamically created checklist of the items that were clicked which you can then select from to have it print. (The Print_Select() function in the example) I cannot seem to get the Print_ini function to spit the information out so that the Print_select function can create the checklist. Contents of menu.ini [Variable] Sep=************************* [item1] Title=Button 1 Solution=Some information related to Button 1. [item2] Title=Button 2 Solution=Other information about Button 2. [item3] Title=Button 3 Solution=There is no information to display about Button 3. [item4] Title=Button 4 Solution=This function is not available. <end> I would like for the Pr.ini to read: [1] Title=Button 1 Solution= Button 1 ************************* Some information related to Button 1. [2] Title=Button 2 Solution= Button 2 ************************* Other information about Button 2. [3] Title=Button 4 Solution= Button 4 ************************* This function is not available. [4] Title=Button 3 Solution= Button 3 ************************* There is no information to display about Button 3. <end> in what ever order selected CODE#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $Sep = IniRead("Menu.ini","Variable","Sep","") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 193, 125) $Button1 = GUICtrlCreateButton("Button1", 83, 53, 75, 25, 0) $Button2 = GUICtrlCreateButton("Button2", 164, 53, 75, 25, 0) $Button3 = GUICtrlCreateButton("Button3", 245, 53, 75, 25, 0) $Button4 = GUICtrlCreateButton("Button4", 326, 53, 75, 25, 0) $Edit1 = GUICtrlCreateEdit("", 77, 137, 338, 116) GUICtrlSetData(-1, "") $Input1 = GUICtrlCreateInput("Input1", 53, 383, 121, 21) $Close = GUICtrlCreateButton("Close", 479, 395, 75, 25, 0) $PRSelect = GUICtrlCreateButton("Print Select", 371, 392, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $sIniFile = @ScriptDir & "\button.ini" $PRini = @ScriptDir & "\PR.ini" $output = "" IniRead("button.ini","Item1","Title","") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $output = $output & @CRLF & IniRead("Menu.ini","Item1","Title","") $output = $output & @CRLF & $Sep $output = $output & @CRLF & " "& IniRead("Menu.ini","Item1","Solution","") GuiCtrlSetData($Edit1,$output) GuiCtrlSetData($input1,"Item1") Print_ini() $output = "" Case $Button2 $output = $output & @CRLF & IniRead("Menu.ini","Item2","Title","") $output = $output & @CRLF & $Sep $output = $output & @CRLF & " "& IniRead("Menu.ini","Item2","Solution","") GuiCtrlSetData($Edit1,$output) GuiCtrlSetData($input1,"Item2") Print_ini() $output = "" Case $Button3 $output = $output & @CRLF & IniRead("Menu.ini","Item3","Title","") $output = $output & @CRLF & $Sep $output = $output & @CRLF & " "& IniRead("Menu.ini","Item3","Solution","") GuiCtrlSetData($Edit1,$output) GuiCtrlSetData($input1,"Item3") Print_ini() $output = "" Case $Button4 $output = $output & @CRLF & IniRead("Menu.ini","Item4","Title","") $output = $output & @CRLF & $Sep $output = $output & @CRLF & " "& IniRead("Menu.ini","Item4","Solution","") GuiCtrlSetData($Edit1,$output) GuiCtrlSetData($input1,"Item4") Print_ini() $output = "" Case $Close If $nMsg = $Close Then Exit Case $PRSelect If $nMsg = $PRSelect Then Print_Select() EndSwitch WEnd $S = IniReadSectionNames($PrIni) Func Print_ini() For $x = 1 To $S[0] IniWrite("pr.ini",$x , "Title", GuiCtrlRead($Input1)) IniWrite("pr.ini", $x , "Solution", GuiCtrlRead($Edit1)) Next EndFunc Func Print_Select() $Section = IniReadSectionNames($PRini) GUICreate("test") $print = GUICtrlCreateButton("Print", 212, 75, 75, 25) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Exit Else Dim $Check[uBound($Section) ] Dim $Solution[uBound($Section) ] Local $nLeft = 25, $nTop = 25, $nWidth = 200, $nHeight = 25 For $x = 1 To $Section[0] $Check[$x] = GUICtrlCreatecheckbox(IniRead($PRini, $x, "Title", ""), $nLeft, $nTop, $nWidth, $nHeight) $Solution[$x] = IniRead($PRini, $x, "Solution", "") $nTop += 35 Next EndIf $title = IniRead($PRini, $x, "Title", "") GUISetState(@SW_SHOW) EndFunc Or if anyone has any other Ideas I am very open to suggestions. Edited June 30, 2009 by kttenneb Link to comment Share on other sites More sharing options...
wraithdu Posted June 29, 2009 Share Posted June 29, 2009 You can't have lines like these Button 4 ************************* This function is not available. just hanging out in an INI file. INI files are strictly section / key=value pairs (like your first INI). Link to comment Share on other sites More sharing options...
Valik Posted June 29, 2009 Share Posted June 29, 2009 Your thread title presents the very contradiction you face. You can't write to INI in a format you want because you've made the determination that the format you want is INI. If you don't wish to use the INI format then you can't use the INI format because the INI format is already defined. So... why did you post a thread at all? Either you want to use INI format or you don't. Doesn't seem very thread-worthy to me. Just seems like you need to stop for 15 seconds and actually think about what you wanted and what was happening. Link to comment Share on other sites More sharing options...
kttenneb Posted June 29, 2009 Author Share Posted June 29, 2009 Your thread title presents the very contradiction you face. You can't write to INI in a format you want because you've made the determination that the format you want is INI. If you don't wish to use the INI format then you can't use the INI format because the INI format is already defined. So... why did you post a thread at all? Either you want to use INI format or you don't. Doesn't seem very thread-worthy to me. Just seems like you need to stop for 15 seconds and actually think about what you wanted and what was happening. Valik OK first I do not need to be attacked or ridiculed, Im just looking for a little help, if you do not want to help, why wast 3 min of your precious time to post something that does not help anyone. Secondly I am new and did not realize that the extra lines would cause a problem. --but my example does not even get to the point of writing the pr.ini The problem I believe is that I cannot get the second pr.ini file to change the section name to [1],[2],[3],..... I know that it is probably a simple array issue but I am not familiar with working with arrays, and so I have asked for help. The answer might be in the help files but for persons that are just learning the program part of the problem is not knowing what to look for and the other is understanding what you are looking at. Most of this program has become second nature to those that have used it for a while but for Noobs it can be overwhelming. Link to comment Share on other sites More sharing options...
AoRaToS Posted June 29, 2009 Share Posted June 29, 2009 $S = IniReadSectionNames($PrIni) $S has not been declared globally so it won't work inside the functions. same for $Edit1, $Input1 I think you also have to change it to: $S = IniReadSectionNames($sIniFile) so you get the count of the sections in the first ini and write that many times to the second ini Or did I get this wrong? s!mpL3 LAN Messenger Current version 2.9.9.1 [04/07/2019] s!mpL3 LAN Messenger.zip s!mpL3 Link to comment Share on other sites More sharing options...
kttenneb Posted June 29, 2009 Author Share Posted June 29, 2009 $S = IniReadSectionNames($PrIni)$S has not been declared globally so it won't work inside the functions. same for $Edit1, $Input1I think you also have to change it to: $S = IniReadSectionNames($sIniFile)so you get the count of the sections in the first ini and write that many times to the second iniOr did I get this wrong?Thanks I will try those suggestions. The count in the second will not be the same as the first probably not 25 or 30. and it will reset on close. I plan on using the second to to review the selections made and print if needed. Link to comment Share on other sites More sharing options...
Valik Posted June 29, 2009 Share Posted June 29, 2009 ValikOK first I do not need to be attacked or ridiculed,I haven't even begun to attack you.Im just looking for a little help, if you do not want to help, why wast 3 min of your precious time to post something that does not help anyone.Why waste 3 minutes of several hundred people's time when you don't have to?The thing you aren't taking away from this is you need to stop and think. One of two things has happened here:Your thread title has nothing to do with your problem.Your thread title answers itself.So which particular scenario is it? Do you get the point yet?The answer might be in the help files but for persons that are just learning the program part of the problem is not knowing what to look for and the other is understanding what you are looking at.If you don't know what to look for... then you don't need to be using it yet. It's a rather simple concept, really. It means you have gaps in your knowledge that tutorials or just reading over the documentation can solve.Most of this program has become second nature to those that have used it for a while but for Noobs it can be overwhelmingThat is a personal problem. I've never found a language to be overwhelming because I've always been willing to sit down, read, think and play around until I understand something. Link to comment Share on other sites More sharing options...
kttenneb Posted June 29, 2009 Author Share Posted June 29, 2009 Valik, Again with the hostility. I may not have stated the problem correctly in the title. Sorry I have tried to explain what I would like to happen. The formatting problem as I stated was that I could not get the Ini to change the section name to [1],[2],[3],..... I am not trying to waste any ones time I am just looking for a little help and I thought this was a help forum. If you are not willing to help why even post? Link to comment Share on other sites More sharing options...
Valik Posted June 29, 2009 Share Posted June 29, 2009 Again with the hostility.I haven't been hostile to you yet. You'll know when I'm being hostile because you will suddenly lose the ability to post. I may not have stated the problem correctly in the title. SorryRight. You didn't think. Much like you still refuse to think. I am not trying to waste any ones time I am just looking for a little help and I thought this was a help forum.It's a hep forum for people who stop and think. If you are not willing to help why even post?I'm sorry that I am not trying to help you with one specific problem but rather trying to get you to do the one thing that will help you with all future problems. Maybe I need to do it in code? While $bStillNotStoppingAndThinking Stop() Think() WEnd Do you get it yet? Stop and think. So far you haven't thought about the thread title. You haven't thought about the problem and you haven't stopped to think about what I've said. Instead you keep going down the "oh mommy, big bad guy is being mean to me" route when I am in fact doing nothing of the sort. Have you even bothered to stop and experiment with the INI functions? Figure out how one function works and incorporate that into your script. Build things up in stages. Don't try to go from zero to done in one burst because when things don't work you don't have a clue where the problem is. Link to comment Share on other sites More sharing options...
kttenneb Posted June 29, 2009 Author Share Posted June 29, 2009 I have tried to apologize for misstating the title for the post. I have tried to restate my issue. I have thought out what I would like the program to do. I have experimented with the ini functions and have not been able to get it to work. The example script is a combination of about 4 different isolated scripts that I created. I was able to write the content of the edit1 to the ini file as in the example with the spaces and extra lines so i did not know that that would be an issue. In my experimentation the only example that created the dynamic GUI correctly was one that used[1],[2],[3].... in the section name. It was also an ini that I created from scratch not using the program to write it. I am not looking for someone to write my script I was just looking for a nudge in the right direction. I am also not wanting to feed any ones power trip, I just asked a simple question. Link to comment Share on other sites More sharing options...
Valik Posted June 29, 2009 Share Posted June 29, 2009 In my experimentation the only example that created the dynamic GUI correctly was one that used[1],[2],[3].... in the section name. It was also an ini that I created from scratch not using the program to write it.So generate the INI file using static data but do it programmatically. Then once you figure out how to do that, start changing the static data to dynamic data harvested from your other input source. I am not looking for someone to write my script I was just looking for a nudge in the right direction.Then what are you looking for? Because if you get any more of a nudge from me you are going to leave this planet. I am also not wanting to feed any ones power trip, I just asked a simple question.Yawn. Be original or be quiet. Link to comment Share on other sites More sharing options...
Proph Posted June 29, 2009 Share Posted June 29, 2009 What Valik is pointing out is you are trying to do an odd senario. Why are you wanting the output to be like this: Solution= Button 4 It is not correct ini structure to have a new line after the "=". Ini files are always structured: Key=Value Is there a reason you have to have it on a new line? You would simplify your task much more if you have the ini format correct. To do what you want to do I think is much more complicated then you think. You can not do it using iniread/write funcs. You would need to do some file reading and filewriting specifically under the key= you specify... plus you will need to make sure it is in the section you are specifying. Which will slow down your job much more than it needs to be. Link to comment Share on other sites More sharing options...
picea892 Posted June 29, 2009 Share Posted June 29, 2009 if you write and read to a txt file you can have your cake and eat it to. This is a lot more work and effort for little gain in my opinion. Link to comment Share on other sites More sharing options...
kttenneb Posted June 30, 2009 Author Share Posted June 30, 2009 (edited) What Valik is pointing out is you are trying to do an odd senario. Why are you wanting the output to be like this: Solution= Button 4 It is not correct ini structure to have a new line after the "=". Ini files are always structured: Key=Value Is there a reason you have to have it on a new line? You would simplify your task much more if you have the ini format correct. To do what you want to do I think is much more complicated then you think. You can not do it using iniread/write funcs. You would need to do some file reading and filewriting specifically under the key= you specify... plus you will need to make sure it is in the section you are specifying. Which will slow down your job much more than it needs to be. No that is not the problem that I am having. I can restructure the second ini no problem. I am having a problem building an array in the program based on clicks and passing it to the ini so that the section headings are [1],[2],[3] instead of [item1], [item2], [item3] like the first ini. The reason that I want to try to do it that way is because the Print_Select() function looks at the second ini file and creates a dynamic list of check boxes of the items that were clicked on. When I have tried the Print_Select() function with an ini file like the first one with [item1], [item2] it gives me check boxes with no label. When I have used a static (one I wrote manually) ini with [1],[2],[3]sections it has worked like I want it to but I want the second ini file to be created from the list of items clicked to that point. I have not been able to format the section headings to just [1],[2],[3] to even see if it will work that way. If it will not work this way fine I will figure out something else. I have unsuccessfully tried to explain this 3 or 4 times now. I figured out how to write it directly to a txt doc but then I thought of the added feature of being able to select the items to print from a dynamically created GUI or list. Edited June 30, 2009 by kttenneb Link to comment Share on other sites More sharing options...
ajag Posted June 30, 2009 Share Posted June 30, 2009 >$title = IniRead($PRini, $x, "Title", "") Why the sections must be [1], [2], ...? (I don't know if section names can be numeric). If you name the sections [sec1], [sec2], [sec3] you can read them with $title = IniRead($PRini, "sec" & $x, "Title", "") A-Jay Rule #1: Always do a backup        Rule #2: Always do a backup (backup of rule #1) Link to comment Share on other sites More sharing options...
kttenneb Posted June 30, 2009 Author Share Posted June 30, 2009 >$title = IniRead($PRini, $x, "Title", "") Why the sections must be [1], [2], ...? (I don't know if section names can be numeric). If you name the sections [sec1], [sec2], [sec3] you can read them with $title = IniRead($PRini, "sec" & $x, "Title", "") A-Jay Thanks for the reply I will try it Link to comment Share on other sites More sharing options...
wraithdu Posted June 30, 2009 Share Posted June 30, 2009 (edited) Of course section names can be numeric strings. Numbers are perfectly valid strings as well. As stated before, you've missing the heart of the matter. You don't understand how to work with INIs, dynamic data, or both. IniWrite("test.ini", 1, "key", "value") IniWrite("test.ini", "2", "key2", "value2") Works just fine. Edited June 30, 2009 by wraithdu Link to comment Share on other sites More sharing options...
kttenneb Posted July 1, 2009 Author Share Posted July 1, 2009 Of course section names can be numeric strings. Numbers are perfectly valid strings as well. As stated before, you've missing the heart of the matter. You don't understand how to work with INIs, dynamic data, or both. IniWrite("test.ini", 1, "key", "value") IniWrite("test.ini", "2", "key2", "value2") Works just fine. OK-- Looking closer at my code the problem could be in the following section. CODEFunc Print_Select() $Section = IniReadSectionNames($PRini) GUICreate("test") $print = GUICtrlCreateButton("Print", 212, 75, 75, 25) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Exit Else Dim $Check[uBound($Section) ] Dim $Solution[uBound($Section) ] Local $nLeft = 25, $nTop = 25, $nWidth = 200, $nHeight = 25 For $x = 1 To $Section[0] $Check[$x] = GUICtrlCreatecheckbox(IniRead($PRini, $x, "Title", ""), $nLeft, $nTop, $nWidth, $nHeight) $Solution[$x] = IniRead($PRini, $x, "Solution", "") $nTop += 35 Next EndIf because it is looking at the ini and reading the section heading as the number of the check box created. for example using the function above and using an ini file with these entries [3] Title=SAVE AS [4] Title=FORMS >>NEW SHEET [10] Title=OPTIONS >>RESET INPUT [111] Title=WINDOW >>CLOSE ALL [345] Title=FORMS >>RETURN TO LINK LIST Displays a Gui with 5 check boxes box 1 and 2 have no label box 3 reads "Save As" box 4 reads "FORMS >>NEW SHEET" and box 5 is blank because it is using the values of the section headings to determine the check box number and 10, 111, and 345 are way out of the range of the list of buttons. not sure if I will be able to get it to work or not but I know why it is broken. I will find a solution or hit it from a different angle. Thanks for all of the feedback and sorry for the waste of time. Link to comment Share on other sites More sharing options...
wraithdu Posted July 1, 2009 Share Posted July 1, 2009 Read the docs and sit down and think about what you're doing first. 1) IniReadSectionNames() returns the count of the sections in [0], so Dim $Check[$Section[0]] Dim $Solution[$Section[0]] 2) You're reading the section names, so USE them IniRead($PRini, $Section[$x], "Title", "") Link to comment Share on other sites More sharing options...
kttenneb Posted July 1, 2009 Author Share Posted July 1, 2009 Great thanks that was what I was looking for!! 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