Jump to content
Sign in to follow this  

Problem with writing to text file.

Recommended Posts


New to AutoIt. I'm just trying to get a feel for things. I wanted to make a simple program that would check for a txt file and if it exists, shows the contents and allows you edit it, and if it doesn't exist, creates and allows you to edit it. There's also a save button to save the text that you enter. It all works, but the txt file isn't written to till after you exit the program.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Stuff", 197, 225, 193, 158)
$Stuff = GUICtrlCreateEdit("", 0, 0, 193, 201)
$MenuItem1 = GUICtrlCreateMenu("File")
$Save = GUICtrlCreateMenuItem("Save", $MenuItem1)
#EndRegion ### END Koda GUI section ###

$fileExi = FileExists("stuff.txt");Checks for file.  Doesn't exist: ask to create.
If $fileExi = 0 Then
    $dec = MsgBox(4, "Stuff.txt doesn't exist.", "Would you like to create stuff.txt?")
    If $dec = 6 Then
        $fileR = FileOpen("stuff.txt", 10)

If $fileExi = 1 Then
    $fileR = FileOpen("Stuff.txt", 0) 
    $list = FileRead($fileR)
    GuiCtrlSetData($Stuff, $list)

While 1
    $nMsg = GUIGetMsg()
        Case $nMsg = $Save
            $fSave = FileOpen("stuff.txt", 2)
            $sText = GUICtrlRead($Stuff)
            FileWrite($fSave, $sText)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE


Any ideas?

Share this post

Link to post
Share on other sites

New to AutoIt. I'm just trying to get

Any ideas?

how are you "proving" that the file isn't written?

The help file gives info about how to tell if a particular command failed. Use that info if you believe your testing methodology is sound.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

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.