Jump to content

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)
GUISetState(@SW_SHOW)
#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)
    Else
        Exit
    EndIf
EndIf

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

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

    EndSwitch
WEnd

Any ideas?

Link to comment
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.

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