Sign in to follow this  
Followers 0
Hypertrophy

need help with some logic

5 posts in this topic

Here's what my ini looks like

key1=joe
key2=bob,will
key3=sam,whatever
key4=doodoo

how do i go through this ini and locate ONLY the values that have commas in them (meaning the values that are arrays) and doing somehing, while disregarding all the other values that do no fit the above criteria. im lost.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello.

Maybe something like this:

$aSection = IniReadSection("C:\PathTo\MyFile.ini", "MySection")
For $i = 1 To $aSection[0][0]
    If StringInStr($aSection[$i][1], ",") Then
        MsgBox(4096, "", "Array value found! Text: " & $aSection[$i][1])
    EndIf
Next

If you want to go through ALL sections of your INI, put the code above into another loop:

$aSectionNames = IniReadSectionNames("C:\PathTo\MyFile.ini")
For $x = 1 To $aSectionNames[0]
    $aSection = IniReadSection("C:\PathTo\MyFile.ini", $aSectionNames[$x])
    For $y = 1 To $aSection[0][0]
        If StringInStr($aSection[$y][1], ",") Then
            MsgBox(4096, "", "Array value found! Text: " & $aSection[$y][1])
        EndIf
    Next
Next
Edited by Crystall

Hello World!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi. Thank you this looks very good. Another question, what if I wanted to handle the values that weren't arrays? How would I structure the loop then? For example code below only handles the values in the section that are arrays. What if I also have individual values like in my first post. How would I go about handling them?

$aSection = IniReadSection("C:\PathTo\MyFile.ini", "MySection")
For $i = 1 To $aSection[0][0]     
     If StringInStr($aSection[$i][1], ",") Then
         MsgBox(4096, "", "Array value found! Text: " & $aSection[$i][1])
     EndIf 
Next
Edited by Hypertrophy

Share this post


Link to post
Share on other sites

I think you could just add an else statement to capture those.

$aSection = IniReadSection("C:\PathTo\MyFile.ini", "MySection")
For $i = 1 To $aSection[0][0]     
     If StringInStr($aSection[$i][1], ",") Then
         MsgBox(4096, "", "Array value found! Text: " & $aSection[$i][1])
     else
         MsgBox(4096, "", "Non-Array value found! Text: " & $aSection[$i][1])
     EndIf 
Next

Share this post


Link to post
Share on other sites

Thanks! Will try this later.

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