Jump to content
Sign in to follow this  
digitalexpl0it

INI File Loop option

Recommended Posts

digitalexpl0it

Hello All I am new to the forums.

I have searched the web and the forums for my issue in my code. I am trying to read an option in an ini file with a number variable like 5, this number can be changed at any time. I then read the ini and make a for loop to read the entries in the ini file. The option 5 variable is there to let the loop know how many times to loop and read the INI file for the optional values.

Main Code

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

; INI File - Settings File
Local Const $sFilePath = "settings.ini"
Local $iFileExists = FileExists($sFilePath)

If not $iFileExists Then
    msgbox(0,"Oh NO!", "settings.ini not found!")
endif

; Read the INI section labelled 'OtherTransfers'. This will return a 2 dimensional array.
Local $aArray = IniReadSection($sFilePath, "OtherTransfers")
Local $opArray = IniReadSection($sFilePath, "Options")

If Not @error Then
    ; Enumerate through the array displaying the keys and their respective values.
    Local $howMany = $opArray[1][1]
    for $i = 1 to $howMany -1
        msgbox(0,"test",$aArray[$i][1])
    next
EndIf

here is the ini file

[Options]
OT_HowMany=5
[OtherTransfers]
OT_Source_1=c:\test1
OT_Destination_1=\\test1
OT_Source_2=c:\test2
OT_Destination_2=\\test2
OT_Source_3=c:\test3
OT_Destination_3=\\test3
OT_Source_4=c:\test4
OT_Destination_4=\\test4
OT_Source_5=c:\test5
OT_Destination_5=\\test5

now the [Options] section will change depending on how many OT_HowMany is specified. Now when I run the script without a msgBox I get a count of 5 msgboxes, but once I add the ini array in, I only get the first 4 from the ini file in the Options Section. 

Any Help would be appreciated. 

Share this post


Link to post
Share on other sites
Spider001

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
; INI File - Settings File
Local Const $sFilePath = "settings.ini"
Local $iFileExists = FileExists($sFilePath)
If not $iFileExists Then
   msgbox(0,"Oh NO!", "settings.ini not found!")
endif
; Read the INI section labelled 'OtherTransfers'. This will return a 2 dimensional array.
Local $aArray = IniReadSection($sFilePath, "OtherTransfers")
;Local $opArray = IniReadSection($sFilePath, "Options")
If Not @error Then
   ; Enumerate through the array displaying the keys and their respective values.
   ;Local $howMany = $opArray[1][1]
   ;_ArrayDisplay($aArray)
   for $i = 1 to $aArray[0][0]
      msgbox(0,"test",$aArray[$i][1])
   next
EndIf

Edited by Spider001

Share this post


Link to post
Share on other sites
digitalexpl0it

thanks that works, I guess I didnt need to specify the numbers of loops

Share this post


Link to post
Share on other sites
Spider001

no you don't need that the number is on they array already

_ArrayDisplay($aArray) = a verry good function
Edited by Spider001

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  

×