JohnOne Posted August 30, 2009 Share Posted August 30, 2009 (edited) I have a script to write an ini file and Im trying to make one to read it correctlyWhen I run script to create it, it looks like this after some fields have been enteredNot all the fields need to be filled for my purposes but after running the script to read the ini I get thisAs you can see it also returns the commas without even having data in themMy goal is to have it return just the data between the commas (am I right in thinking data is supposed to be separated with commas ?)The values will be strings rather than integersCan anyone help me with this ?I cant even figure if its something I need to change\add in the gui or the readini script.Code for guiexpandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Form1_1 = GUICreate("Test box", 230, 181) Global $Label1 = GUICtrlCreateLabel("1", 8, 40, 39, 17) Global $Input1 = GUICtrlCreateInput("", 48, 40, 25, 21) Global $Label2 = GUICtrlCreateLabel("2", 80, 40, 39, 17) Global $Input2 = GUICtrlCreateInput("", 120, 40, 25, 21) Global $Label3 = GUICtrlCreateLabel("3", 152, 40, 39, 17) Global $Input3 = GUICtrlCreateInput("", 192, 40, 25, 21) Global $Label4 = GUICtrlCreateLabel("4", 8, 72, 39, 17) Global $Input4 = GUICtrlCreateInput("", 48, 72, 25, 21) Global $Label5 = GUICtrlCreateLabel("5", 80, 72, 39, 17) Global $Input5 = GUICtrlCreateInput("", 120, 72, 25, 21) Global $Label6 = GUICtrlCreateLabel("6", 152, 72, 39, 17) Global $Input6 = GUICtrlCreateInput("", 192, 72, 25, 21) Global $Label7 = GUICtrlCreateLabel("7", 8, 104, 39, 17) Global $Input7 = GUICtrlCreateInput("", 48, 104, 25, 21) Global $Label8 = GUICtrlCreateLabel("8", 80, 104, 39, 17) Global $Input8 = GUICtrlCreateInput("", 120, 104, 25, 21) Global $Label9 = GUICtrlCreateLabel("9", 152, 104, 39, 17) Global $Input9 = GUICtrlCreateInput("", 192, 104, 25, 21) Global $Button1 = GUICtrlCreateButton("Cancel", 8, 144, 75, 25, $WS_GROUP) Global $Button2 = GUICtrlCreateButton("Next", 136, 144, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Exit Case $Button2 $nData = "thekey = " & GUICtrlRead($Input1) & ", " & GUICtrlRead($Input2) & ", " & GUICtrlRead($Input3) & ", " & GUICtrlRead($Input4) & ", " & GUICtrlRead($Input5) & ", " & GUICtrlRead($Input6) & ", " & GUICtrlRead($Input7) & ", " & GUICtrlRead($Input8) & ", " & GUICtrlRead($Input9) $sIni = @ScriptDir & "\AutoIt-Test.ini" ; create a new section using a variable as input. IniWriteSection($sIni, "Section", $nData) EndSwitch WEndCode for read$var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") MsgBox(4096, "Result", $var)Also, is there a control to auto tab the fields in the gui after two charactors\numbers are entered ?Sorry for the novice questions.John Edited August 30, 2009 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
aNewLyfe Posted August 30, 2009 Share Posted August 30, 2009 you can split $nData, try StringSplit($nData,",") then: If isArray($nData) Then $maxindex = $nData[0] for $i = 1 to $maxindex $SplittedData = $maxindex[$i] msgbox(0,$i,$SplittedData) next Endif this will give you values 11 to 44 one by one. For your second question, add a little code to while. if strlen(guictrlread($input)) >= 2 then send("{TAB}") or guictrlsetstate($input2,$GUI_FOCUS) endif ~ Every Living Thing is a Code Snippet of World Application ~ Link to comment Share on other sites More sharing options...
JohnOne Posted August 30, 2009 Author Share Posted August 30, 2009 Thanks very much for reply I'l try to get my head around that now Do I have to create an array first to use this method ? cheers AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
aNewLyfe Posted August 30, 2009 Share Posted August 30, 2009 Thanks very much for replyI'l try to get my head around that nowDo I have to create an array first to use this method ?cheersnope, stringsplit allready doing that ~ Every Living Thing is a Code Snippet of World Application ~ Link to comment Share on other sites More sharing options...
JohnOne Posted August 30, 2009 Author Share Posted August 30, 2009 (edited) I appreciate your help mate But I having a problem I assumed The script to add would be in the read script and so $nData would be $var I put it like this $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") StringSplit($var,",") If isArray($var) Then $maxindex = $var[0] for $i = 1 to $maxindex $SplittedData = $maxindex[$i] msgbox(0,$i,$SplittedData) next Endif ;MsgBox(4096, "Result", $var) The script runs without returning any errors but no msgbox appears, so not sure if its even reading it. Is there an #include I need to add for arrays ? (never used them before) Edited August 30, 2009 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
aNewLyfe Posted August 30, 2009 Share Posted August 30, 2009 I appreciate your help mate But I having a problem I assumed The script to add would be in the read script and so $nData would be $var I put it like this $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") StringSplit($var,",") If isArray($var) Then $maxindex = $var[0] for $i = 1 to $maxindex $SplittedData = $maxindex[$i] msgbox(0,$i,$SplittedData) next Endif ;MsgBox(4096, "Result", $var) The script runs without returning any errors but no msgbox appears, so not sure if its even reading it. Is there an #include I need to add for arrays ? (never used them before) So It looks $var isn't an array, cause of no data return with iniread or returned data doesn't contains commas. can you say what you got with MsgBox(4096, "Result", $var) command ? if there isn't any key in ini file, you have to use : inireadsection. try again with inireadsection(@ScriptDir & "\AutoIt-Test.ini", "Section"), if i guess right, you will get what u want. btw, you dont need to include array lib if you dont use _Array ... commands ~ Every Living Thing is a Code Snippet of World Application ~ Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2009 Author Share Posted August 31, 2009 (edited) If I comment away the if loop but leave stringsplit in I get same result as before$var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") StringSplit($var,",") ;If isArray($var) Then ;$maxindex = $var[0] ;for $i = 1 to $maxindex ;$SplittedData = $maxindex[$i] ;msgbox(0,$i,$SplittedData) MsgBox(4096, "Result", $var) ;next ;EndifEDIT:My ini file looks like this[Section] thekey = 11, 22, 33, 44, , , , , Edited August 31, 2009 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
aNewLyfe Posted August 31, 2009 Share Posted August 31, 2009 If I comment away the if loop but leave stringsplit in I get same result as before $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") StringSplit($var,",") ;If isArray($var) Then ;$maxindex = $var[0] ;for $i = 1 to $maxindex ;$SplittedData = $maxindex[$i] ;msgbox(0,$i,$SplittedData) MsgBox(4096, "Result", $var) ;next ;Endif EDIT: My ini file looks like this [Section] thekey = 11, 22, 33, 44, , , , , you have to continue declare the variable, it must be : $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") $var = StringSplit($var,",") then you can use $var[1] , 2 , 3 , 4 at msgbox but if $var isn't an array, you get error with this way ~ Every Living Thing is a Code Snippet of World Application ~ Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2009 Author Share Posted August 31, 2009 (edited) After a lot of reading around forum\help files and mistakillas help I managed to get to the point where the iniread code will splitt the strings and return the result. But it only returns the result of the indexes I ask it to $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") $var2 = StringSplit($var, ",") MsgBox(0, "Result", $var2[1] & $var2[2] & $var2[3] & $var2[4]) Can anyone help me understand the code to use in getting it only return the fields with data in ? EDIT: This seems to work, just not returning empty values $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") $var2 = StringSplit($var, ",") ;If $var2[0] <> 9 Then ; Exit ;EndIf MsgBox(0, "numofelements", $var2[0]) MsgBox(0, "Result", $var2[1] & $var2[2] & $var2[3] & $var2[4] & $var2[5] & $var2[6] & $var2[7] & $var2[8] & $var2[9]) Is this the correct way of going about this, or is there a simpler way ? Edited August 31, 2009 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Manjish Posted August 31, 2009 Share Posted August 31, 2009 Here: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Form1_1 = GUICreate("Test box", 230, 181) Global $Label1 = GUICtrlCreateLabel("1", 8, 40, 39, 17) Global $Input1 = GUICtrlCreateInput("", 48, 40, 25, 21) Global $Label2 = GUICtrlCreateLabel("2", 80, 40, 39, 17) Global $Input2 = GUICtrlCreateInput("", 120, 40, 25, 21) Global $Label3 = GUICtrlCreateLabel("3", 152, 40, 39, 17) Global $Input3 = GUICtrlCreateInput("", 192, 40, 25, 21) Global $Label4 = GUICtrlCreateLabel("4", 8, 72, 39, 17) Global $Input4 = GUICtrlCreateInput("", 48, 72, 25, 21) Global $Label5 = GUICtrlCreateLabel("5", 80, 72, 39, 17) Global $Input5 = GUICtrlCreateInput("", 120, 72, 25, 21) Global $Label6 = GUICtrlCreateLabel("6", 152, 72, 39, 17) Global $Input6 = GUICtrlCreateInput("", 192, 72, 25, 21) Global $Label7 = GUICtrlCreateLabel("7", 8, 104, 39, 17) Global $Input7 = GUICtrlCreateInput("", 48, 104, 25, 21) Global $Label8 = GUICtrlCreateLabel("8", 80, 104, 39, 17) Global $Input8 = GUICtrlCreateInput("", 120, 104, 25, 21) Global $Label9 = GUICtrlCreateLabel("9", 152, 104, 39, 17) Global $Input9 = GUICtrlCreateInput("", 192, 104, 25, 21) Global $Button1 = GUICtrlCreateButton("Cancel", 8, 144, 75, 25, $WS_GROUP) Global $Button2 = GUICtrlCreateButton("Next", 136, 144, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Exit Case $Button2 $nData = "thekey = " & GUICtrlRead($Input1) & ", " & GUICtrlRead($Input2) & ", " & GUICtrlRead($Input3) & ", " & GUICtrlRead($Input4) & ", " & GUICtrlRead($Input5) & ", " & GUICtrlRead($Input6) & ", " & GUICtrlRead($Input7) & ", " & GUICtrlRead($Input8) & ", " & GUICtrlRead($Input9) $sIni = @ScriptDir & "\AutoIt-Test.ini" ; create a new section using a variable as input. IniWriteSection($sIni, "Section", $nData) read() ExitLoop EndSwitch WEnd Func read() $var = IniRead(@ScriptDir & "\AutoIt-Test.ini", "Section", "thekey", "no data") $data=StringSplit($var,",") If isArray($data) Then $maxindex = $data[0] for $i = 1 to $maxindex msgbox(0,$i,$data[$i]) next Endif EndFunc ;MsgBox(4096, "Result", $var) [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2009 Author Share Posted August 31, 2009 (edited) Thanks to all This should be enough to get me moving along again Edited August 31, 2009 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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