Sign in to follow this  
Followers 0
ficofico

Simple script file reader/writer

3 posts in this topic

Hy guys, I've found this amazing tool and forum ....

I've a problem that need to solve

I've an input box

GUICtrlCreateGroup("Luminosità", 10, 200, 120, 40)

$luminosita = GUICtrlCreateInput("", 12, 220, 100, 20, $ES_NUMBER)

and a button

$provabutton = GUICtrlCreateButton("prova", 50, 300, 80, 30)

I want that ,on lunch executable , input read from a txt file , and changing the input box with another value and pressing the button, the txt file change

I don't know how do this, and with help I have found "write in a line" or other, but it's possible to write "text", not variables

In the text file I need to read and put only a floating number, not strange arrays.

It's possible to do this? Very thanks at all...

Share this post


Link to post
Share on other sites



Check out these spiffy examples:

;Some pre run stuff.  if you need to change the path of the text file, PLEASE DO!
$filepath = "C:\test.txt"
$file = FileOpen ($filepath, 10)
FileWrite ($file, "These examples were created by Bert on the AutoIt forums.  Enjoy learning AutoIt :)")
FileClose ($file)

;################################################
;#####      LAUNCHING A PROGRAM             #####
;################################################

MsgBox (0, "Example:", "This is an example of using a button to launch a program.  To be precise, notepad.")
;includes:
#include <GUIConstants.au3>

;Create the GUI
$Form1 = GUICreate("GUI Title", 267, 73, 193, 115)
;Label- Bit of 'eye candy'
$Label1 = GUICtrlCreateLabel("Click launch to launch notepad", 4, 4, 255, 33)
;Button: To launch Notepad
$Button1 = GUICtrlCreateButton("Launch", 4, 40, 75, 25, 0)
;Show the GUI
GUISetState(@SW_SHOW)

While 1
    ;Poll the GUI for changes
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ;If the big X is clicked, Close
            ExitLoop ;Would normally be Exit
        Case $msg = $Button1
            ;If the Launch button is pressed
            Run ("notepad"); The path can be an .exe, basically, anything you can type in run, and in turn run...
    EndSelect
WEnd
;Delete the GUI
GUIDelete ($Form1)

;################################################
;#####         READING A TEXT FILE          #####
;################################################
MsgBox (0, "Example:", "This is an example of Reading a text file")

;Open the file
$file = FileOpen ($filepath, 0)
;Read the File
$text = FileRead ($file)
;Display file contents
MsgBox (0, "File Contents", $text)
FileClose ($file)

;################################################
;#####   CHANGING THE CONTENTS OF A INPUT   #####
;################################################
MsgBox (0, "Example:", "This is an example of changing the content of an input box")

$text1 = "This is the orginal text"
$text2 = "This is not the orginal text.  Because it is different"

;Create the GUI
$gui = GUICreate ("Example", 200, 200)
;Create the input box
$input = GUICtrlCreateInput ($text1, 5, 5, 190, 27)
;Create a button
$button = GUICtrlCreateButton ("Change Value", 60, 35, 80, 25)
;Show the GUI
GUISetState(@SW_SHOW)

While 1
    ;Poll the GUI for changes
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ;If the big X is clicked, Close
            ExitLoop ; Would normally be Exit
        Case $msg = $Button
            ;If the Launch button is pressed
            GUICtrlSetData ($input, $text2)
    EndSelect
WEnd
;Delete the GUI
GUIDelete ($gui)

;################################################
;#####   WRITING A VARIBLE TO A TEXT FILE   #####
;################################################
MsgBox (0, "Example:", "This is an example of writing to a text file")
; Read the old contents
$file = FileOpen ($filepath, 0)
$original = FileRead ($file)
FileClose ($file)

;Write the new contents
$file = FileOpen ($filepath, 1)
$new = InputBox ("New Text", "Please type a line to write a line to.")
FileWrite ($file, $new)
FileClose ($file)

;Read the updated file
$file = FileOpen ($filepath, 0)
$newcont = FileRead ($file)
FileClose ($file)
;Display the message
$msg = "File Read Contents Before:" & @CRLF & _
$original & @CRLF & _
"File New Text:" & @CRLF & _
$new & @CRLF & _
"File Read Contents After:" & @CRLF & _
$newcont
MsgBox (0, "File Read/Write Example", $msg)

; Exit Program
Exit

Oh... And welcome to the forums :)

Share this post


Link to post
Share on other sites

thanks, it works perfect

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