;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) strFileTemp = FileCreateTemp ("WB") If strListKeys != "" arrFilter = Arrayize (strListKeys, strListDelim) ArraySort (arrFilter) ; For sure. EndIf If strSection == "" arrSections = Arrayize (IniItemizePvt ("", strFilename), @TAB) Else arrSections = Arrayize (strSection, @TAB) EndIf intSectionsLast = ArrInfo (arrSections, 1) - 1 For intSection = 0 To intSectionsLast arrSection = Arrayize (IniItemizePvt (arrSections[intSection], strFilename), @TAB) ArrayRedim (arrSection, -1, 1) ArrayInsert (arrSection, 1, 2, "") ArrayInsert (arrSection, 0, 2, "") intKeyLast = ArrInfo (arrSection, 1) - 1 If strListKeys == "" For intKey = 0 To intKeyLast arrSection[intKey, 0] = arrSections[intSection] arrSection[intKey, 2] = IniReadPvt (arrSections[intSection], arrSection[intKey, 1], "", strFilename) Next Else For intKey = intKeyLast To 0 By -1 If ArraySearch (arrFilter, arrSection[intKey, 1], 2) == -1 ArrayRemove (arrSection, intKey, 1) Else arrSection[intKey, 0] = arrSections[intSection] arrSection[intKey, 2] = IniReadPvt (arrSections[intSection], arrSection[intKey, 1], "", strFilename) EndIf Next EndIf If ArrInfo (arrSection, 1) > 0 Then ArrayFilePutCSV (strFileTemp : "." : intSection, arrSection) Next blnResult = FileAppend (strFileTemp : ".*", strFileTemp) arrIni = ArrayFileGet (strFileTemp, 0) If ArrInfo (arrIni, 1) > 0 ArraySort (arrIni) ; For sure. ArrayFilePut (strFileTemp, arrIni) arrIni = ArrayFileGetCSV (strFileTemp, 0) EndIf blnResult = FileDelete (strFileTemp) blnResult = FileDelete (strFileTemp : ".*") Return arrIni ;.......................................................................................................................................... ; This UDF "udfArrayFromIniFile" creates a dim-2 array with three columns from the content of an ini file. ; ; Parameters: ; ; strFilename ... The filename of the ini file. ; ; strSection ... The section from the ini file to be loaded into the array. ; If an empty string is given as the section name, ; then all sections contained within the ini file will be stored into the array. ; ; strListKeys ... If this list contains key names (case insensitiv), ; then the returning array contains only those keys which are given in this list . ; ; strDelim ... The delimiter character to act as a delimiter between items in the list. ; ; Note: This UDF creates temporary files and removes them afterwards. ; ; Example: ; ; From ini file ... To dim-2 array ... ; ; [COLORS] +----+----------+-------+-----------+ ; CON=128,0,128 | | c0 | c1 | c2 | ; EXT=255,0,255 +----+----------+-------+-----------+ ; | r0 | COLORS | CON | 128,0,128 | ; [KEYWORDS] | r1 | COLORS | EXT | 255,0,255 | ; About=1 | r2 | KEYWORDS | About | 1 | ; Abs=1 | r3 | KEYWORDS | Abs | 1 | ; Acos=1 | r4 | KEYWORDS | Acos | 1 | ; +----+----------+-------+-----------+ ; ;.......................................................................................................................................... ; (c)Detlev Dalitz.20110404. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. strFileTest = FileCreateTemp ("WB") :Test1 ; Return all entries from the given section. strFilename = DirHome () : "WIL.CLR" strSection = "COLORS" strListKeys = "" strListDelim = "" arrIni = udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) ArrayFilePutCSV (strFileTest, arrIni) RunWait ("notepad.exe", strFileTest) :Test2 ; Return all entries from the given section, which match the given keys. strFilename = DirHome () : "WIL.CLR" strSection = "COLORS" strListKeys = "UDF,CON" strListDelim = "," arrIni = udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) ArrayFilePutCSV (strFileTest, arrIni) RunWait ("notepad.exe", strFileTest) :Test3 ; Return all entries from all sections. strFilename = DirHome () : "WIL.CLR" strSection = "" strListKeys = "" strListDelim = "" arrIni = udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) ArrayFilePutCSV (strFileTest, arrIni) RunWait ("notepad.exe", strFileTest) :Test4 ; Return all entries from all sections, which match the given keys. strFilename = DirHome () : "WIL.CLR" strSection = "" strListKeys = "UDF,CON" strListDelim = "," arrIni = udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) ArrayFilePutCSV (strFileTest, arrIni) RunWait ("notepad.exe", strFileTest) :Test5 ; This will give an empty array. strFilename = DirHome () : "WIL.CLR" strSection = "COLORS" strListKeys = "UDF,CON" strListDelim = "" arrIni = udfArrayFromIniFile (strFilename, strSection, strListKeys, strListDelim) ArrayFilePutCSV (strFileTest, arrIni) RunWait ("notepad.exe", strFileTest) :CANCEL FileDelete (strFileTest) Exit