Jump to content

Recommended Posts

  • Moderators
Posted

kylomas,

  Quote

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:

  Reveal hidden contents

 

Posted
  On 2/24/2015 at 8:17 PM, TheSaint said:

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.

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

I will not spam this thread again!

Edited by Melba23
Large image deleted

Regards,
 

  • Moderators
Posted

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.

Posted

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:

  Reveal hidden contents

 

Posted (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 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.

  Reveal hidden contents

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

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
  • Recently Browsing   0 members

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