Jump to content

need help with some logic


Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

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