Jump to content

Recommended Posts

Hi, i would like to know if there is a possible way to use subsections for ini files?

For example, my ini file would look something like this:

 

Clientname.ini

[Info]

Country=USA

Type=Distributor

 

[Costs]

[[JAN]] <----- subsection

cost1=----

cost2=----

[[FEB]]

cost1=----

cost2=----

 

[Sales]

[[JAN]] <----- subsection

sale1=----

sale2=----

[[FEB]]

sale1=----

sale2=----

 

[Profits]

[[JAN]] <----- subsection

prof1=----

prof2=----

[[FEB]]

prof1=----

prof2=----

 

The sales would be inputed everyday by the script, and then whenever viewed, i would be using an array to view every sale/cost/profit under the subsection

 

 

Thanks for your time!

Share this post


Link to post
Share on other sites

In short no, however to get around this I would use something like below:

You can then use a function to create different reports based upon month or costs, profits, sales or both, simple example below:

#include <Array.au3>
#include <String.au3>

$aReportSection = _Report("", "JAN")
_ArrayDisplay($aReportSection)

$aReportSection = _Report("Costs", "FEB")
_ArrayDisplay($aReportSection)

$aReportSection = _Report("Profits", "")
_ArrayDisplay($aReportSection)


Func _Report($_sReport = "", $_sMonth = "")
    Local $sClient = @ScriptDir & "\Client.ini"
    Local $aSections = IniReadSectionNames($sClient)
        If @error Then Exit
    Local $aReportMonth, $aSection, $aResults[1][2]
    For $i = $aSections[0] To 1 Step - 1
        If $_sReport = "" And $_sMonth = "" Then
            _ArrayDelete($aSections, _ArraySearch($aSections, "Info"))
            ExitLoop
        EndIf
        $aReportMonth = StringSplit($aSections[$i], ":")
        ;~ Doesn't include seperator ":", so delete section name from array and continueloop
        If $aReportMonth[0] <= 1 Then
            _ArrayDelete($aSections, $i)
            ContinueLoop
        EndIf
        If $_sReport = "" Then
            If $_sMonth = $aReportMonth[2] Then ContinueLoop
            _ArrayDelete($aSections, $i)
        ElseIf $_sReport <> $aReportMonth[1] Then
            _ArrayDelete($aSections, $i)
        ElseIf $_sMonth = "" Then
            If $_sReport = $aReportMonth[1] Then ContinueLoop
            _ArrayDelete($aSections, $i)
        ElseIf $_sMonth <> $aReportMonth[2] Then
            _ArrayDelete($aSections, $i)
        EndIf
    Next
    $aSections[0] = UBound($aSections) - 1
    For $i = 1 To $aSections[0]
        $aSection = IniReadSection($sClient, $aSections[$i])
        $aReportMonth = StringSplit($aSections[$i], ":")
        For $j = 1 To $aSection[0][0]
            $aSection[$j][0] = _StringProper($aReportMonth[2]) & " - " & $aSection[$j][0]
        Next
        _ArrayConcatenate($aResults, $aSection, 1)
    Next
    $aResults[0][0] = $_sReport = "" ? "All Reports" : $_sReport & " Report"
    $aResults[0][1] = $_sMonth = "" ? "" : _Month($_sMonth)
    Return $aResults
EndFunc

Func _Month($_sMonth)
    Switch $_sMonth
        Case "JAN"
            Return "January"
        Case "FEB"
            Return "February"
        Case "MAR"
            Return "March"
        Case "APR"
            Return "April"
        Case "MAY"
            Return "May"
        Case "JUN"
            Return "June"
        Case "JUL"
            Return "July"
        Case "AUG"
            Return "August"
        Case "SEP"
            Return "September"
        Case "OCT"
            Return "October"
        Case "NOV"
            Return "November"
        Case "DEC"
            Return "December"
        Case Else
            Return ""
    EndSwitch
EndFunc
[Info]
Country=USA
Type=Distributor

[Costs:JAN]
cost1=----
cost2=----

[Costs:FEB]
cost1=----
cost2=----

[Sales:JAN]
sale1=----
sale2=----

[Sales:FEB]
sale1=----
sale2=----

[Profits:JAN]
prof1=----
prof2=----

[Profits:FEB]
prof1=----
prof2=----

 

Share this post


Link to post
Share on other sites

You can also have logic in your script that looks for a section by reading in a key's value.  where the value matches the sections name.  (just as another way to skin the cat)

 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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

  • Similar Content

    • By nacerbaaziz
      good morning sirs.
      please i have a request from you.
      i have an variable to Read a data from a file
      this data is Encrypted
      and when i read it i Decrypte it.
      for that i need a function to Write a ini data to string.
      ;#Function# ===================================================================================================================== ; Name............: _IniReadFromString ; Description.....: Returns the value of a key in a specific section of an ini-formatted string ; Syntax..........: _IniReadFromString($szInput, $szSection, $szKey, $Default) ; Parameters......: ;   $szInput - The string that contains data in ini format ;   $szSection   - The sectionname (just as in IniRead) ;   $szKey   - The keyname (just as in IniRead) ;   $Default - The default value if the key does not exist or reading failed (just as in IniRead) ; Return values ..: ;   Success  - Returns the read value ;   Failure  - Returns $Default ; Author .........: FichteFoll ; Remarks ........: Works for Unicode as well as for ANSI ; Related ........: IniRead, _IniReadSectionFromString ; Link ...........; See on top ; Example ........; $var = _IniReadFromString(StringFormat("[Sect]\r\nMyKey1=value1\r\nMyKey2=value2"), "Sect", "MyKey2", "no_value") ; =============================================================================================================================== Func _IniReadFromString($szInput, $szSection, $szKey, $Default) $szInput = StringStripCR($szInput) ;~  Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?(",3) Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?", 3) If @error Then Return SetError(1, 0, $Default) ; key not found    Return $aRegMl[0] EndFunc;==>_IniReadFromString ; ############################################################################################################################### ; =============================================== ; = Internal Use Only ; =============================================== Func __StringEscapeRegExp($szExp) Return StringRegExpReplace($szExp, "([\(\)\[\]\{\}\\\/\?\.\\|\+])", "\\$1") ; ()[]{}\/?.|+ EndFunc;==>__StringEscapeRegExp like this  function Read the ini from string.
       
       
      please ihelp me
      thanks in advance
    • By nacerbaaziz
      hello sirs,
      i have searched allot about an function that can  read the INI file as a  string
      i mean function to read the ini files from string and not from the file directly.
      i finally found an UDF that do what i want
      but unfortunately all the functions work,  but the function that i want it not working.
      this is the udf
      the function that  i need is _IniReadFromString
      this is the function

      Func _IniReadFromString($szInput, $szSection, $szKey, $Default) $szInput = StringStripCR($szInput) Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?(", 3) If @error Then Return SetError(1, 0, $Default) ; key not found Return $aRegMl[0] EndFunc;==>_IniReadFromString
      i hope that any one can help me
      thank you in advance
      iniex.au3
    • By nacerbaaziz
      hi dears
      am using an ini files as a History
      Sometimes the file size is be larger to 5 MB
      AutoIt does not recognize the full content of the file
      When I did a search to find out why, I discovered that INI files could not be read if they size larger than 64 KB.
      for that I preferred to ask here if is there any way to bypass this obstacle.
      The contents of the file are  as follows
      [filesList]
      c:\...\...\f1.mp3=00:15:20
      c:\...\...\f2.mp3=00:10:20
      c:\...\...\f3.wav=00:59:20
      ....... Etc
      This is the section for reading the file (adapted from my main script)

      case $continue     Local $aArray = IniReadSection($WaitingListFile, StringEncrypt(true, "filesList", $MyPassword))     If Not @error Then Opt("GUICloseOnESC", 1) _GUICtrlListView_DeleteAllItems($scList)         For $i = 1 To $aArray[0][0] $path = path_list(StringEncrypt(false, $aArray[$i][0], $MyPassWord), 1) if FileExists(StringEncrypt(false, $aArray[$i][0], $MyPassWord)) then GUICtrlCreateListViewItem(_GetFileName(FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord))) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord)), $scList) else $path = $path endIf         Next GUISetState(@sw_disable, $hGUI) GUISetState(@sw_show, $hGUI2) GUICtrlSetState($SClist, $GUI_FOCUS) else if $accessibilitymode = 1 then speak(str("listEmpty")) endIf endIf
      Is there any way to solve this problem, please?
      am waiting your answers...
      Greetings to All
    • By AndreasNWWWWW
      Hi, i'm just curious is there a way to sort an ini file after largest first?
      my inifiles writes itself like this
      14=500
      13=GREY
      12=500
      11=600
      10=600
      9=600
      8=700
      7=700
      5=600
      3=600
      2=800
      1=700
      15=GREY
      4=GREY
       
      but is there a way so i can get it sortet 
      15
      14
      13
      12 
      etc?
    • By AndreasNWWWWW
      Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.
      for my test i'm looking for 100,200,300,400,500
      and if any of those excits i want to pop a msgbox with the number in the section.
      i can in my example find one, but it does not check everyone. why?  what am i missing?
      Local $iscore810[5] = [100,200,300,400,500] Local $iMax800 = 5 While 1 ;~     Send("{pause}") ;;func les ini fil     $var = IniReadSection("Area.ini", "modus")     If @error Then         MsgBox(4096, "Error", "Unable to read section.")     Else          For $number = 1 To $var[0][0] If $var[$number][1] == $iscore810[3] Then       MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5) EndIf                       Next     EndIf     exit WEnd  
×
×
  • Create New...