jdillig Posted February 24, 2015 Share Posted February 24, 2015 Gentlemen, Hopefully you can help me out here. I have been beating my head against a wall for about a week trying to figure this one out before writing this. I have a simple setup where i am storing information inside a .ini file and using the IniRead() function to pull this information. I have done this in the past and not had an issue until now. The $Lab_LDConfig_Descript variable always will equal the "0" default value and i cannot figure out why. I can take the full path (from the root) and past into CMD and it will find and open the .ini so I do not believe it is an issue with the path. I have also tried UTF and ANSI encoding on the file and this did not change anything. Hopefully this is something stupid and simple but I cannot find it! Here is the basic code: $Lab_LDConfig_Descript = IniRead(@ScriptDir&"\labs\R77.20 Standalone\LDConfig.ini","Lab Description","Description",0) if $Lab_LDConfig_Descript = 0 Then MsgBox(0,"Error!","Iniread returned 0!") Else MsgBox(0,"Success!","Iniread returned "&$Lab_LDConfig_Descript) EndIf The LDConfig.ini file contains the following: [Lab Description] Description=This is a lab [OVF Instructions] OVFDeploy=instructions here Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2015 Moderators Share Posted February 24, 2015 jdillig,Welcome to the AutoIt forums. IniRead returns a string - you are comparing it to a number. Change the line to read:if $Lab_LDConfig_Descript = "0" Thenand all will be well. Basically mixing numbers and strings in comparisons is a good recipe for tears at bedtime. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jdillig Posted February 24, 2015 Author Share Posted February 24, 2015 jdillig, Welcome to the AutoIt forums. IniRead returns a string - you are comparing it to a number. Change the line to read: if $Lab_LDConfig_Descript = "0" Then and all will be well. Basically mixing numbers and strings in comparisons is a good recipe for tears at bedtime. M23 Melba23, Thanks for the response. I tried this and found no difference. I am expecting the $Lab_LDConfig_Descript variable to contain the string, "This is a lab" as read from the LDConfig.ini file. When I output what $Lab_LDConfig_Descript contains into a msgbox, I still get "0". Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2015 Moderators Share Posted February 24, 2015 jdillig,Well, it works for me because I created the ini file and path as you showed in the OP and ran the code before posting. To explain why I suggested what I did: you were using a comparison with mixed datatypes - in this case AutoIt does an internal conversion so they are the same type, usually to numeric values. Thus the string "This is a lab" is converted to 0 - as it is not a number - and this matched the numeric 0 on the other side. Converting both sides to strings (by adding quotes around the "0") made the comparison valid and the correct MsgBox appeared with the correct value. Now if you say that IniRead is actually not reading the ini value at all then I can only suggest that the file is somehow not accessible. Try adding a FileExists with the same path just before reading and see what is returned. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DarkwarlorD Posted February 24, 2015 Share Posted February 24, 2015 Good evening. I Tried your script with a few modifications ... take a look: $Lab_LDConfig_Descript = IniRead(@ScriptDir & "\LDConfig.ini", "Lab Description", "Description", "ERROR") if $Lab_LDConfig_Descript = "ERROR" Then MsgBox(0, "Error!", "Iniread returned ERROR!") Else MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) EndIf For me worked fine, but I changed both the path and the default value returned by IniRead. Try change or verifying the path of ini file Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 24, 2015 Moderators Share Posted February 24, 2015 Out of curiosity, what is the size of the ini file? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jdillig Posted February 24, 2015 Author Share Posted February 24, 2015 (edited) jdillig, Well, it works for me because I created the ini file and path as you showed in the OP and ran the code before posting. To explain why I suggested what I did: you were using a comparison with mixed datatypes - in this case AutoIt does an internal conversion so they are the same type, usually to numeric values. Thus the string "This is a lab" is converted to 0 - as it is not a number - and this matched the numeric 0 on the other side. Converting both sides to strings (by adding quotes around the "0") made the comparison valid and the correct MsgBox appeared with the correct value. Now if you say that IniRead is actually not reading the ini value at all then I can only suggest that the file is somehow not accessible. Try adding a FileExists with the same path just before reading and see what is returned. M23 I added a fileexist() check and it found it ok. Below is the code I used. Good evening. I Tried your script with a few modifications ... take a look: $Lab_LDConfig_Descript = IniRead(@ScriptDir & "\LDConfig.ini", "Lab Description", "Description", "ERROR") if $Lab_LDConfig_Descript = "ERROR" Then MsgBox(0, "Error!", "Iniread returned ERROR!") Else MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) EndIf For me worked fine, but I changed both the path and the default value returned by IniRead. Try change or verifying the path of ini file I tested your method and it did work when the .ini file was in the same directory as the script. Does anyone know if the IniRead() function relies on a .ini file path that does not contain any spaces? Out of curiosity, what is the size of the ini file? The test .ini is only 4 lines (97 bytes) and the full .ini is around 20-30 lines (496 bytes) This is the code I used to test with the suggestions so far. It still does not work when the .ini file is not in the same directory as the script. if FileExists(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini") then MsgBox(0,"","It is there") $Lab_LDConfig_Descript = IniRead(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini", "Lab Description", "Description", "ERROR") if $Lab_LDConfig_Descript = "ERROR" Then MsgBox(0, "Error!", "Iniread returned ERROR!") Else MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) EndIf Edited February 24, 2015 by jdillig Link to comment Share on other sites More sharing options...
JohnOne Posted February 24, 2015 Share Posted February 24, 2015 (edited) Try renaming that folder "R77.20 Standalone" removing the . and see if it works. Edited February 24, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jdillig Posted February 24, 2015 Author Share Posted February 24, 2015 Try renaming that folder "R77.20 Standalone" removing the . and see if it works. Same issue. FileExists() finds the file but IniRead() does not. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2015 Moderators Share Posted February 24, 2015 (edited) jdillig, Does anyone know if the IniRead() function relies on a .ini file path that does not contain any spaces?There is no problem with IniRead and spaces - I created the same folder structure as in your example and it worked without problem. Let us try another test. Try using this and see what you get:; Add this at the top of your script #include <Array.au3> ; Then we try to read all section names in the ini file $aSections = IniReadSectionNames(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini") _ArrayDisplay($aSections) ; And then the specific section in which we are interested $aSection = IniReadSection(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini", "Lab Description") _ArrayDisplay($aSection)Needless to say that works for me - any luck at your end? M23Edit:And I have lifted your "New Member" first day post limit - I think we might need a while to get to the bottom of this! Edited February 24, 2015 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Trong Posted February 24, 2015 Share Posted February 24, 2015 (edited) Gentlemen, The LDConfig.ini file contains the following: [Lab Description] Description=This is a lab [OVF Instructions] OVFDeploy=instructions here Global $sFileINI=@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini"; @ScriptDir & "\LDConfig.ini" If Not FileExists($sFileINI) Then MsgBox(0,"Error!","INI File Not Found!"& @CRLF &$sFileINI) Else Local $Lab_LDConfig_Descript = IniRead($sFileINI, "Lab Description", "Description", "Error") If ($Lab_LDConfig_Descript<>"Error") Then MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) Else MsgBox(0, "Error!", "Iniread returned ERROR!") EndIf EndIf Edited February 24, 2015 by Trong Regards, Link to comment Share on other sites More sharing options...
jdillig Posted February 24, 2015 Author Share Posted February 24, 2015 jdillig, There is no problem with IniRead and spaces - I created the same folder structure as in your example and it worked without problem. Let us try another test. Try using this and see what you get: ; Add this at the top of your script #include <Array.au3> ; Then we try to read all section names in the ini file $aSections = IniReadSectionNames(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini") _ArrayDisplay($aSections) ; And then the specific section in which we are interested $aSection = IniReadSection(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini", "Lab Description") _ArrayDisplay($aSection) Needless to say that works for me - any luck at your end? M23 Edit: And I have lifted your "New Member" first day post limit - I think we might need a while to get to the bottom of this! So this is interesting, the _arraydisplay() only shows 1 of the 2 sections inside the .ini. The one shown however is not the one I called from IniRead(), it finds the "OVF Instructions" only. _arraydisplay() Row|Col 0 [0]|1 [1]|OVF Instructions I don't think that the .ini format is incorrect... Maybe it is? Link to comment Share on other sites More sharing options...
jdillig Posted February 24, 2015 Author Share Posted February 24, 2015 Global $sFileINI=@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini"; @ScriptDir & "\LDConfig.ini" If Not FileExists($sFileINI) Then MsgBox(0,"Error!","INI File Not Found!"& @CRLF &$sFileINI) Local $Lab_LDConfig_Descript = IniRead($sFileINI, "Lab Description", "Description", "Error") If ($Lab_LDConfig_Descript<>"Error") Then MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) Else MsgBox(0, "Error!", "Iniread returned ERROR!") EndIf Trong, Same issue, no change Link to comment Share on other sites More sharing options...
Trong Posted February 24, 2015 Share Posted February 24, 2015 Trong, Same issue, no change Global $sFileINI=@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini"; <<<<<<<<<<<<<<<<<<<<<<<< If Not FileExists($sFileINI) Then MsgBox(0,"Error!","INI File Not Found!"& @CRLF &$sFileINI) Else Local $Lab_LDConfig_Descript = IniRead($sFileINI, "Lab Description", "Description", "Error") Local $LOVF_Instructions_OVFDeploy = IniRead($sFileINI, "OVF Instructions", "OVFDeploy", "Error") If ($Lab_LDConfig_Descript<>"Error") Then MsgBox(0, "Success!", "Lab LDConfig Descript: " & $Lab_LDConfig_Descript& @CRLF & "LOVF Instructions OVFDeploy: " & $LOVF_Instructions_OVFDeploy) Else MsgBox(0, "Error!", "Iniread returned ERROR!") EndIf EndIf Regards, Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2015 Moderators Share Posted February 24, 2015 jdillig,We progress! The problem is obviously in the ini file itself. I just copy-pasted what you had in the OP into my file - I suggest you do the same and see if you can read it then. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted February 24, 2015 Share Posted February 24, 2015 (edited) I have a feeling this thread is going to go another 5 pages then... oops sorry, I thought I was using AutoIt but I was actually painting my dog. Solved. EDIT: Or not Edited February 24, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kylomas Posted February 24, 2015 Share Posted February 24, 2015 (edited) This works... $Lab_LDConfig_Descript = IniRead(@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini", "Lab Description", "Description", 0) ConsoleWrite($Lab_LDConfig_Descript & @CRLF) If $Lab_LDConfig_Descript = "0" Then MsgBox(0, "Error!", "Iniread returned 0!") Else MsgBox(0, "Success!", "Iniread returned " & $Lab_LDConfig_Descript) EndIf The comparison to a numeric 0 was wrong... Return Value Success: the requested key value as a string. Failure: the default string if requested key not found. Edited February 24, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
TheSaint Posted February 24, 2015 Share Posted February 24, 2015 If the last solution provided by Melb23 does not do the job (I'm imagining you may have a bracket error or something like that), then can you open your INI file in Notepad and then take a screenshot and upload here for us to check. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
kylomas Posted February 24, 2015 Share Posted February 24, 2015 Dude, the OP was comparing the "string" returned from the iniread to a numeric 0...see post above... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
TheSaint Posted February 24, 2015 Share Posted February 24, 2015 (edited) We worked that out at Post #2. All the examples since have been working for everyone else, but not OP. Hence why we think something is wrong inside his INI file, and it is not exactly as shown. Edited February 24, 2015 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) 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