Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] IniRead with condition

15 posts in this topic

#1 ·  Posted (edited)

Hi guys, i have some problem with IniRead.

This is the script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $ini = @WorkingDir & "\language.ini"

If FileExists(@WorkingDir & "\language.ini") Then
GUI()
Else
FileOpen(@WorkingDir & "\language.ini", 1)
INICreate()
EndIf

Func INICreate()
IniWrite ($ini, "Default_Language", "Title", "Window")
IniWrite ($ini, "Default_Language", "File", "File")
IniWrite ($ini, "Default_Language", "Modify", "Modify")
IniWrite ($ini, "Default_Language", "Language", "Language")
IniWrite ($ini, "Default_Language", "Label1", "Test text")
IniWrite ($ini, "Default_Language", "Label1", "Different text")
IniWrite ($ini, "Default_Language", "Button1", "Test")
IniWrite ($ini, "Default_Language", "Button2", "Word")
IniWrite ($ini, "User_Language", "Title", "?")
IniWrite ($ini, "User_Language", "File", "?")
IniWrite ($ini, "User_Language", "Modify", "?")
IniWrite ($ini, "User_Language", "Language", "?")
IniWrite ($ini, "User_Language", "Label1", "?")
IniWrite ($ini, "User_Language", "Label1", "?")
IniWrite ($ini, "User_Language", "Button1", "?")
IniWrite ($ini, "User_Language", "Button2", "?")
EndFunc

GUI()

Func GUI()
$Form1 = GUICreate("Window", 217, 239, -1, -1)
$MenuItem5 = GUICtrlCreateMenu(File())
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem5)
$MenuItem4 = GUICtrlCreateMenu("Modify")
$MenuItem3 = GUICtrlCreateMenu("Language")
$Label1 = GUICtrlCreateLabel("Test text", 44, 64, 129, 17)
$Label2 = GUICtrlCreateLabel("Different text", 54, 192, 109, 17)
$Button1 = GUICtrlCreateButton("Test", 16, 16, 89, 41)
$Button2 = GUICtrlCreateButton("Word", 112, 16, 89, 41)
GUICtrlCreateEdit("", 18, 80, 185, 105)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
EndFunc

Func File()
    $var = IniRead($ini, "Default_Language", "File", '')
    If $var Then
        Return $var
    Else
        $var = IniRead($ini, "User_Language", "Title", '')
        If Not $var Then
            MsgBox(0,'','Cant locate anything')
            Exit
  Else
   Return $var
        EndIf
    EndIf
EndFunc

I want to make a conditional IniRead in the GUI, in this case.

Work fine if i use this:

$MenuItem5 = GUICtrlCreateMenu(IniRead( $ini, "Default_Language", "Title", "Window")

But i need to make a something like this:

$MenuItem5 = GUICtrlCreateMenu(File())

Func File()
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   IniRead($ini, "Default_Language", "File", "File")
   Else
   IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
EndFunc

But not work, the result in the GUI is 0.

Someone has some idea? Thanks for support

PS If something is not clear, simply ask.

Edited by johnmcloud

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

use return on func

$var = IniRead($ini, "User_Language", "Title", "i need a text here")
    EndIf
    Return $var
EndFunc

i need a text here

is part what iniread return if that key isnt located, so if there isnt any key named Title itl return 'i need a text here'

The default value to return if the requested key is not found.

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Thanks for answer. The result in the GUI is always 0:

Func File()
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   IniRead($ini, "Default_Language", "File", "File")
   Else
   IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
   Return
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Return $var

not Return and iniread need to log data to $var

look upper post one more time, i edited it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Return $var

Give me error, i don't have a $var variable :)

So i have try to

Return $ini

The result is the path in the of the .ini in the GUI

Please be more clear, i'm not a super expert. Thanks

EDIT: Maybe i'm a noob, but give me the same error, variable not found:

Func File()
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   IniRead($ini, "Default_Language", "File", "File")
   Else
   $var = IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
   Return $var
EndFunc
Edited by johnmcloud

Share this post


Link to post
Share on other sites

Func File()
   Local $var
   If IniRead($ini, "User_Language", "Title", "?") = 0 Then
   $var = IniRead($ini, "Default_Language", "File", "File")
   Else
   $var = IniRead($ini, "User_Language", "Title", "i need a text here")
   EndIf
   Return $var
EndFunc

Is what he means

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

well more something like this :)

Func File()
    $var = IniRead($ini, "Default_Language", "File", '')
    If $var Then
        Return $var
    Else
        $var = IniRead($ini, "User_Language", "Title", '')
        If Not $var Then
            MsgBox(0,'','Cant locate anything')
            Exit
        Else
            Return $var
        EndIf
    EndIf
EndFunc

confusing iniread rewrited it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks guys, but there is a problem, the result is always "File" also if i delete the "?"

I want to make a two language gui.

So if ? is replaced by any text i want to load that text, hope this is the right approach.

@bogQ Same problem, if i delete the "?" the result is always "File" into the GUI

Edited by johnmcloud

Share this post


Link to post
Share on other sites

maby its better for you to load them into array, newer the less i edited upper code, i got lost in your iniwrite so i made mistake first time


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

The ini structure is easy:

[Default_Language]

File=File

[user_Language]

File=?

If user replace "?" with "autoit", i want to load that string in the GUI, so instead of "File" i want to see "autoit" :)

If you can do an example, i'll be grateful

Edited by johnmcloud

Share this post


Link to post
Share on other sites

i now c, did not know that you need to use ? in your 'if then else',

well if noone help you untill i get home from work (in 40 minutes) il post you some small example


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Ok, thanks. I'm using "?" or i can write "none" or " "

Just for make difference, it's not a problem.

Share this post


Link to post
Share on other sites

Ok, thanks. I'm using "?" or i can write "none" or " "

The default return value is up to you and won't change anything.

If user replace "?" with "autoit", i want to load that string in the GUI, so instead of "File" i want to see "autoit" :)

If you can do an example, i'll be grateful

Your not checking if the value is "?". Your checking if the value = 0.

If IniRead($ini, "User_Language", "Title", "?") = 0 Then

That would need to be

If IniRead($ini, "User_Language", "Title", "?") = "?" Then

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@Beege i think was like other function, like MsgBox(0,0, "Test") = 1 Then etc

You have right, now work:

Func File()
   Local $var
   If IniRead($ini, "User_Language", "File", "?") = "?" Then
   $var = IniRead($ini, "Default_Language", "File", "File")
   Else
   $var = IniRead($ini, "User_Language", "File", "")
   EndIf
   Return $var
EndFunc

Thanks to all for support :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

This shud work perfectly

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ini = @WorkingDir & "language.ini"
Dim $element_array[9]=['Title','File','Exit','Modify','Language','Label1','Label2','Button1','Button2']
If Not FileExists($ini) Then
    INICreate()
EndIf
GUI()


Func INICreate()
    IniWrite ($ini, "Default_Language", "Title", "Window")
    IniWrite ($ini, "Default_Language", "File", "File")
    IniWrite ($ini, "Default_Language", "Exit", "Exit")
    IniWrite ($ini, "Default_Language", "Modify", "Modify")
    IniWrite ($ini, "Default_Language", "Language", "Language")
    IniWrite ($ini, "Default_Language", "Label1", "Test text")
    IniWrite ($ini, "Default_Language", "Label2", "Different text")
    IniWrite ($ini, "Default_Language", "Button1", "Test")
    IniWrite ($ini, "Default_Language", "Button2", "Word")
    IniWrite ($ini, "User_Language", "Title", "?")
    IniWrite ($ini, "User_Language", "File", "?")
    IniWrite ($ini, "User_Language", "Exit", "?")
    IniWrite ($ini, "User_Language", "Modify", "?")
    IniWrite ($ini, "User_Language", "Language", "?")
    IniWrite ($ini, "User_Language", "Label1", "?")
    IniWrite ($ini, "User_Language", "Label2", "?")
    IniWrite ($ini, "User_Language", "Button1", "?")
    IniWrite ($ini, "User_Language", "Button2", "?")
EndFunc

Func GUI()
    $Form1 = GUICreate(Language(0), 217, 239, -1, -1)
    $MenuItem5 = GUICtrlCreateMenu(Language(1))
    $MenuItem6 = GUICtrlCreateMenuItem(Language(2), $MenuItem5)
    $MenuItem4 = GUICtrlCreateMenu(Language(3))
    $MenuItem3 = GUICtrlCreateMenu(Language(4))
    $Label1 = GUICtrlCreateLabel(Language(5), 44, 64, 129, 17)
    $Label2 = GUICtrlCreateLabel(Language(6), 54, 192, 109, 17)
    $Button1 = GUICtrlCreateButton(Language(7), 16, 16, 89, 41)
    $Button2 = GUICtrlCreateButton(Language(8), 112, 16, 89, 41)
    GUICtrlCreateEdit("", 18, 80, 185, 105)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc
Func Language($el_num)
    $User_Language = IniRead($ini, "User_Language", $element_array[$el_num], '')
    $Def__Language = IniRead($ini, "Default_Language", $element_array[$el_num], '')
    If $User_Language <> '?' And $User_Language <> '' And $User_Language <> ' ' And $User_Language <> ' ' Then
        Return $User_Language
    Else
        Return $Def__Language
    EndIf
EndFunc

later if i have time il post you some easyer solution

edit:

or another one

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $ini = "language.ini"
Dim $element_array[9][2]=[ _
    ['Title','Window'], _
    ['File','File'], _
    ['Exit','Exit'], _
    ['Modify','Modify'], _
    ['Language','Language'], _
    ['Label1','Test text'], _
    ['Label2','Different text'], _
    ['Button1','Test'], _
    ['Button2','Word']]
If Not FileExists($ini) Then
    INICreate()
EndIf
GUI()
Func INICreate()
    IniWrite ($ini, "User_Language", $element_array[0][0], "?")
    IniWrite ($ini, "User_Language", $element_array[1][0], "?")
    IniWrite ($ini, "User_Language", $element_array[2][0], "?")
    IniWrite ($ini, "User_Language", $element_array[3][0], "?")
    IniWrite ($ini, "User_Language", $element_array[4][0], "?")
    IniWrite ($ini, "User_Language", $element_array[5][0], "?")
    IniWrite ($ini, "User_Language", $element_array[6][0], "?")
    IniWrite ($ini, "User_Language", $element_array[7][0], "?")
    IniWrite ($ini, "User_Language", $element_array[8][0], "?")
EndFunc

Func GUI()
    $Form1 = GUICreate(Language(0), 217, 239, -1, -1)
    $MenuItem5 = GUICtrlCreateMenu(Language(1))
    $MenuItem6 = GUICtrlCreateMenuItem(Language(2), $MenuItem5)
    $MenuItem4 = GUICtrlCreateMenu(Language(3))
    $MenuItem3 = GUICtrlCreateMenu(Language(4))
    $Label1 = GUICtrlCreateLabel(Language(5), 44, 64, 129, 17)
    $Label2 = GUICtrlCreateLabel(Language(6), 54, 192, 109, 17)
    $Button1 = GUICtrlCreateButton(Language(7), 16, 16, 89, 41)
    $Button2 = GUICtrlCreateButton(Language(8), 112, 16, 89, 41)
    GUICtrlCreateEdit("", 18, 80, 185, 105)
    GUISetState(@SW_SHOW)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc
Func Language($el_num)
    $User_Language = IniRead($ini, "User_Language", $element_array[$el_num][0], '')
    If $User_Language <> '?' And $User_Language <> '' And $User_Language <> ' ' And $User_Language <> ' ' Then
        Return $User_Language
    Else
        Return $element_array[$el_num][1]
    EndIf
EndFunc
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Wingens
      By Wingens
      Hi I am trying to read multiple sections from an ini file into an array and use the result to calculate how many records there are from the suppliers and this devided into the status records that belong to it. The problem I am having; I am able to use Ubound to calculate how many record there are in total to the option chosen from the combo box, but where I am getting stuck is the part to link the status and leverancier to each other and count them.
      Hope some one can help me.
      My code right now:
      #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> $Form1 = GUICreate("Form1", 615, 437, 569, 253) $LEVCOMBO = GUICtrlCreateCombo("", 184, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) Global $aSections = IniReadSectionNames(@ScriptDir & "\leveranciers.ini") If (Not @Error) Then GUICtrlSetData($LEVCOMBO, _ArraytoString($aSections, "|", 1), $aSections[1]) $LABEL = GUICtrlCreateLabel("Totaal aantal RMA aanvragen: ", 48, 200, 250, 21) $TOTALCOUNT = GUICtrlCreateLabel("", 200, 200, 100, 21) $LABEL2 = GUICtrlCreateLabel("Aantal aangevraagd: ", 48, 225, 250, 21) $TOTALAANGEVRAAGD = GUICtrlCreateLabel("", 200, 225, 100, 21) $LABEL3 = GUICtrlCreateLabel("Aantal verzonden: ", 48, 250, 250, 21) $TOTALVERZONDEN = GUICtrlCreateLabel("", 200, 250, 100, 21) $LABEL4 = GUICtrlCreateLabel("Aantal afgehandeld: ", 48, 275, 250, 21) $TOTALAFGEHANDELD = GUICtrlCreateLabel("", 200, 275, 100, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $LEVCOMBO COMBO() EndSwitch WEnd Func COMBO() Local $hINI_FILENAME = @ScriptDir & "\ini.ini" $READAANGEVRAAGDRMA = IniReadSection($hINI_FILENAME, 'LEVERANCIER') $READSTATUS = IniReadSection($hINI_FILENAME, 'STATUS') $VAR = GUICtrlRead($LEVCOMBO) $READAANGEVRAAGDRMACOUNT = _ArrayFindAll($READAANGEVRAAGDRMA, $VAR, Default, Default, Default, Default, 1) GUICtrlSetData($TOTALCOUNT,UBound($READAANGEVRAAGDRMACOUNT)) $nb = $READAANGEVRAAGDRMA[0][0] Local $res[$nb+1][3] $res[0][0] = $nb For $i = 1 to $nb $res[$i][0] = $READAANGEVRAAGDRMA[$i][1] $res[$i][1] = $READSTATUS[$i][1] Next _ArrayDisplay($res) EndFunc And the ini files that goes with it:
      ini.ini:
      [STATUS] 1=Afgehandeld 3=Verzonden 4=Aangevraagd 5=Aangevraagd 6=Aangevraagd 7=Aangevraagd 8=Verzonden 9=Aangevraagd 10=Aangevraagd 11=Aangevraagd 12=Aangevraagd 13=Aangevraagd 14=Aangevraagd 15=Aangevraagd 16=Aangevraagd 17=Aangevraagd 18=Aangevraagd 19=Aangevraagd 20=Aangevraagd 21=Aangevraagd 22=Aangevraagd [LEVERANCIER] 9=Dobit B.V. 1=Dobit B.V. 10=Dobit B.V. 11=Dobit B.V. 12=Dobit B.V. 13=Dobit B.V. 14=Asus 15=Asus 16=Brother 17=Dobit B.V. 18=Dobit B.V. 19=Dobit B.V. 20=Dobit B.V. 21=Dobit B.V. 22=Asus leveranciers.ini:
      [Kies een leverancier...] [Dobit B.V.] URL =http://eline.dobit.be/eline/master.php [TechData B.V.] URL = [MaxICT B.V.] URL = [Brother] URL= [Asus] URL=https://eu-rma.asus.com/pickup_europe/pickup.aspx?country=nl [HP] URL= [Lenovo] URL= [CCV] URL=  
      test.au3
      ini.ini
      leveranciers.ini
    • TheDcoder
      By TheDcoder
      Hello , I was thinking of a situation where a key in a ini file can contain anything, If we were to know if the key does not exists using IniRead, Its not possible to do it without compromising a single possibility... I was thinking that if IniRead were to set @error when a key does not exist, it solves the problem which I mentioned before
       
      What do you think? Would you like this feature?
      TD
    • zemkor
      By zemkor
      Hello, i have question. How to save and read data from "GUICtrlCreateEdit" to ini file ?. Problem is: IniWrite write only first line of text and IniRead read only first line text.
      How to do it?
      Thanks for answer.
      $text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func save() Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; save file dialog $ini_file = FileSaveDialog('Save', @ScriptDir, 'Ini (*.ini)|All (*.*)', 10, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; write to ini file IniWrite($ini_file, "Data", "Text", GUICtrlRead($Text)) EndFunc $text = GUICtrlCreateEdit("Text", 20, 165, 120, 50) Func load() ;natiahne nastavenia z .ini Local $ini_file, $workingdir ; save workingdir $workingdir = @WorkingDir ; open file dialog $ini_file = FileOpenDialog('Open', @ScriptDir, 'Ini (*.ini)|All (*.*)', 1, 'Config.ini', $Form1) ; check if return is valid If @error Or $ini_file == '' Then FileChangeDir($workingdir) Return SetError(1, 0, '') EndIf ; read from ini file GUICtrlSetData($text, IniRead($ini_file, "Data", "Text", "")) EndFunc This not working, read and write only firt line
    • MHz
      By MHz
      These functions handle ANSI and unicode inifiles similar to IniRead, IniWrite and IniDelete.
      _WinAPI_WritePrivateProfileStringW _WinAPI_GetPrivateProfileStringW So you can read from unicode inifiles created from other programs or perhaps read and write to your own inifiles.
      I was unable to figure out how the API function of WritePrivateProfileStringW can create a unicode file initially so I instead used FileOpen to create a unicode file and write the 1st entry to achieve this. Further use uses WritePrivateProfileStringW is ok to handle the unicode entries. ANSI file creation is done by WritePrivateProfileStringW by default.
      Deletion of keys and sections may need use of Null which is in AutoIt 3.3.9.0 and later. I put comments with the code so hopefully understandable to you.
      The functions use a similar parameter syntax to IniRead and IniWrite. _WinAPI_WritePrivateProfileStringW has an additional parameter to handle the flag passed to FileOpen for the initial creation of the inifile. _WinAPI_GetPrivateProfileStringW has an additional parameter in case you want the buffer that holds the return value within the UDF to be larger.
      The example has some russian text in it so you need to save it in a unicode script for correct testing.
      Example
      ; show message if script is not unicode. Unicode text in this script requires it to be UTF encoded. ; if needed in Scite, use menu bar, File -> Encoding -> UTF (any UTF type that suits you) and save the script. If Not FileGetEncoding(@ScriptFullPath) Then MsgBox(0, @ScriptName, 'Script is not unicode') ; write to ini file $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', 'Открыть', 0x21) _Notify('Write', $return) ; read from ini file $return = _WinAPI_GetPrivateProfileStringW("test.ini", 'russian', 'Open', 'Default') _Notify('Read', $return) #cs AutoIt 3.3.9.0 or later using Null keyword ; setting $sValue parameter with Null keyword will delete a key using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', Null) ; setting $sKey parameter with Null keyword will delete a section using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', Null, Null) ; setting $sSection parameter with Null keyword will flush using AutoIt 3.3.9.x or later. $return = _WinAPI_WritePrivateProfileStringW("test.ini", Null, Null, Null) #ce ; More info of an API that mimics these functions and explains use of Null at http://code.google.com/p/privateprofilestring/ Func _Notify($title, $return = 0, $error = @error, $extended = @extended) ; notify results from other function calls MsgBox(StringRegExpReplace($error, '-{0,1}([1-9])[0-9]*', '0x30'), $title, _ '@error = ' & $error & @CRLF & _ '@extended = ' & $extended & @CRLF & _ '$return = ' & $return _ ) EndFunc User defined functions
      ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_WritePrivateProfileStringW ; Description ...: Write to ANSI and unicode encoded ini files ; Syntax.........: _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue[, $iMode = 1]) ; Parameters ....: $sFileName - The filename of the .ini file ; $sSection - The section name in the .ini file ; $sKey - The key name in the in the .ini file ; $sValue - The value to write/change ; $iMode - Refer to FileOpen mode parameter ; Return values .: Success - Not 0 ; Failure - 0 ; @error 1 to 5 - Refer to DllCall ; @error 6 - FileOpen failed to open a handle to create the file ; Author ........: MHz ; Modified.......: ; Remarks .......: Similar to IniWrite but uses unicode API calls. If $sValue is Null then $sKey is deleted. If $sKey is Null, ; then $sSection is deleted. If $sSection, $sKey and $sValue are all Null, then $sFileName is ; flushed. *** Null is a keyword that only exists in AutoIt3 versions 3.3.9.x and later *** ; Related .......: DllCall, FileOpen, IniWrite ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms725501%28v=vs.85%29.aspx ; http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue, $iMode = 1) Local $handle_write, $ret ; check if path is relative and make it absolute if it is relative $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName ; create a unicode encoded file if needed and write the entry If Not FileExists($sFileName) And $iMode > 0x20 Then $handle_write = FileOpen($sFileName, $iMode) If $handle_write = -1 Then Return SetError(6, 0, 0) FileWrite($handle_write, '[' & $sSection & ']' & @CRLF & $sKey & '=' & $sValue & @CRLF) FileClose($handle_write) Return 1 EndIf ; write to the ini file. $ret[0] will contain nonzero if successful $ret = DllCall('Kernel32.dll', 'bool', 'WritePrivateProfileStringW', _ 'wstr', $sSection, _ 'wstr', $sKey, _ 'wstr', $sValue, _ 'wstr', $sFileName _ ); lpAppName, lpKeyName, lpString, lpFileName If @error Then Return SetError(@error, @extended, 0) Return SetExtended(0, $ret[0]) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinAPI_GetPrivateProfileStringW ; Description ...: Read from ANSI and unicode encoded ini files ; Syntax.........: _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey[, $sDefault = ''[, $iBufferSize = 65536]]) ; Parameters ....: $sFileName - The filename of the .ini file ; $sSection - The section name in the .ini file ; $sKey - The key name in the in the .ini file ; $sDefault - The default value to return if the requested key is not found ; $iBufferSize - Adjustable buffer size which contains the chars from the API call ; Return values .: Success - Returns the requested key value ; Failure - Returns the default string if requested key not found ; @error 1 to 5 - Refer to DllCall ; Author ........: MHz ; Modified.......: ; Remarks .......: Similar to IniRead but uses unicode API calls ; Related .......: IniRead ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724353%28v=vs.85%29.aspx ; http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx ; Example .......: Yes ; =============================================================================================================================== Func _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey, $sDefault = '', $iBufferSize = 65536) Local $buffer, $ret ; check if path is relative and make it absolute if it is relative $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName ; create a buffer to hold the returned string $buffer = DllStructCreate('wchar[' & $iBufferSize & ']') ; read from the ini file. $ret[0] will contain number of chars returned $ret = DllCall('Kernel32.dll', 'dword', 'GetPrivateProfileStringW', _ 'wstr', $sSection, _ 'wstr', $sKey, _ 'wstr', $sDefault, _ 'ptr', DllStructGetPtr($buffer), _ 'dword', DllStructGetSize($buffer), _ 'wstr', $sFileName _ ); lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName If @error Then SetError(@error, @extended, $sDefault) Return SetExtended($ret[0], DllStructGetData($buffer, 1)) EndFunc Thanks to AZJIO for some russian text for use in the example.
      Edit:
      Updated with summary correction by guiness in post #2
    • Darkbeo
      By Darkbeo
      Hello all,

      is possible to create a script that sets the key to be pressed from information taken from an ini file?

      AutoIt.au3

      HotKeySet( IniRead("file.ini", "Section", "Key", "Hotkey"), "Function" )
      file.ini

      [Section] Key=F5
      So the result would be:

      HotKeySet( "F5", "Function" )