dragonheard Posted November 27, 2013 Share Posted November 27, 2013 (edited) Hello, so i made this script: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("notepad by g3mini", 501, 501, 258, 127, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 500, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 500, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Form1 Case $Form1 Case $Form1 Case $Form1 Case $Input1 $name = GUICtrlRead ($Input1) case $edit $text = GUICtrlRead ($edit) $read = FileRead($name) if FileExists($name) then FileDelete($name) EndIf FileWrite($name,$text) EndSwitch WEnd what i want to do is that whenever $name allready exists it shows the text inside the file. i figured i could probably do this with putting the $read (line 25) inside the $edit (line 5, instead of the "") but it gives me an error that $read is not declared yet. is there any way to make it read the variable $read without flipping the whole script upsidedown? ps: what the script does is exactly what notepad would but instead it saves every change you make (when i type anything it instantly saves it so that if my laptop/pc crashes it's saved.) ps2: it works allready but i just can't re-open files. if anyone could teach me any other way of re-opening a file it would be greatfully appreciated. thanks, dh Edited November 27, 2013 by dragonheard Link to comment Share on other sites More sharing options...
l3ill Posted November 27, 2013 Share Posted November 27, 2013 Hi dragonheard, Have a look at FileRead & FileWrite to save your data like you are suggesting. Still going to be saved to Notepad though. And to save variable between uses have a look at the INI functions very close to the other 2 in the helpfile. very straightforward stuff... Bill p.s. you posted in developer chat... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2013 Moderators Share Posted November 27, 2013 dragonheard, when i type anything it instantly saves itBe very careful - what you have just defined is basically a "keylogger". I realise that this is not your original intention, but I would ask you to take great care in how you code this script. Reading and saving the content of the edit when it changes is fine (search the forum for scripts dealing with the $EN_CHANGE message to see how to detect changes) but do not even think of looking for and saving actual keypresses. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted November 27, 2013 Share Posted November 27, 2013 It's a very disk intensive method to use also. If I type 100 words a minute, I'd not appreciate all those disk operations. I'd suggest AdlibRegister to check if the control is active and has changed, then save. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
dragonheard Posted November 27, 2013 Author Share Posted November 27, 2013 dragonheard, Be very careful - what you have just defined is basically a "keylogger". I realise that this is not your original intention, but I would ask you to take great care in how you code this script. Reading and saving the content of the edit when it changes is fine (search the forum for scripts dealing with the $EN_CHANGE message to see how to detect changes) but do not even think of looking for and saving actual keypresses. M23 i 'm sorry hahaha it does not record keypresses all it does is act like a notepad wich saves whenever any change is made. It's a very disk intensive method to use also. If I type 100 words a minute, I'd not appreciate all those disk operations. I'd suggest AdlibRegister to check if the control is active and has changed, then save. it checks if a change is made & then saves it due to the case function and if i make it wait till i stop typing it kind of kills the idea behind it. Hi dragonheard, Have a look at FileRead & FileWrite to save your data like you are suggesting. Still going to be saved to Notepad though. And to save variable between uses have a look at the INI functions very close to the other 2 in the helpfile. very straightforward stuff... Bill p.s. you posted in developer chat... thanks although i want it to show up in the textbox in the program itself & i don't know where else to post it? thanks everyone , dh Link to comment Share on other sites More sharing options...
l3ill Posted November 27, 2013 Share Posted November 27, 2013 This should get you started, only the text save part works but you can see how and implement the same logic to write your title to an INI file as suggested. Very basic....no bells and or whistle's #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("notepad by g3mini", 501, 501, 258, 127, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 500, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 500, 21) GUISetState(@SW_SHOW) Local $saveText = FileOpen("saved.txt", 1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $edit $text = GUICtrlRead ($edit) FileWrite($saveText,$text) EndSwitch WEnd My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
AZJIO Posted November 27, 2013 Share Posted November 27, 2013 Notepad (example) 1. You need to have the flag modification 2. Set the time interval between saves. If both triggers are allowed to save, then do it. Allow the user to select. Perhaps a person has a UPS unit, and to pull a head of a hard disk once again will manage more expensively. My other projects or all Link to comment Share on other sites More sharing options...
dragonheard Posted December 2, 2013 Author Share Posted December 2, 2013 i think i should be describing it more as a live editor there are some websites that allow this that you can even open 1 file with multiple users and instantly see what changes are being made. This should get you started, only the text save part works but you can see how and implement the same logic to write your title to an INI file as suggested. Very basic....no bells and or whistle's #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("notepad by g3mini", 501, 501, 258, 127, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 500, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 500, 21) GUISetState(@SW_SHOW) Local $saveText = FileOpen("saved.txt", 1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $edit $text = GUICtrlRead ($edit) FileWrite($saveText,$text) EndSwitch WEnd the reason why i make it delete the file first is because i haven't found a command which empties a file first. if i don't do so it will paste the whole text whenever a change is made behind the existing text. example: i type hi it says: hi but when i delete hi and type bla after it says: hibla because it just pasts it behind the text allready there. i've tried a if fileeists $name thing, it detects the file but it does not show it's content inside the edit box which is what i'm trying to accomplish. thanks for the help , dh Link to comment Share on other sites More sharing options...
l3ill Posted December 2, 2013 Share Posted December 2, 2013 (edited) You can change the Parameters in the FilOpen command to overwrite instead of append ;-) Local $saveText = FileOpen("saved.txt", 2) ; $FO_OVERWRITE (2) = Write mode (erase previous contents) Edited December 2, 2013 by billo My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
dragonheard Posted December 4, 2013 Author Share Posted December 4, 2013 thanks i might try that, but i still have not found a way to make it show the content in a file if said file already exists Link to comment Share on other sites More sharing options...
l3ill Posted December 4, 2013 Share Posted December 4, 2013 (edited) thanks i might try that, but i still have not found a way to make it show the content in a file if said file already exists File open uses the file that already exists unless it doesnt exixt and then it creates it. Is that what you mean? Par 4 The file handle must be closed with the FileClose() function. A file may fail to open due to access rights or attributes. The default mode when writing text is ANSI - use the unicode flags to change this. When writing unicode files the Windows default mode (and the fastest in AutoIt due to the least conversion) is UTF16 Little Endian (mode 32). >>>>>Opening a file in write mode creates the file if it does not exist. Directories are not created unless the correct flag is used. When reading and writing via the same file handle, the FileSetPos() function must be used to update the current file position. A file can be read as binary (byte) data by using FileOpen() with the binary flag. Edited December 4, 2013 by billo My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
dragonheard Posted December 9, 2013 Author Share Posted December 9, 2013 thanks billo for the help , i did get it to open it but i want it to show the content of opened file in the GUI not just open it. Link to comment Share on other sites More sharing options...
JohnOne Posted December 9, 2013 Share Posted December 9, 2013 if FileExists($name) then GUICtrlSetData($edit, FileRead($name)) FileDelete($name) EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
dragonheard Posted December 10, 2013 Author Share Posted December 10, 2013 if FileExists($name) then GUICtrlSetData($edit, FileRead($name)) FileDelete($name) EndIf thanks i will try that & tell if it works or not Link to comment Share on other sites More sharing options...
dragonheard Posted December 11, 2013 Author Share Posted December 11, 2013 that did not work, it does open the file i think but it still does not show any content it just overwrites everything without showing it's content first. here's the code at this moment: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("notepad by g3mini", 750, 375, 258, 127, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 750, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 750, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Form1 Case $Form1 Case $Form1 Case $Form1 Case $Input1 $name = GUICtrlRead ($Input1) case $edit $text = GUICtrlRead ($edit) $read = FileRead($name) if FileExists($name) then GUICtrlSetData($edit, FileRead($name)) FileDelete($name) EndIf FileWrite($name,$text) EndSwitch WEnd Link to comment Share on other sites More sharing options...
l3ill Posted December 11, 2013 Share Posted December 11, 2013 You cant have both You can change the Parameters in the FilOpen command to overwrite instead of append ;-) Local $saveText = FileOpen("saved.txt", 2) ; $FO_OVERWRITE (2) = Write mode (erase previous contents) Its either going to append or overwrite. if you want something to show up with Johns code you will have to use append. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
dragonheard Posted December 18, 2013 Author Share Posted December 18, 2013 You cant have both Its either going to append or overwrite. if you want something to show up with Johns code you will have to use append. I'm sorry, you kinda lost me there: how do i put John's code and that code together? Link to comment Share on other sites More sharing options...
JohnOne Posted December 18, 2013 Share Posted December 18, 2013 (edited) Here is a dirty solution. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $Form1 = GUICreate("notepad by g3mini", 750, 375, 258, 127, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 750, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 750, 21) $Dummy = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [["{SPACE}", $Dummy]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) $null = 0 $name = '' While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Input1 $name = GUICtrlRead($Input1) Case $Dummy If _WinAPI_GetFocus() = GUICtrlGetHandle($edit) Then GUISetAccelerators($null) Send("{SPACE}") GUISetAccelerators($aAccelKeys) _Work() EndIf EndSwitch WEnd Func _Work() $hFile = FileOpen($name, 2) FileWrite($hFile, GUICtrlRead($edit)) FileClose($hFile) ConsoleWrite(FileRead($name) & @LF) EndFunc ;==>_Work When you enter the target filename, you must press enter key for $Input1 to register. EDIT: Forgot to mention, this will save the edit control to disk, each time the space bar is pressed, so most every word, not letter. Edited December 18, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
l3ill Posted December 18, 2013 Share Posted December 18, 2013 (edited) I'm sorry, you kinda lost me there: how do i put John's code and that code together? Append - will always just add whatever you write to the end of whatever you wrote before like a diary or a ledger. And you can set it up so what you wrote last time is visible when you open your script see post # 13 Overwrite will gve you a fresh clean empty notepad everytime you openFile anewed. From what I understand you are going for the diary/ledger, or? Bill Edited December 18, 2013 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
dragonheard Posted January 12, 2014 Author Share Posted January 12, 2014 sorry it took me so long to reply i was busy for a while, Here is a dirty solution. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $Form1 = GUICreate("notepad by g3mini", 750, 375, 258, 127, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP)) $edit = GUICtrlCreateEdit("", 0, 24, 750, 476) GUICtrlSetFont(-1, 12, 400, 0, "arial") $Input1 = GUICtrlCreateInput("Filename here.", 0, 0, 750, 21) $Dummy = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [["{SPACE}", $Dummy]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) $null = 0 $name = '' While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Input1 $name = GUICtrlRead($Input1) Case $Dummy If _WinAPI_GetFocus() = GUICtrlGetHandle($edit) Then GUISetAccelerators($null) Send("{SPACE}") GUISetAccelerators($aAccelKeys) _Work() EndIf EndSwitch WEnd Func _Work() $hFile = FileOpen($name, 2) FileWrite($hFile, GUICtrlRead($edit)) FileClose($hFile) ConsoleWrite(FileRead($name) & @LF) EndFunc ;==>_Work When you enter the target filename, you must press enter key for $Input1 to register. EDIT: Forgot to mention, this will save the edit control to disk, each time the space bar is pressed, so most every word, not letter. i tried to add this, it does not show the previous content in the gui itself , thanks for the idea of making is save on each time a space is being sent though might make that a permanent. Append - will always just add whatever you write to the end of whatever you wrote before like a diary or a ledger. And you can set it up so what you wrote last time is visible when you open your script see post # 13 Overwrite will gve you a fresh clean empty notepad everytime you openFile anewed. From what I understand you are going for the diary/ledger, or? Bill that's correct; what i want it to do is save any change being made to the text and whenever filename allready exists to view it's content inside the editbox thanks, dh Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now