Ferman Posted October 1, 2012 Share Posted October 1, 2012 (edited) Alright,So I am trying to make an autoit script to create a file and I just looked at the example on the function page for FileWriteLine everything seemed to make since so I added a GUISetOnEvent so that when the "done" button is pressed it will create a file with text in it and it will continue to write the text in it over and over again... I am just trying to get this to work before I do any other stuff.So I used Koda to make the gui real fast (that was the easy part) and I exported it etc and I added the GUISetOnEvent and the function from the FileWriteLine example and it doesn't work.I did get it to work once though but I had to generate the code from Koda with events on everybutton which then left minimize and close useless, so creating a file with text in it worked but closing the application itself didn't which was pretty useless.My question is "How do I make the FileWriteLine actually work?". With this code right now it will not create test.txt with "Line1 Line2 Line3" written in it.expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf $Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193) GUISetBkColor(0xFFFFFF) $website = GUICtrlCreateInput("", 16, 40, 361, 21) GUICtrlSetCursor (-1, 2) $website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17) $done = GUICtrlCreateButton("Done", 304, 160, 73, 33) GUICtrlSetOnEvent($done, "doneClick") $coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20) $directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func doneClick() Local $file = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") FileClose($file) EndFunc Edited October 1, 2012 by Ferman Link to comment Share on other sites More sharing options...
water Posted October 1, 2012 Share Posted October 1, 2012 And the question is? FireFox 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Ferman Posted October 1, 2012 Author Share Posted October 1, 2012 And the question is?My question is "How do I make the FileWriteLine actually work?". With this code right now it will not create test.txt with "Line1 Line2 Line3" written in it......Sorry I was a little flustered when I was writing this post which means I am not very coherent in my typing haha.. Its making me mad. I haven't used autoit in like 2-3 years which means I forgot a lot and I mean I didn't really know much when I used it last. Link to comment Share on other sites More sharing options...
Danyfirex Posted October 1, 2012 Share Posted October 1, 2012 (edited) Use case $done expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3>#Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf $Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193) GUISetBkColor(0xFFFFFF) $website = GUICtrlCreateInput("", 16, 40, 361, 21) GUICtrlSetCursor (-1, 2) $website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17) $done = GUICtrlCreateButton("Done", 304, 160, 73, 33) GUICtrlSetOnEvent($done, "doneClick") $coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20) $directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $done ;the case when you click on botton doneClick() EndSwitch WEnd Func doneClick() Local $file = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") FileClose($file) EndFunc Saludos Edited October 1, 2012 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Ferman Posted October 1, 2012 Author Share Posted October 1, 2012 Use case $done expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3>#Region ### START Koda GUI section ### Form=C:UsersjustinDesktopcreat-vhostvhost-gui.kxf $Form1 = GUICreate("Create a new vHost for localdev", 401, 201, 325, 193) GUISetBkColor(0xFFFFFF) $website = GUICtrlCreateInput("", 16, 40, 361, 21) GUICtrlSetCursor (-1, 2) $website_label = GUICtrlCreateLabel("Website Name ( Do not provide the extension ex. graphtek.com = graphtek )", 16, 16, 364, 17) $done = GUICtrlCreateButton("Done", 304, 160, 73, 33) GUICtrlSetOnEvent($done, "doneClick") $coldfusion = GUICtrlCreateCheckbox("Is this a coldfusion site?", 16, 72, 281, 20) $directory_edit = GUICtrlCreateButton("Edit Directories", 16, 160, 105, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $done ;the case when you click on botton doneClick() EndSwitch WEnd Func doneClick() Local $file = FileOpen("test.txt", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, "Line1") FileWriteLine($file, "Line2" & @CRLF) FileWriteLine($file, "Line3") FileClose($file) EndFunc Saludos IT WORKS!!! Thank you very much! I guess I have some more reading to do. Apparently I didn't think of making a case for $done. Link to comment Share on other sites More sharing options...
FireFox Posted October 1, 2012 Share Posted October 1, 2012 @Ferman Then remove this : GUICtrlSetOnEvent($done, "doneClick") Or add this after includes : Opt("GUIOnEventMode", 1) Br, Firefox. 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