rezz Posted January 13, 2011 Posted January 13, 2011 I'm currently using filewrite to create and write to a text file like a log entry. Notepad is open with the created file displayed. Is there a way to get notepad to refresh itself to show any newly added text that filewrite may have sent?? Right now I am closing and reopening Notepad completely in order to accomplish a refresh. Is there another way?
BrewManNH Posted January 13, 2011 Posted January 13, 2011 Try using an Edit box instead of Notepad and updating it and the file at the same time. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
somdcomputerguy Posted January 13, 2011 Posted January 13, 2011 Notepad ++ has a 'Reload from disk' feature. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
rezz Posted January 13, 2011 Author Posted January 13, 2011 I'll try the edit later and see how that goes. Notepad ++ is not an option at the moment but will keep it in mind. Thanks for the ideas.
Varian Posted January 13, 2011 Posted January 13, 2011 You could try this:Open notepadstart a loop Read contents of file copy contents to clipboard use ControlCommand() with "EditPaste" into the EDIT control of notepadrestart the loop
rezz Posted January 13, 2011 Author Posted January 13, 2011 Thanks Varian. That sounds better than what I'm currently doing. I'll test some combinations this evening. I also thought about using an autoit created text editor in some way but that would bring me back to the original problem again.
BrewManNH Posted January 13, 2011 Posted January 13, 2011 (edited) Here's an example of what I came up with using an Edit control on a GUI. expandcollapse popup#include <Constants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Global $Day, $sFile = "" Global Const $File = @DesktopDir & "\SomeLogFile.txt" Switch @WDAY Case 1 $Day = "Sunday" Case 2 $Day = "Monday" Case 3 $Day = "Tuesday" Case 4 $Day = "Wednesday" Case 5 $Day = "Thursday" Case 6 $Day = "Friday" Case 7 $Day = "Saturday" EndSwitch $GUI = GUICreate($File, 650, 650, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "GUICLOSE") $Edit = GUICtrlCreateEdit("", 10, 10, 630, 630, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) GUICtrlSetFont($Edit, 10, 400, -1, "Courier New") GUISetState() $sFile = "At " & @HOUR & ":" & @MIN & ":" & @SEC & " on " & $Day & " " & @MON & "/" & @MDAY & "/" & @YEAR & @CRLF & @CRLF For $I = 1 To 10 $sFile &= "Line " & $I & " Some information you want placed into the file" & @CRLF $hFile = FileOpen($File, 2) FileWriteLine($hFile, $sFile) GUICtrlSetData($Edit, $sFile) Sleep(2000) Next FileClose($hFile) Func GUICLOSE() Exit EndFunc ;==>GUICLOSE While 1 Sleep(100) WEnd All it does is, in this example, is to create a text file called SomeLogFile.txt on your desktop, and will write a line of text to it every 2 seconds, and will also update the Edit box at the same time. It can be adapted to whatever use you need to do for your log file. I used the FileOpen command using flag 2 to recreate the file every time it loops through otherwise your text file looks kind of funky after a while. I could have just as easily have used a different method of writing text to the file, but this was the quickest way that I thought of at the time. Edited January 13, 2011 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! Reveal hidden contents I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
rezz Posted January 14, 2011 Author Posted January 14, 2011 Thanks everyone. I ended up creating an edit box within the existing GUI. Then used the existing filewrite to create the actual text file. Then used _FileWriteToLine($sTxtFile, 1, $LOGTEXT, 0) $Log = FileRead($sTxtFile) FileClose($sTxtFile) ClipPut($Log) and finally: GUICtrlSetData($TextBox[3], $Log) That displays the log contents in the gui for viewing. Now to figure out if I want to allow editing within the edit field and try to save it back to the text file.....probably not.
rezz Posted January 14, 2011 Author Posted January 14, 2011 It ended up being a hybrid of BrewManNH's edit idea and Varian's Clipput idea. expandcollapse popup#include <GuiConstants.au3> #include<File.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> $sTxtFile = _PathFull("CaseNotes " & @MON & "-" & @MDAY & ".txt") Global $Log Global $sTxtFile Global $LOGTEXT Global $NotesButton[5] Global $Notes[5] Global $TextBox[5] Global $LogFile $hGUI = GUICreate("View Text File in Gui", 720, 432) $hTab = GUICtrlCreateTab(10, 10, 720, 480, BitOR("", $TCS_FIXEDWIDTH)) _GUICtrlTab_SetItemSize($hTab, 75, 17) GUICtrlCreateLabel("Log Viewer", 500, 40, 60, 20) $NotesButton = GUICtrlCreateButton("Notes", 220, 380, 60, 20) $TextBox = GUICtrlCreateEdit("", 420, 60, 300, 300) $Notes = GUICtrlCreateInput("", 20, 270, 290, 100, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL) GUICtrlCreateLabel("This creates the text file in the current working folder and names it CaseNotes " & @MON & "-" & @MDAY & ".txt" & @CRLF & "Clicking on Notes saves the text from the notes field to the text file and displays the text file contents in the Log Viewer", 80, 40, 300, 130) ;GUICtrlCreateTabItem("") ;End of Tab Creation GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $NotesButton CaseNotes() GUICtrlSetData($TextBox, $Log) EndSwitch WEnd Func CaseNotes() If Not FileExists("CaseNotes " & @MON & "-" & @MDAY & ".txt") Then FileOpen("CaseNotes " & @MON & "-" & @MDAY & ".txt", 1) FileClose("CaseNotes " & @MON & "-" & @MDAY & ".txt") EndIf $LOGTEXT = GUICtrlRead($Notes) _FileWriteToLine($sTxtFile, 1, $LOGTEXT, 0) $Log = FileRead($sTxtFile) FileClose($sTxtFile) ClipPut($Log) EndFunc ;==>CaseNotes Thank you all for the help and ideas.
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