Jump to content

INI Array Help Needed


Recommended Posts

Hello I am trying to pull everything from a section in a ini file but need to batch it by each 4 lines then move to the next four lines in the section

my message box shows me the correct information but when it loops I get an error at $WorkingDir = $aArray[$iii][1]. So the idea is to have many entries under the [shortcuts] section without any limits. 

; Read the INI section. This will return a 2 dimensional array.
Local $aArray = IniReadSection($ssFilePath, "Shorcuts")

If Not @error Then
    for $i = 1 to $aArray[0][0]
        ; Set new timer
        $ii = $i
        $iii = $ii
        $iiii = $iii
        $ProgramEXEFullPath = $aArray[$i][1]
        ; update Timer to pull next line in INI file
        $ii = $i + 1
        $LNKPath = StringReplace($aArray[$ii][1],"[USERNAME]", @UserName)
        $LNKPath = StringReplace($LNKPath,"[PROFILEPATH]", @UserProfileDir)
        ; update Timer to pull next line in INI file
        $iii = $ii + 1
        $WorkingDir = $aArray[$iii][1]
        ; update Timer to pull next line in INI file
        $iiii = $iii + 1
        $Desc = $aArray[$iiii][1]
        ; debug msgbox
        msgbox(0,"INI File Varibles", $ProgramEXEFullPath & " | " & $LNKPath & " | " & $WorkingDir & " | " & $Desc)
        ; loop
        $i = $i +1  
    next
else
    msgbox(0,"Ahh Snap!", "Cannot read shortcuts.ini file, possible format incorrect or file currupted.")
endif

here is INI file

[Shorcuts]
ProgramEXEFullPath=C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE
LNKPath=C:\Users\[USERNAME]\Desktop\Word 2010.lnk
WorkingDir=C:\Program Files (x86)\Microsoft Office\Office14
Desc=Microsoft Word 2010

Not sure why it errors, I am doing this using 2 lines but I cant get the erorr to stop using 4, any help is greatly appreciated. 

Edited by digitalexpl0it
Link to comment
Share on other sites

  • Moderators

For $i = enums the array already, so remove this line: $i = $i +1

Edit:

And use the Step method:

For $i = 1 To $Array[0][0] Step 4 ;(or 3?)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Your forgetting to use the "Step" to your advantage

[Step <stepval>]

For $i = 1 To $Array[0][0] Step 4

EDIT: To slow it seems. :sweating:

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

digitalexpl0it,

If what you posted is the extent of your INI file you are overcomplicating this.  Consider the following...

; Read the INI section. This will return a 2 dimensional array.
local $ssFilePath = @scriptdir & '\initest.ini'
Local $aArray = IniReadSection($ssFilePath, "Shortcuts")

If Not @error Then
    $ProgramEXEFullPath = $aArray[1][1]
    $LNKPath = StringReplace($aArray[2][1],"[USERNAME]", @UserName)
    $LNKPath = StringReplace($LNKPath,"[PROFILEPATH]", @UserProfileDir)
    $WorkingDir = $aArray[3][1]
    $Desc = $aArray[4][1]
    consolewrite('$ProgramEXEFullPath  = ' & $ProgramEXEFullPath & @CRLF  & _
                 '$LNKPath             = ' & $LNKPath & @CRLF & _
                 '$WorkingDir          = ' & $WorkingDir & @CRLF & _
                 '$Desc          = ' & $Desc & @CRLF )
else
    msgbox(0,"Ahh Snap!", "Cannot read shortcuts.ini file, possible format incorrect or file currupted.")
endif

kylomas

edit: Incidentally, I changed "shorcuts" to shortcuts".

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...