Jump to content

Iniread & Iniwrite


Markir
 Share

Recommended Posts

Hello everybody,

I have a question of this feature.

#include <GUIConstants.au3>



GUICreate("IniTest") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)


$ok1 = GUICtrlCreateButton ("Sichern",  -10, 340, 50)
GUICtrlSetOnEvent(-1, "Sichern")

$ok2 = GUICtrlCreateButton ("Abbrechen",  0, -1)
GUICtrlSetOnEvent(-1, "Abbrechen")


GUISetState ()    ; will display an  dialog box with 2 button
GUISetState (@SW_SHOW)

; Run the GUI until the dialog is closed
While 1
    Sleep(10)
Wend


Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
$var='Enabled'
IniWrite("E:\myfile.ini", "Checkbox", "Status", $var)
ELSE 
$var='Disabled'
IniWrite("E:\myfile.ini", "Checkbox", "Status", $var)
EndIf
EndFunc


Func Abbrechen()

EndFunc

With this code I get the status of the checkbox in the myfile.ini. So now I would have, then i start the programm at second time, that the checkbox will get the status that is in the myfile.ini. How can I realise that?

Link to comment
Share on other sites

  • Developers

#include <GUIConstants.au3>

$var = IniRead("E:\myfile.ini", "Checkbox", "Status", $GUI_UNCHECKED) 

GUICreate("IniTest"); will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN,$var)
.............

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I have changed the code to your one...

#include <GUIConstants.au3>

$var = IniRead("E:\myfile.ini", "Checkbox", "Status", $GUI_UNCHECKED) 

GUICreate("IniTest"); will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN,$var)


$ok1 = GUICtrlCreateButton ("Sichern",  -10, 340, 50)
GUICtrlSetOnEvent(-1, "Sichern")

$ok2 = GUICtrlCreateButton ("Abbrechen",  0, -1)
GUICtrlSetOnEvent(-1, "Abbrechen")


GUISetState ()    ; will display an  dialog box with 2 button
GUISetState (@SW_SHOW)

; Run the GUI until the dialog is closed
While 1
    Sleep(10)
Wend


Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
$var='Enabled'
IniWrite("E:\myfile.ini", "Checkbox", "Status", $var)
ELSE 
$var='Disabled'
IniWrite("E:\myfile.ini", "Checkbox", "Status", $var)
EndIf
EndFunc


Func Abbrechen()

EndFunc

..., but then I start the Programm at a second time the checkbox will be disabled, but in the myfile.ini the status = Enabled. Where ist the problem?

Link to comment
Share on other sites

  • Developers

change this as well and see if that helps:

Func Sichern()
    IniWrite("E:\myfile.ini", "Checkbox", "Status", GUICtrlRead($checkCN))
EndFunc  ;==>Sichern

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hello,

now it works so far. Then I start the program, tthe ini file will be read and the status is right, but in the ini file there will be displayed "0" or "4" and not "disabled" or "enabled"

Here is the code:

#include <GUIConstants.au3>

$var = IniRead("C:\myfile.ini", "Checkbox", "Status", $GUI_UNCHECKED) 

GUICreate("Ini-Test"); will create a dialog box that when displayed is centered

Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)

$checkCN = GUICtrlCreateCheckbox ("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN,$var)


$ok1 = GUICtrlCreateButton ("Sichern",  -10, 340, 50)
GUICtrlSetOnEvent(-1, "Sichern")

$ok2 = GUICtrlCreateButton ("Abbrechen",  0, -1)
GUICtrlSetOnEvent(-1, "Abbrechen")


GUISetState ()    ; will display an  dialog box with 2 button
GUISetState (@SW_SHOW)

; Run the GUI until the dialog is closed
While 1
    Sleep(10)
Wend


Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
Iniwrite("C:\myfile.ini", "Checkbox", "Status", GUICtrlRead($checkCN))
ELSE 
Iniwrite("C:\myfile.ini", "Checkbox", "Status", GUICtrlRead($checkCN))
EndIf
EndFunc  ; ==>Sichern


Func Abbrechen()

EndFunc

Can anybody help me to solve the problem?

Link to comment
Share on other sites

  • Developers

Hello,

now it works so far. Then I start the program, tthe ini file will be read and the status is right, but in the ini file there will be displayed "0" or "4" and not "disabled" or "enabled"

Can anybody help me to solve the problem?

<{POST_SNAPBACK}>

Yes, because 0 & 4 are the values for it.

If you want to save a word then just add the IF's back like you had them.

Also add an If at the beginning of the script to set the $var to 0 or 4 depending on the value in the INI file.... :lmao:

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Hello Jdeb,

sorry but I don'T understand what you mean? Can you explaine me it on the code?

<{POST_SNAPBACK}>

something like:

#include <GUIConstants.au3>

If IniRead("C:\myfile.ini", "Checkbox", "Status", 'Disabled') = 'Disabled' Then
    $var = $GUI_UNCHECKED
Else
    $var = $GUI_CHECKED
EndIf

GUICreate("Ini-Test"); will create a dialog box that when displayed is centered

Opt ("GUICoordMode", 2)
Opt ("GUIOnEventMode", 1)

$checkCN = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN, $var)


$ok1 = GUICtrlCreateButton("Sichern", -10, 340, 50)
GUICtrlSetOnEvent(-1, "Sichern")

$ok2 = GUICtrlCreateButton("Abbrechen", 0, -1)
GUICtrlSetOnEvent(-1, "Abbrechen")


GUISetState()    ; will display an  dialog box with 2 button
GUISetState(@SW_SHOW)

; Run the GUI until the dialog is closed
While 1
    Sleep(10)
WEnd

If GUICtrlRead($checkCN) = $GUI_CHECKED Then
    IniWrite("E:\myfile.ini", "Checkbox", "Status", 'Enabled')
Else
    IniWrite("E:\myfile.ini", "Checkbox", "Status", 'Disabled')
EndIf


Func Abbrechen()
    
EndFunc  ;==>Abbrechen

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

How can I write Input in the ini file and read from the ini file to see the ini files?

With the code below, in the ini file are status 4 or 5. Can anybody help me? I need examples for dropdown menu, too.

#include <GUIConstants.au3>

If IniRead("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled') = 'Disabled' Then
    $var = $GUI_UNCHECKED
Else
    $var = $GUI_CHECKED
EndIf

IniRead("C:\xpr_install.ini", "Textinput", "Eintrag", '$file')

GUICreate("Ini-Test"); will create a dialog box that when displayed is centered

Opt ("GUICoordMode", 2)
Opt ("GUIOnEventMode", 1)

$checkCN = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN, $var)

$file = GUICtrlCreateInput ( "", 10,  5, 100, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)

$ok1 = GUICtrlCreateButton("Sichern", -10, 340, 50)
GUICtrlSetOnEvent(-1, "Sichern")

$ok2 = GUICtrlCreateButton("Abbrechen", 0, -1)
GUICtrlSetOnEvent(-1, "Abbrechen")


GUISetState()   ; will display an  dialog box with 2 button
GUISetState(@SW_SHOW)

; Run the GUI until the dialog is closed
While 1
    Sleep(10)
WEnd

Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Enabled')
    IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
Else
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled')
    IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
EndIf
EndFUnc

Func Abbrechen()
    
EndFunc ;==>Abbrechen
Link to comment
Share on other sites

  • Developers

How can I write Input in the ini file and read from the ini file to see the ini files?

With the code below, in the ini file are status 4 or 5. Can anybody help me? I need examples for dropdown menu, too.

<{POST_SNAPBACK}>

You probably need to explain what you want to accomplish here.....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Okay, I would describe it a little bit better:

$file = GUICtrlCreateInput ( "", 10,  5, 100, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)

In this Inputfield I want to write my name, for example.

Then I klick on Button "Sichern", the following code

Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Enabled')
    IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
Else
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled')
    IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
EndIf
EndFUnc

must save the input "marc" in the xpr_install.ini file.

At last, then I open the programm at a second time, the input "marc" should display again.

I hope you understand me, because my english is not so good.

Link to comment
Share on other sites

Hi..

i think its all ok, you just have to read the value from the inifile at the beginning of your program, and set the textfield to the value.

I think the best would be to write a function "laden()" as opposite to your function "sichern()" which does the same in revearse order.. and call this function at the beginning of your program.

And you could also simplifiy your sichern function, cause you do the same with the Textinput if the checkbox is checked or not.

so:

Func Sichern()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Enabled')
Else
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled')
EndIf
IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
EndFUnc
Link to comment
Share on other sites

Hi ..

yes i speak german, but we are in a english Board, so lets stay in english :-)

about an example, i dont have much experience with the GUI.. so you will have to correct my example (its propably not working, but there's the helpfile.... )

#include <GUIConstants.au3>

If IniRead("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled') = 'Disabled' Then
    $var = $GUI_UNCHECKED
Else
    $var = $GUI_CHECKED
EndIf

$value=IniRead("C:\xpr_install.ini", "Textinput", "Eintrag", " ") ;read the value from ini file...

GUICreate("Ini-Test"); will create a dialog box that when displayed is centered

Opt ("GUICoordMode", 2)
Opt ("GUIOnEventMode", 1)

$checkCN = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN, $var)

$file = GUICtrlCreateInput ( "", 10,  5, 100, 20)
GUICtrlSetState($file,$value) ;set the value

..
..
..

mfg Domonoky

Edited by Domonoky
Link to comment
Share on other sites

Hello Domonoky,

your example works a little bit, here the code:

#include <GUIConstants.au3>

If IniRead("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled') = 'Disabled' Then
    $var = $GUI_UNCHECKED
Else
    $var = $GUI_CHECKED
EndIf

$value=IniRead("C:\xpr_install.ini", "Textinput", "Eintrag", " ");read the value from ini file...

GUICreate("Ini-Test"); will create a dialog box that when displayed is centered

Opt ("GUICoordMode", 2)
Opt ("GUIOnEventMode", 1)

$checkCN = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
GUICtrlSetState($checkCN, $var)

$file = GUICtrlCreateInput ( "", 10,  5, 100, 20)
GUICtrlSetState($file,$value);set the value

$ButtonReg_Import = GUICtrlCreateButton ("  Import  ", 10, 30)
GUICtrlSetOnEvent(-1, "Reg_Import")

GUISetState() 
While 1
   Sleep(10)
WEnd

Func Reg_Import()
If GUICtrlRead($checkCN) = $GUI_CHECKED Then
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Enabled')
Else
    IniWrite("C:\xpr_install.ini", "Checkbox", "Status", 'Disabled')
EndIf
IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", $file)
EndFUnc

But the result of this code is the following in the ini-file:

[Checkbox]

Status=Enabled

[Textinput]

Eintrag=4

I have write the name marc in the inputfield, and in the file there is the input "4".

Link to comment
Share on other sites

  • Developers

$file contains the handle of the input control. to read its value you need to do GuiCtrlRead() ....

IniWrite("C:\xpr_install.ini", "Textinput", "Eintrag", GUICtrlRead($file))

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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