Jump to content

IniRead() Not Finding Values


jdillig
 Share

Recommended Posts

  • Moderators

kylomas,

the OP was comparing the "string" returned from the iniread to a numeric 0

I pointed that out in post #2 of the thread. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

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"))
EndFunc

I will not spam this thread again!

Edited by Melba23
Large image deleted

Regards,
 

Link to comment
Share on other sites

  • Moderators

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

.

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

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
 

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

@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 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)

userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...