Moderators Melba23 Posted February 24, 2015 Moderators Share Posted February 24, 2015 kylomas,the OP was comparing the "string" returned from the iniread to a numeric 0I pointed that out in post #2 of the thread. 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...
kylomas Posted February 24, 2015 Share Posted February 24, 2015 M23, Yea, I saw that. Somehow the whole thing got sideways... 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...
jdillig Posted February 24, 2015 Author 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. I tested using AutoIT to actually write the .ini file and so far it seems to be working. Is there some special formatting that the IniWrite() function uses to write the .ini? This is the exact contents of the new file that was written using the iniwrite() function. The formatting is the same as before for the Section and Key names. [OVF Instructions] OVFDeploy=MyOVF Script [Lab Description] Description=mydescripthere I do appreciate the help from you guys on this! I still don't understand why this didn't work before, if anyone wants to take a crack at explaining why, I would love to understand the root issue. Link to comment Share on other sites More sharing options...
Trong Posted February 25, 2015 Share Posted February 25, 2015 (edited) I think I'm an idiot, but it worked! ;@ScriptDir Global $sFileINI=@ScriptDir & "\labs\R77.20 Standalone\LDConfig.ini"; ;IniWrite If Not IniWriteData() Then MsgBox(0,"IniWrite Error!","INI File Not Found: "&$sFileINI) ;IniRead If Not FileExists($sFileINI) Then MsgBox(0,"Error!","INI File Not Found: "&$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 Func IniWriteData() If Not FileExists($sFileINI) Then FileOpen($sFileINI,1+8) IniWrite($sFileINI, "Lab Description", "Description", "Value Description" ) IniWrite($sFileINI, "OVF Instructions", "OVFDeploy", "Value OVFDeploy" ) ;~ Return FileExists($sFileINI) Return ((IniRead($sFileINI, "Lab Description", "Description", "Error")<>"Error") And (IniRead($sFileINI, "OVF Instructions", "OVFDeploy", "Error")<>"Error")) EndFuncI will not spam this thread again! Edited February 25, 2015 by Melba23 Large image deleted Regards, Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25, 2015 Moderators Share Posted February 25, 2015 Your code is going to bleed memory, you never close the FileOpen call. Func IniWriteData() If Not FileExists($sFileINI) Then FileClose(FileOpen($sFileINI,2+8)); 2 creates a new file, not 1 IniWrite($sFileINI, "Lab Description", "Description", "Value Description" ) IniWrite($sFileINI, "OVF Instructions", "OVFDeploy", "Value OVFDeploy" ) ;~ Return FileExists($sFileINI) Return ((IniRead($sFileINI, "Lab Description", "Description", "Error")<>"Error") And (IniRead($sFileINI, "OVF Instructions", "OVFDeploy", "Error")<>"Error")) EndFunc . Trong 1 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...
orbs Posted February 25, 2015 Share Posted February 25, 2015 i once encountered an incident where the ini file was generated by a Unix system - in some bizarre format - and Windows API of the ini* function was unable to parse. i dug a bit and found the file - it is attached. extract it, open it in Notepad and see for yourself, then open it in NotePad++ to see how it really is: White_to_Include_bad.zip (Note: it is zipped because when i tried to upload it as is to the forum, it says i'm not allowed to upload this kind of file. it is safe, though.) luckily, at the time i was developing my >LFN UDF, with its own set of functions to handle ini files without relying on the Windows API. i just applied it, and it worked right-off. here is an adapted version of the LFN function to read a value from ini file. test it on your original file (if you still have a copy of it): Func _IniRead($sFile, $sSection, $sKey, $xDefaultValue) ; adapated from the LFN UDF If Not FileExists($sFile) Then Return $xDefaultValue Local $aFileLines = FileReadToArray($sFile) If @error Then Return $xDefaultValue Local $bSectionFound = False Local $iPos = 0 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True Else If $bSectionFound Then ; entering next section, key not found Return $xDefaultValue ExitLoop EndIf EndIf Else If $bSectionFound Then $iPos = StringInStr($aFileLines[$i], '=') If $iPos = 0 Then ContinueLoop If StringLeft($aFileLines[$i], $iPos - 1) = $sKey Then Return StringTrimLeft($aFileLines[$i], $iPos) EndIf EndIf Next Return $xDefaultValue EndFunc ;==>_IniRead Trong 1 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...
TheSaint Posted February 25, 2015 Share Posted February 25, 2015 (edited) @jdillig - It is AutoIt, not AutoIT .... no Eye Tee at the end. Auto as in automating it. @orbs - I'm not sure that was the scenario, as melba23's array read example did return the second element, just not the first. As we have not seen a screenshot of the original, and have to go by the claim it was not a Unicode issue, then I'm leaning toward an error in the INI file (incorrect bracket, carriage return, etc). Or the OP did not fully follow the examples posted ... due to a misunderstanding etc? Edited February 25, 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