Sign in to follow this  
Followers 0
chssoccer

INI section and key - Solved

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I have a buddylist program and what it does is searches for buddy names in an external application and the external app returns the table that buddy was sitting at. Well I want to take those tables that the buddy was sitting at and put them in an .ini file in a section called OnlineBuddies, then the key will be the buddy's name. So if the tables are Nemo, Hotspring, and Mega and the buddy sitting at these tables is called Wildman then I want the Ini to look like this:

[OnlineBuddies]
Wildman=Nemo,Hotspring,Mega

Now, what I mentioned above I have working perfectly. The problem I have is when I search for the next buddy and his info comes up and I write it in the ini it totally overwrites the previous buddy's info and what I want it to look like is this:

Wildman=Nemo,HotSpring,Mega
NextBuddy=Supra,Jock,Fatty

How can I accomplish this? Here's my code if you need.

For $i = 1 To $buddiesSearch[0]
                            ControlSend("Find Player", "", $Edit, $buddiesSearch[$i] & "{Enter}"); Searches for each individual player
                            $buddyname = ControlGetText("Find Player", "", 1001)
                            Sleep(100)
                            MsgBox(0, "", $buddyname)
                            $removeplayer = ControlGetHandle("Find Player", "", 261)
                            ControlClick("Find Player", "", 261); clicks remove player button
                            $ListBox = ControlGetHandle ( "Find Player", "", "ListBox1" )
                        Next
                            $count = _GUICtrlListCount($ListBox)
                            If $count < 1 Then $count = 1; correct count so our For loop goes one time, no matter user is off/online
                        For $a = 0 To $count - 1
                            $text = _GUICtrlListGetText($ListBox, $a); Gets the tables/items
                            If $text = -1 Then
                                $text = "Offline"
                            Else
                            EndIf
                            $text = StringReplace($text, "-", "|")
                            $item = GUICtrlCreateListViewItem($text, $sListview)
                            $Online = _GUICtrlListCount($ListBox)
                            If $Online > 0 Then
                                INIDelete("C:\buddies.ini", "OnlineBuddies"); Clears/Deletes the OnlineBuddies sections
                                INIWrite("C:\buddies.ini", "OnlineBuddies", IniReadSection("C:\buddies.ini", "OnlineBuddies") & $buddyname, IniRead("C:\buddies.ini", "OnlineBuddies", $buddyname, "") & $text & ","); Writes the buddy's name and table to the ini
                                GUICtrlSetImage($nListview, "shell32.dll", -138)
                            Else
                                GUICtrlSetImage($nListview, "shell32.dll", -110)
                            EndIf
                            ControlSetText("Find Player", "", "Edit1", "")
                        Next
Edited by chssoccer

Share this post


Link to post
Share on other sites



Its not hard.

$result = IniRead()

IniWrite(.... $result & ",NewPlayerName")

Share this post


Link to post
Share on other sites

I think your problem might be:

INIDelete("C:\buddies.ini", "OnlineBuddies"); Clears/Deletes the OnlineBuddies sections

Are you not deleting the section here, then writing the new name? Effectively overwriting it.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Its not hard.

$result = IniRead()

IniWrite(.... $result & ",NewPlayerName")

umm no. because that doesn't work. and I have no idea what the point is for that iniread at the top.

Share this post


Link to post
Share on other sites

umm no. because that doesn't work. and I have no idea what the point is for that iniread at the top.

Lets see, you said you want to append to what is already in the file so you will have to read it first.

test.ini:

[OnlineBuddies]

Wildman=Nemo,Hotspring,Mega

If you want to add a table you do this:

$newTable = "Nevada"

$result = IniRead("test.ini", "OnlineBuddies", "Wildman")

IniWrite("test.ini", "OnlineBuddies", "Wildman", $result & "," & $newTable)

If you want to add a new player:

IniWrite("test.ini", "OnlineBuddies", "NextBuddy", "Supra,Jock,Fatty")

Share this post


Link to post
Share on other sites

Lets see, you said you want to append to what is already in the file so you will have to read it first.

test.ini:

[OnlineBuddies]

Wildman=Nemo,Hotspring,Mega

If you want to add a table you do this:

$newTable = "Nevada"

$result = IniRead("test.ini", "OnlineBuddies", "Wildman")

IniWrite("test.ini", "OnlineBuddies", "Wildman", $result & "," & $newTable)

If you want to add a new player:

IniWrite("test.ini", "OnlineBuddies", "NextBuddy", "Supra,Jock,Fatty")

That still can't work because I can't use actual names for the players and tables because I'm searching for a buddy that is online and may be sitting at any table under any name. And multiple buddies, which is the only reason i need the ini to look like this

BuddyName=Table1,Table2,Table3
NewBuddyName=NewTable1,NewTable2,NewTable3

Share this post


Link to post
Share on other sites

That still can't work because I can't use actual names for the players and tables because I'm searching for a buddy that is online and may be sitting at any table under any name. And multiple buddies, which is the only reason i need the ini to look like this

BuddyName=Table1,Table2,Table3
NewBuddyName=NewTable1,NewTable2,NewTable3
Is it even possible?

Share this post


Link to post
Share on other sites

Maybe you weren't clear enough in what you need.

IniWrite("test.ini","Section","Key1","Value1, Value2, Value3") <==== Write Key1 = Value1, Value2, Value3

IniWrite("test.ini","Section","Key2","Value4, Value5, Value6") <==== Write Key2 = Value4, Value5, Value6

Where are you getting stuck? There is no reason the first key name would be overwritten unless you use the same name on the second write.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0