brad25 Posted April 13, 2011 Share Posted April 13, 2011 The problem I am having is loading an ini file's section to a inputbox. I'm using 3 ini files and I write to them each file has its on section. When I try to call that data to the textbox I get 1 witch is an error of some sort. here's the part of code im having problems with and as you see below I read input4 to open the ini file it works to write. $read1 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\"& GUICtrlRead($Input4) & "a.ini", "Section1") $read2 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "b.ini", "Section2") $read3 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "c.ini", "Section3") GUICtrlSetData( $input1 , $read1) GUICtrlSetData( $input2 , $read2) GUICtrlSetData( $input3 , $read3) Full code expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\documents and settings\bryan theard\desktop\fuuuuuu7uu.kxf $Form1_1 = GUICreate("Form1", 771, 443, -1, -1) $Button1 = GUICtrlCreateButton("Load", 80, 32, 49, 17, 0) $Save = GUICtrlCreateButton("Save", 352, 408, 81, 25, 0) $Miles = GUICtrlCreateLabel("Miles", 32, 104, 140, 17) $Label1 = GUICtrlCreateLabel("Date", 216, 104, 140, 17) $Description = GUICtrlCreateLabel("Description", 416, 104, 140, 17) $Input1 = GUICtrlCreateInput("Input1", 24, 168, 169, 100) $Input2 = GUICtrlCreateInput("Input1", 208, 168, 177, 100) $Input3 = GUICtrlCreateInput("Input3", 400, 168, 345, 100) $Input4 = GUICtrlCreateInput("Input4", 24, 32, 49, 21) $Group1 = GUICtrlCreateGroup("", 16, 152, 185, 129) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("", 200, 152, 193, 129) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group3 = GUICtrlCreateGroup("", 392, 152, 361, 129) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group4 = GUICtrlCreateGroup("Miles", 24, 88, 169, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group5 = GUICtrlCreateGroup("Date", 208, 88, 177, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group6 = GUICtrlCreateGroup("Description", 400, 88, 345, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group7 = GUICtrlCreateGroup(" Latest Record", 16, 72, 737, 73) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group8 = GUICtrlCreateGroup("Unit#", 16, 16, 129, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group9 = GUICtrlCreateGroup("Update", 16, 296, 737, 97) $Milagee = GUICtrlCreateInput("", 24, 336, 161, 21) $Date = GUICtrlCreateInput("Date", 216, 336, 161, 21) $Input5 = GUICtrlCreateInput("Input5", 400, 312, 345, 67) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label2 = GUICtrlCreateLabel("Fleet Maintenance Records", 264, 24, 359, 36) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x316AC5) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### func write() ;;;; $sInia = "C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "a.ini" $sInib = "C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "b.ini" $sInic = "C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "c.ini" $sData = GUICtrlRead($Milagee) $sdData = GUICtrlRead($Date) $sddData = GUICtrlRead($Input5) IniWriteSection($sInia, "Section1" , $sData) IniWriteSection($sInib, "Section2" , $sdData) IniWriteSection($sInic, "Section3" , $sddData) EndFunc ;lables func read() $miless = FileReadLine("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "a.ini", 2) GUICtrlSetData($Miles , $miless) $datesl = FileReadLine("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "b.ini", 2) GUICtrlSetData($Label1 , $datesl) $dec = FileReadLine("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "c.ini", 2) GUICtrlSetData($Description , $dec) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $read1 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\"& GUICtrlRead($Input4) & "a.ini", "Section1") $read2 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "b.ini", "Section2") $read3 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "c.ini", "Section3") GUICtrlSetData( $input1 , $read1) GUICtrlSetData( $input2 , $read2) GUICtrlSetData( $input3 , $read3) EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch if $nmsg = $save Then write() if $nmsg = $Button1 Then read() WEnd Link to comment Share on other sites More sharing options...
BrewManNH Posted April 13, 2011 Share Posted April 13, 2011 IniReadSection returns an array, you are using it incorrectly to populate the inputs. If your INI file section contains more than one entry it won't work even if you loop through the array because it will only set the Input to the last item in the section. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
brad25 Posted April 14, 2011 Author Share Posted April 14, 2011 IniReadSection returns an array, you are using it incorrectly to populate the inputs. If your INI file section contains more than one entry it won't work even if you loop through the array because it will only set the Input to the last item in the section.How can I get it to read the entire section? there could be up to 10-15 lines in 1 section. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 14, 2011 Share Posted April 14, 2011 (edited) You'll need to loop through the $read1 array similar to something like this: $read1 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "a.ini", "Section1") For $I = 1 to $read1[0][0] ConsoleWrite($read1[$I][0] & "=" & $read1[$I][1] Next If you run this in Scite you can see what the section "Section1" contains as the key/value pairs. How you want to handle that information I leave up to you. Also, your IniWriteSection is formatted incorrectly as well. When you write to the INI file with that command the data has to be a 2D array or a delimited string. From the help file: If the data is a string, then each key=value pair must be delimited by @LF. If the data is an array, the array must be 2-dimensional and the second dimension must be 2 elements. Edited April 14, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
brad25 Posted April 14, 2011 Author Share Posted April 14, 2011 You'll need to loop through the $read1 array similar to something like this: $read1 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "a.ini", "Section1") For $I = 1 to $read[0][0] ConsoleWrite($read[$I][0] & "=" & $read[$I][1] Next If you run this in Scite you can see what the section "Section1" contains as the key/value pairs. How you want to handle that information I leave up to you. Also, your IniWriteSection is formatted incorrectly as well. When you write to the INI file with that command the data has to be a 2D array or a delimited string. i'm sorry im a little confused how do i declare $read? $read = GUICtrlSetData( $input1 , $read1)? Link to comment Share on other sites More sharing options...
BrewManNH Posted April 14, 2011 Share Posted April 14, 2011 Sorry, typo on the variable name, I corrected it in the post above. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
brad25 Posted April 14, 2011 Author Share Posted April 14, 2011 (edited) Sorry, typo on the variable name, I corrected it in the post above.ok got a subscript used with non-array variable when trying thisalso how does the data get into input1? Edited April 14, 2011 by brad25 Link to comment Share on other sites More sharing options...
BrewManNH Posted April 14, 2011 Share Posted April 14, 2011 Sounds like your ini file isn't formatted correctly. If it was written from the write() function, then it won't be formatted right. This is an example of a properly fomatted ini file: [Sections] 1="User Info" [Attributes.1] 1="Asset Tag" 2="Employee ID" 3="Primary" 4="Description" 5="Location" 6="Area" 7="Remarks" 8="Date Placed" [Attributes.1.1] ID = 1 Type = String(4) [Attributes.1.2] ID = 2 Type = String(5) [Attributes.1.3] ID = 3 Type = String(3) [Attributes.1.4] ID = 4 Type = String(50) [Attributes.1.5] ID = 5 Type = String(50) [Attributes.1.6] ID = 6 Type = String(50) [Attributes.1.7] ID = 7 Type = String(50) [Attributes.1.8] ID = 8 Type = Date Each section name is inside square brackets, and inside those sections the key/value pair has to be formatted as Key=Value. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
brad25 Posted April 14, 2011 Author Share Posted April 14, 2011 I set my ini up properly and still getting that subscript used with non-array variable. Im getting it on this code For $I = 1 to $read1[0][0] Link to comment Share on other sites More sharing options...
BrewManNH Posted April 14, 2011 Share Posted April 14, 2011 Try using this code, I added some error checking. Take note of the IniReadSection line, you'll need to make sure that the INI file being read from is hard coded in that line. $read1 = IniReadSection("C:\Documents and Settings\Bryan Theard\Desktop\DB\" & GUICtrlRead($Input4) & "a.ini", "Section1"); <<< Change this to the path and name of your ini file without using the GUICtrlRead. If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $I = 1 to $read[0][0] ConsoleWrite($read[$I][0] & "=" & $read[$I][1] Next EndIf If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
brad25 Posted April 14, 2011 Author Share Posted April 14, 2011 It reads now but only putting 1 line in my input I tried this GUICtrlSetData( $input1 , $read1[$I][1] & @CRLF & $read1[$I][2]) It does not goto the second line If i leave out the @ctrl it shows first and second line of my ini in the same line in my input box. Link to comment Share on other sites More sharing options...
brad25 Posted April 15, 2011 Author Share Posted April 15, 2011 BrewManNH Help lol Link to comment Share on other sites More sharing options...
BrewManNH Posted April 15, 2011 Share Posted April 15, 2011 Change your Input creation lines to include the $ES_Multiline style. $Input1 = GUICtrlCreateInput("Input1", 24, 168, 169, 100, BitOR($ES_MULTILINE , $GUI_SS_DEFAULT_INPUT)) Change all instances of these where you want more than one line in your inputs. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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