FireLordZi Posted February 4, 2008 Share Posted February 4, 2008 (edited) I've got different keys in my .ini that are actually the names of buddies. They keys values are the tables the buddy is currently sitting at. Also appended to the tables are keys, so it could look like this for example: [OnlineBuddies] Nemo=Table1;Table2;Table3;~2-3-08 Ando=Table4;Table5;Table6;~2-3-08 I have a listview that I want each date to appear in a certain column which I can do if I specify an exact keyname to read, but I can't. And it's because I want ALL the dates from ALL the buddies to appear in the listview. So I created a For Loop so I can do it for each buddy. $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w In $readsection[0][0] $sIni = IniRead("C:\buddies.ini", "OnlineBuddies", $readsection[$w][0], "") MsgBox(0, "", $readsection[$w][0]) $var0 = StringSplit($sIni, "~") $var1 = StringSplit($sIni, ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value In $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf When I check what each key is, if I have two keys in there, it will return the name of the first key twice, same if I have three keys, it will return the name of the first key three times. What's wrong with my loop? Edited February 4, 2008 by FireLordZi While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I've got different keys in my .ini that are actually the names of buddies. They keys values are the tables the buddy is currently sitting at. Also appended to the tables are keys, so it could look like this for example: [OnlineBuddies] Nemo=Table1;Table2;Table3;~2-3-08 Ando=Table4;Table5;Table6;~2-3-08 I have a listview that I want each date to appear in a certain column which I can do if I specify an exact keyname to read, but I can't. And it's because I want ALL the dates from ALL the buddies to appear in the listview. So I created a For Loop so I can do it for each buddy. $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w In $readsection[0][0] $sIni = IniRead("C:\buddies.ini", "OnlineBuddies", $readsection[$w][0], "") MsgBox(0, "", $readsection[$w][0]) $var0 = StringSplit($sIni, "~") $var1 = StringSplit($sIni, ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value In $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf When I check what each key is, if I have two keys in there, it will return the name of the first key twice, same if I have three keys, it will return the name of the first key three times. What's wrong with my loop? $readsection[$w][0] = Key $readsection[$w][1] = Value I don't see anywhere that you change the second dimension. Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 $readsection[$w][0] = Key $readsection[$w][1] = Value I don't see anywhere that you change the second dimension. I don't understand what you mean? While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I don't understand what you mean?Okay I reread the question and I don't understand it. What I'm saying is you are just getting keys your not getting any values. Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 Okay I reread the question and I don't understand it. What I'm saying is you are just getting keys your not getting any values.I'm confusing you and myself. I'm getting the keys because I want to read all of them and at the same time write to them.But the again, I would have to get the values after I get the key then read it. Maybe it would be easier if I just asked how to I read all keys in a section and for each one write all the data into a listview? While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 (edited) I'm confusing you and myself. I'm getting the keys because I want to read all of them and at the same time write to them. But the again, I would have to get the values after I get the key then read it. Maybe it would be easier if I just asked how to I read all keys in a section and for each one write all the data into a listview? When you do an IniReadSection it returns the Keys And the Values, as I explained the 2D Array. Run this $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w In $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value In $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf Edited February 4, 2008 by Thatsgreat2345 Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 (edited) When you do an IniReadSection it returns the Keys And the Values, as I explained the 2D Array. Run this $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w In $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value In $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf I'm getting an error on the For In line with readsection[0][0]. It says variable must be a type of 'object'? Edited February 4, 2008 by FireLordZi While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I'm getting an error on the For In line. It says variable must be a type of 'object'?Change In to To Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 Now it says For statement is badly formatted. While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 Now it says For statement is badly formatted. $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w To $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value To $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $w To $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) Next For $value To $var0 $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf Same error... Shouldn't there be a '= 1' after the For $w? While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 (edited) Same error... Shouldn't there be a '= 1' after the For $w? Here look at this #include <GUIConstants.au3> Global $Text $Form1 = GUICreate("Form1", 633, 447, 193, 125) $ListView1 = GUICtrlCreateListView("Tables|Date", 56, 32, 417, 273) $readsection = IniReadSection(@DesktopDir & '\some.ini', "OnlineBuddies") If IsArray($readsection) Then For $w = 1 To $readsection[0][0] $Date = StringSplit($readsection[$w][1], "~") $Tables = StringSplit($Date[1], ";") For $i = 1 To UBound($Tables) - 1 $Text &= $Tables[$i] & ',' Next GUICtrlCreateListViewItem(StringTrimRight($Text,2) & '|' & $Date[2],$ListView1) $Text = '' Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited February 4, 2008 by Thatsgreat2345 Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 Okay what are you trying to do in the first place because if this is your complete code then I have no idea what your doing. And why you are using for loops for the last part? $var0 has to be a NUMBER as well. If $Var0 returns a string or something the last for loop won't do anything. Even though the last for loop all it is doing is setting the same exact text over and over I took out the second For loop, I thought about what you said and it wasn't needed. $var0 is a string, it is the value to the key currently being read. Again, I'm trying somehow to get this code to read all sections, starting with the first one, write the value into a listview, and do the same for the second one and for all of them. Just a little touchup. It sets the value for the first key but not for the second: If IsArray($readsection) Then For $w = 1 To $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I took out the second For loop, I thought about what you said and it wasn't needed. $var0 is a string, it is the value to the key currently being read. Again, I'm trying somehow to get this code to read all sections, starting with the first one, write the value into a listview, and do the same for the second one and for all of them. Just a little touchup. It sets the value for the first key but not for the second: If IsArray($readsection) Then For $w = 1 To $readsection[0][0] MsgBox(0, "", 'Key: ' & $readsection[$w][0] & @CRLF & 'Value: ' & $readsection[$w][1]) $var0 = StringSplit($readsection[$w][1], "~") $var1 = StringSplit($readsection[$w][1], ";") $date_ = StringTrimLeft($var1[UBound($var1)-1], 1) $dateitems = _GUICtrlListViewSetItemText($nListview, 0, 2, $date_); Sets the date from the INI file Next EndIf because you aren't changing where it is setting. I recommend using GuiCtrlCreateListViewItem. Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 Here look at this #include <GUIConstants.au3> Global $Text $Form1 = GUICreate("Form1", 633, 447, 193, 125) $ListView1 = GUICtrlCreateListView("Tables|Date", 56, 32, 417, 273) $readsection = IniReadSection(@DesktopDir & '\some.ini', "OnlineBuddies") If IsArray($readsection) Then For $w = 1 To $readsection[0][0] $Date = StringSplit($readsection[$w][1], "~") $Tables = StringSplit($Date[1], ";") For $i = 1 To UBound($Tables) - 1 $Text &= $Tables[$i] & ',' Next GUICtrlCreateListViewItem(StringTrimRight($Text,2) & '|' & $Date[2],$ListView1) $Text = '' Next EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I'm getting an error at line 14 saying Array variable has incorrect number of subscripts or subscript dimension range exceeded. While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I'm getting an error at line 14 saying Array variable has incorrect number of subscripts or subscript dimension range exceeded.be sure to change the inireadsection to your actual file as I have changed it. Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 I did, I created a some.ini and a section called 'OnlineBuddies' and still got the error. Don't think it has to do with the ini... While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
FireLordZi Posted February 4, 2008 Author Share Posted February 4, 2008 Never mind, it's working. You were right. Didn't have the semi-colons. While Alive() { DrinkWine(); }AutoIt Programmer Link to comment Share on other sites More sharing options...
rasim Posted February 4, 2008 Share Posted February 4, 2008 #include <GuiConstantsEx.au3> #include <GuiListView.au3> Global $readsection $hGui = GuiCReate("Test", 300, 200) $hListView = _GUICtrlListView_Create($hGui, "Items|SubItems", 10, 10, 280, 180, -1, $WS_EX_CLIENTEDGE) $readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies") If IsArray($readsection) Then For $i = 1 To $readsection[0][0] $item = StringRegExp($readsection[$i][1], "~?(\d{1,}-\d{1,}-\d{1,})", 1) _GUICtrlListView_AddItem($hListView, $item[0]) Next EndIf GUISetState() Do Until GUIGetMsg() = -3 Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted February 4, 2008 Share Posted February 4, 2008 I did, I created a some.ini and a section called 'OnlineBuddies' and still got the error. Don't think it has to do with the ini...Just change the location back to your other location of the Ini file. It runs just fine for me using the only 2 data keys you gave me. 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