Jump to content
Sign in to follow this  
kris7942

My small problem with Filewriteline & Input

Recommended Posts

kris7942

Hi guys :)

I am newbie in autoit scripts but i like this program, so i want try to compile easy .ini configurator based on "FileWriteLine", but the problem is the file wasnt created with text from $input :)

Ini file is always

My ini file

ProgramWindow = Name of your Program Window

CloseKey = Close Key

StartKey = Start Key

Anyway, if i write in inputs some like F1, F2, F3 or F4 then file still be wrote like above

What is wrong? Need help :P

Opt("GUIOnEventMode", 1)
#include-once
#include <File.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Dialog", 377, 210, 320, 253)
GUISetIcon("D:\004.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 1, 265, 193)
$InputWindow = GUICtrlCreateInput("Name of your Program Window", 16, 16, 145, 21)
$InputStart = GUICtrlCreateInput("Start key", 16, 48, 145, 21)
$InputStop = GUICtrlCreateInput("Close key", 16, 80, 145, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ButtonOK = GUICtrlCreateButton("&OK", 286, 11, 75, 25, $WS_GROUP)
$ButtonCancel = GUICtrlCreateButton("&Cancel", 285, 44, 75, 25, $WS_GROUP)
$Buttonhelp = GUICtrlCreateButton("&Help", 285, 76, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Buttonhelp, "_Help")
GUICtrlSetOnEvent($ButtonCancel, "_Cancel")
GUICtrlSetOnEvent($ButtonOK, "_OK")
#EndRegion ### END Koda GUI section ###

$INI = @ScriptDir & "\Some file.ini"
$title = IniRead($INI, "My ini file", "ProgramWindow", "")
$Exit = IniRead($INI, "My ini file", "CloseKey", "")
$Start = IniRead($INI, "My ini file", "StartKey", "")

        $1 = GUICtrlRead($InputWindow, 1)
        $2 = GUICtrlRead($InputStop, 1)
        $3 = GUICtrlRead($InputStart, 1)

$HelpMsg = "You must set here:"& @LF &"- Name of your Program Window: Here write your Program Window name"& @LF &"- Start key: A key to run script" & @LF &"- Stop key: A key to close program")

Func _Help()
    MsgBox(0, "Small help to set ini file", $HelpMsg)
    EndFunc

Func _Cancel()
GUISetState(@SW_HIDE)
    EndFunc


    Func _OK()
;============================== Creating File ==============================

$file = FileOpen("Some file.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "My ini file" & @CRLF)
FileWriteLine($file, "ProgramWindow = " & $1 & @CRLF)
FileWriteLine($file, "CloseKey = " & $2 & @CRLF)
FileWriteLine($file, "StartKey = " & $3)
FileClose($file)
GUISetState(@SW_HIDE)

EndFunc
Edited by kris7942

Share this post


Link to post
Share on other sites
Josbe

I assume that you know about IniWrite() function.

Well, the *.ini file file must look like this (check the square brackets):

[My ini file]
ProgramWindow=Name of your Program Window
CloseKey=Close Key
StartKey=Start Key

Read more about INI format.

Share this post


Link to post
Share on other sites
kris7942

I replaced

$file = FileOpen("Some file.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "My ini file" & @CRLF)
FileWriteLine($file, "ProgramWindow = " & $1 & @CRLF)
FileWriteLine($file, "CloseKey = " & $2 & @CRLF)
FileWriteLine($file, "StartKey = " & $3)
FileClose($file)
GUISetState(@SW_HIDE)

With

IniWrite(@ScriptDir & "\Some File.ini", "My ini file", "ProgramWindow", $1 & @CRLF)
IniWrite(@ScriptDir & "\Some File.ini", "", "CloseKey", $2 & @CRLF)
IniWrite(@ScriptDir & "\Some File.ini", "", "StartKey", $3)
GUISetState(@SW_HIDE)

and .ini file have

[My ini file]

ProgramWindow=Name of your Program Window

[]

CloseKey=Stop key

StartKey=Start key

I think something is wrong with $1 or program bug? i saw many au3 programs but none can be configured from GUI window :\

Edited by kris7942

Share this post


Link to post
Share on other sites
martin

I replaced

$file = FileOpen("Some file.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "My ini file" & @CRLF)
FileWriteLine($file, "ProgramWindow = " & $1 & @CRLF)
FileWriteLine($file, "CloseKey = " & $2 & @CRLF)
FileWriteLine($file, "StartKey = " & $3)
FileClose($file)
GUISetState(@SW_HIDE)

With

IniWrite(@ScriptDir & "\Some File.ini", "My ini file", "ProgramWindow", $1 & @CRLF)
IniWrite(@ScriptDir & "\Some File.ini", "", "CloseKey", $2 & @CRLF)
IniWrite(@ScriptDir & "\Some File.ini", "", "StartKey", $3)
GUISetState(@SW_HIDE)

and .ini file have

Looks to me like the ini file is exactly as expected from what you have asked your script to write to it. What do you think the problem is with $1? When your program start the text in $InputWindowis set to "Name of your Program Window" so that is what you get in th eini.

Maybe it's because you have given the section as "" for $2 and $3 that you are confused by "[]" ?

EDIT: BTW, adding @CRLF to the end of $2 is of no use.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
NoHAX

Try

ConsoleWrite("Creating File" & @LF)
;============================== Creating File ==============================
$file = FileOpen("Settings.ini", 1)
; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWriteLine($file, "[Setings]" & @CRLF)
FileWriteLine($file, "Window = " & guictrlread($InputWindow) & @CRLF)
FileWriteLine($file, "Start = " & guictrlread($InputStart) & @CRLF)
FileWriteLine($file, "Exit = " & guictrlread($InputStop) & @CRLF)
FileClose($file)
GUISetState(@SW_HIDE)
EndFunc

It works in my script

but i dont know why i must wrote guictrlread($InputWindow) and i cant use $1 = guictrlread($InputWindow) :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.