Jump to content

Reading INI Section names


AlmarM
 Share

Recommended Posts

Hello,

I'm realy confused right now. Let me explain:

I have this file 'Farmville.ini'. It includes Section names wich I dont know (could always be editable).

I tried making a function to read the sections and their values, and set some data to certain input's.

But I can't seem to figure out what im supposed to do.

I'll add both sources, mayby makes things clear.

Farmville.ini

[Strawberrys]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Wheat]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Eggplant]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Soybeans]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Squash]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Pumpkins]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Artichokes]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Rice]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Raspberries]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Daffodils]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

My script (doesn't include my try because it failed sooooo hard)

Global $ctrlName, $ctrlBuy, $ctrlSell, $ctrlTime, $ctrlExp, $ctrlExpDay, $ctrlSBDay
Global $Open

$GUI = GUICreate("Farmville Reader", 255, 160)
$Input = GUICtrlCreateInput("", 10, 10, 200, 20)
$Search = GUICtrlCreateButton("...", 220, 10, 25, 20)
GUICtrlCreateLabel("Name:", 10, 40)
$ctrlName = GUICtrlCreateInput("Naam", 70, 35, 50)
GUICtrlCreateLabel("Buy:", 140, 40)
$ctrlBuy = GUICtrlCreateInput("Buy", 195, 35, 50)
GUICtrlCreateLabel("Sell:", 10, 70)
$ctrlSell = GUICtrlCreateInput("Sell", 70, 65, 50)
GUICtrlCreateLabel("Time:", 140, 70)
$ctrlTime = GUICtrlCreateInput("Time", 195, 65, 50)
GUICtrlCreateLabel("Exp:", 10, 100)
$ctrlExp = GUICtrlCreateInput("Exp", 70, 95, 50)
GUICtrlCreateLabel("Exp Day:", 140, 100)
$ctrlExpDay = GUICtrlCreateInput("Exp Day", 195, 95, 50)
GUICtrlCreateLabel("S/B Day:", 10, 130)
$ctrlSBDay = GUICtrlCreateInput("S/B Day", 70, 130, 50)

$Prev = GUICtrlCreateButton("<< Prev", 130, 130, 60, 20)
$Next = GUICtrlCreateButton("Next >>", 190, 130, 60, 20)

GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $Search
        $OpenDialog = FileOpenDialog("Select file...", @DesktopDir, "Farmville Files (*.ini)")
        
        GUICtrlSetData($Input, $OpenDialog)
        
        $Open = FileOpen(GUICtrlRead($Search), 0)
        _GetData(GUICtrlRead($Search))
    EndSwitch
WEnd

Func _GetData($sPath)
EndFunc

*Sorry for my bad english, can't think straight at the moment.* :D

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Have you seen the IniReadSectionNames ( "filename" ) function? This returns all the section names in an ini file.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Have you seen the IniReadSectionNames ( "filename" ) function? This returns all the section names in an ini file.

Yesh, that was my first mistake. It returns all Section names, then how do I read a specific key from THAT section and assign it to its controls?

Also, I have a Prev and Next button.

:D:huggles:

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Yesh, that was my first mistake. It returns all Section names, then how do I read a specific key from THAT section and assign it to its controls?

Also, I have a Prev and Next button.

:D:huggles:

Just use IniReadSectionNames() then based off of that use IniReadSection().

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Taken from the AutoIt Help files example, slightly modified:

$var = IniReadSectionNames("rawr.ini")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0]
    MsgBox(4096, "", $var[$i])
    Next
EndIf

and then to read keys, use

IniRead()
For $i = 1 To $var[0]
    $var2 = IniReadSection("rawr.ini", $var[$i])
    For $u = 1 To $var[0][0]
        MsgBox(4096, "", $var2[$u][0])
    Next
Next

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Nighty night. I'm not sure if that syntax is proper, or if it'll work (in theory, what I did is right...) I was rushed to go play some football with friends, and my ride came halfway through that post. You just need to change the rawr.ini to whatever, and you could try just running that. But those examples are pretty much straight from the help file, with a little modification

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

Nighty night. I'm not sure if that syntax is proper, or if it'll work (in theory, what I did is right...) I was rushed to go play some football with friends, and my ride came halfway through that post. You just need to change the rawr.ini to whatever, and you could try just running that. But those examples are pretty much straight from the help file, with a little modification

I need like "Section IDs", but I think I could get them from the Array the sections names are stored in. So i'll try some stuff. :D

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Yesh! Did it.

Result:

#include <Array.au3>

Global $ctrlName, $ctrlBuy, $ctrlSell, $ctrlTime, $ctrlExp, $ctrlExpDay, $ctrlSBDay
Global $Open, $Max, $Num = 2

$GUI = GUICreate("Farmville Reader", 255, 160)
$Input = GUICtrlCreateInput("", 10, 10, 200, 20)
$Search = GUICtrlCreateButton("...", 220, 10, 25, 20)
GUICtrlCreateLabel("Name:", 10, 40)
$ctrlName = GUICtrlCreateLabel("Naam", 70, 40, 50)
GUICtrlCreateLabel("Buy:", 140, 40)
$ctrlBuy = GUICtrlCreateInput("Buy", 195, 35, 50)
GUICtrlCreateLabel("Sell:", 10, 70)
$ctrlSell = GUICtrlCreateInput("Sell", 70, 65, 50)
GUICtrlCreateLabel("Time:", 140, 70)
$ctrlTime = GUICtrlCreateInput("Time", 195, 65, 50)
GUICtrlCreateLabel("Exp:", 10, 100)
$ctrlExp = GUICtrlCreateInput("Exp", 70, 95, 50)
GUICtrlCreateLabel("Exp Day:", 140, 100)
$ctrlExpDay = GUICtrlCreateInput("Exp Day", 195, 95, 50)
GUICtrlCreateLabel("S/B Day:", 10, 130)
$ctrlSBDay = GUICtrlCreateInput("S/B Day", 70, 130, 50)

$Prev = GUICtrlCreateButton("<< Prev", 130, 130, 60, 20)
$Next = GUICtrlCreateButton("Next >>", 190, 130, 60, 20)

GUISetState()
While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    Case $Search
        $OpenDialog = FileOpenDialog("Select file...", @DesktopDir, "Farmville Files (*.ini)")
        
        GUICtrlSetData($Input, $OpenDialog)
        
        _GetData(GUICtrlRead($Input), $Num)
        
    Case $Prev
        $Num -= 1
        If $Num = 0 Then $Num = 1
        _GetData(GUICtrlRead($Input), $Num)
        
    Case $Next
        $Num += 1
        If $Num = $Max Then $Num = $Max - 1
        _GetData(GUICtrlRead($Input), $Num)
    EndSwitch
WEnd

Func _GetData($sPath, $sNum)
    $Sections = IniReadSectionNames($sPath)
    $Section = IniReadSection($sPath, $Sections[$sNum])
    
    $Max = $Sections[0] + 1
    
    GUICtrlSetData($ctrlName, $Sections[$sNum])
    GUICtrlSetData($ctrlBuy, $Section[1][1])
    GUICtrlSetData($ctrlSell, $Section[2][1])
    GUICtrlSetData($ctrlTime, $Section[3][1])
    GUICtrlSetData($ctrlExp, $Section[4][1])
    GUICtrlSetData($ctrlExpDay, $Section[5][1])
    GUICtrlSetData($ctrlSBDay, $Section[6][1])
EndFunc

If you are curious, you could always test with this .ini

[Strawberrys]
buy=1
sell=1
time=1
exp=1
exp_day=1
sell_buy_day=1

[Wheat]
buy=2
sell=2
time=2
exp=2
exp_day=2
sell_buy_day=2

[Eggplant]
buy=3
sell=3
time=3
exp=3
exp_day=3
sell_buy_day=3

[Soybeans]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Squash]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Pumpkins]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Artichokes]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Rice]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Raspberries]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

[Daffodils]
buy=
sell=
time=
exp=
exp_day=
sell_buy_day=

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...