Jump to content

Save contents of GUI Edit box to a text file


Recommended Posts

How would I save the contents of a this edit box to a unicode text file?

;====================================================

;================= Example of a GUI =================

;====================================================

; AutoIt version: 3.0.103

; Language: English

; Author: "SlimShady"

;

; ----------------------------------------------------------------------------

; Script Start

; ----------------------------------------------------------------------------

;Include constants

#include <GUIConstants.au3>

;Initialize variables

Global $GUIWidth

Global $GUIHeight

$GUIWidth = 300

$GUIHeight = 250

;Create window

GUICreate("New GUI", $GUIWidth, $GUIHeight)

;Create an edit box with no text in it

$Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

;Create an "OK" button

$OK_Btn = GUICtrlCreateButton("OK", 75, 210, 70, 25)

;Create a "CANCEL" button

$Cancel_Btn = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)

;Show window/Make the window visible

GUISetState(@SW_SHOW)

;Loop until:

;- user presses Esc

;- user presses Alt+F4

;- user clicks the close button

While 1

;After every loop check if the user clicked something in the GUI window

$msg = GUIGetMsg()

Select

;Check if user clicked on the close button

Case $msg = $GUI_EVENT_CLOSE

;Destroy the GUI including the controls

GUIDelete()

;Exit the script

Exit

;Check if user clicked on the "OK" button

Case $msg = $OK_Btn

MsgBox(64, "New GUI", "You clicked on the OK button!")

;Check if user clicked on the "CANCEL" button

Case $msg = $Cancel_Btn

MsgBox(64, "New GUI", "You clicked on the Cancel button!")

EndSelect

WEnd

Link to comment
Share on other sites

use GUICtrlRead to get what you typed in the editbox and then FileWrite to write it in a text file or whatever

and your global vars is useless, just use GUICreate("New GUI", 300, 250) to save some lines :)

Edited by Pain
Link to comment
Share on other sites

Example:

#include <GuiConstants.au3>

$hGUI = GUICreate("Test", 300, 200)

$hEdit = GUICtrlCreateEdit("Hello world", 10, 10, 280, 150)

$SaveButton = GUICtrlCreateButton("Save", 10, 170, 75, 23)

GUISetState()

$hFile = FileOpen("c:\test.txt", 128 + 1)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $SaveButton
            $read = GUICtrlRead($hEdit)
            If $read <> "" Then
                FileWrite($hFile, $read & @CR)
            EndIf
    EndSwitch
WEnd

FileClose($hFile)
ShellExecute("c:\test.txt")
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...