Jump to content

Reading and saving from an edit box


Go to solution Solved by jdelaney,

Recommended Posts

Ive made an edit box for a gui that i want simple notes saved from

This is called from a save button

Local $TextBox = GUICtrlCreateEdit("" & @CRLF, 15, 380, 590, 200, $ES_AUTOVSCROLL + $WS_VSCROLL)

Func _SaveEdit()
    Local $ReadText = GUICtrlRead($TextBox)
    Local $TextFile = FileOpen( @ScriptDir & "\FileTest.txt", $FO_APPEND)
    FileWrite( $TextFile, $ReadText)
EndFunc ;==#  _SaveEdit()

but i want it to bring back any current text in the textfile back into the edit box so we can see previous edits so i tried this

Local $LoadText = FileRead(@ScriptDir & "\FileTest.txt")
Local $TextBox = GUICtrlCreateEdit($LoadText & @CRLF, 15, 380, 590, 200, $ES_AUTOVSCROLL + $WS_VSCROLL)

Now it brings the text back but sometimes it doubles up

and i cant seem to delete stuff from the edit and it remove it from the file?

What have i done wrong?

EDIT i think the extra text is coming from the load of the exisitng file it seems to add them in again when you save..

Edited by Chimaera
Link to comment
Share on other sites

  • Solution

You are appending to, instead of overwriting.  Is that your intention?  The more you save, the longer the file will get.

[optional] Mode to open the file in.
Can be a combination of the following:
    $FO_READ (0) = Read mode (default)
    $FO_APPEND (1) = Write mode (append to end of file)
    $FO_OVERWRITE (2) = Write mode (erase previous contents)
    $FO_CREATEPATH (8) = Create directory structure if it doesn't exist (See Remarks).
    $FO_BINARY (16) = Force binary mode (See Remarks).
    $FO_UNICODE or $FO_UTF16_LE (32) = Use Unicode UTF16 Little Endian reading and writing mode. Reading does not override existing BOM.
    $FO_UTF16_BE (64) = Use Unicode UTF16 Big Endian reading and writing mode. Reading does not override existing BOM.
    $FO_UTF8 (128) = Use Unicode UTF8 (with BOM) reading and writing mode. Reading does not override existing BOM.
    $FO_UTF8_NOBOM (256) = Use Unicode UTF8 (without BOM) reading and writing mode.
    $FO_UTF8_FULL (16384) = When opening for reading and no BOM is present, use full file UTF8 detection. If this is not used then only the initial part of the file is checked for UTF8.
The folder path must already exist (except using $FO_CREATEPATH mode - See Remarks).

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

yeah just figured it out was coming back to post

$FO_OVERWRITE

solves the doubling up

i load the file as normal which retrieves the old text then i overwite which saves the whole text + additions back to the file

Edited by Chimaera
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...