Maikey81 Posted November 8, 2013 Share Posted November 8, 2013 Hi, I may be overlooking something real simple, but I can't seem to figure it out. I'm trying the simplest of examples from the autoit site, IniSectionReadNames en combining this with IniRead. Below is the code: Local $var = IniReadSectionNames("c:\servers.ini") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0] $ip = IniRead($var, $var[$i], "IP", "unknown") MsgBox(4096, "", $var[$i] & " has IP-address: " & $ip) Next EndIf When executing this file, it does read the section names without any problems but it won't return the value of the IP key. It always returns the default value. Below is the contents of the ini file: [Server1] IP=address [Server2] IP=test Any ideas whats going on? Link to comment Share on other sites More sharing options...
Solution ripdad Posted November 8, 2013 Solution Share Posted November 8, 2013 Local $ip, $sFile = "c:\servers.ini" Local $aSection = IniReadSectionNames($sFile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $aSection[0] $ip = IniRead($sFile, $aSection[$i], "IP", "unknown") MsgBox(4096, "", $aSection[$i] & " has IP-address: " & $ip) Next EndIf "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Maikey81 Posted November 8, 2013 Author Share Posted November 8, 2013 Local $ip, $sFile = "c:\servers.ini" Local $aSection = IniReadSectionNames($sFile) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $aSection[0] $ip = IniRead($sFile, $aSection[$i], "IP", "unknown") MsgBox(4096, "", $aSection[$i] & " has IP-address: " & $ip) Next EndIf Thanks ripdad! But I don't seem to understand what the big difference is between your and my code. The only difference i see, is that you declare the ini file in a separate variable before reading the ini file. Link to comment Share on other sites More sharing options...
water Posted November 8, 2013 Share Posted November 8, 2013 The problem is with the first parameter you specified for IniRead. It has to be the file to be read. You specified the array of section names as returned by InIReadSectionNames. IniRead($var, ...) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
orbs Posted November 8, 2013 Share Posted November 8, 2013 @Maikey81, pay close attention to your IniRead() first parameter. also make yourself a habit to name your variables with meaningful names, it is very helpful in long scripts. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
ripdad Posted November 8, 2013 Share Posted November 8, 2013 The main difference is in the parameters. Your code: $ip = IniRead($var, $var[$i], "IP", "unknown") In parameter #1, $var is the entire array -- and not a string path to your ini. Arrays and strings don't mix well in this instance, unless you specifically call an element, like you did in parameter #2. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
Maikey81 Posted November 8, 2013 Author Share Posted November 8, 2013 Ah... now that I see all your replies, it becomes clear. Thank you all for your replies. It's all clear to me now Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now