SjaakTV Posted March 4, 2010 Share Posted March 4, 2010 Hi, I'm new in autoit and i'm trying to make a gui where you can type something in a GUICtrlCreateInput. After you did that you press add and it is added in the notepad file. The functie to write it to the notepad does not work i don't know why and how to fix the add button to to submit the input i can't even imagine how to do that. A bit help would be awesome because i'm trying the learn autoit. Thnx for your time. HotkeySet ("{ESC}", "Stop") Func Stop () Exit 0 EndFunc MENU() Func MENU() GUICreate("Stop spam", 400, 288) GUISetBkColor(0xaaaaaa) GUICtrlCreateLabel((@MON & "/" & @MDAY & "/" & @YEAR), 325, 10) $NewWord = GUICtrlCreateInput("New word",30,50,200,20,1,1) $add = GUICtrlCreateButton("Add", 270, 47, 33) GUISetState(@SW_SHOW) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $NewWord then AddWord() wend GUIDelete() EndFunc Func AddWord() $a = $NewWord $file1 = FileOpen("\test1.txt", 1) FileWriteLine($file1, $a) FileCLose($file1) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2010 Moderators Share Posted March 4, 2010 (edited) SjaakTV,Welcome to the AutoIt forum. A nice try for a first script. I have made a few changes here - take a look and then read why I made them below:expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{ESC}", "Stop") Global $NewWord Func Stop() Exit 0 EndFunc ;==>Stop MENU() Func MENU() GUICreate("Stop spam", 400, 288) GUISetBkColor(0xaaaaaa) GUICtrlCreateLabel((@MON & "/" & @MDAY & "/" & @YEAR), 325, 10) $NewWord = GUICtrlCreateInput("New word", 30, 50, 200, 20, 1, 1) $add = GUICtrlCreateButton("Add", 270, 47, 33) GUISetState(@SW_SHOW) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $add AddWord() EndSwitch WEnd GUIDelete() EndFunc ;==>MENU Func AddWord() $a = GUICtrlRead($NewWord) $file1 = FileOpen("test1.txt", 1) FileWriteLine($file1, $a) FileClose($file1) EndFunc ;==>AddWordThe changes:While...WEnd loop: I added the ability to close the GUI by clicking on the [X] - Windows gives you that option, so you might as well use it! I also changed the message to run the function - you were looking for $NewWord, you need to look for the $add button. I also used a Switch structure - if you have to checkmore than one thing, it is more elegant, easier to maintain and faster than using lots of If statements.AddWord function: You need the content of the Input, so you have to use GUICtrlRead - you were just getting the ControlID. You also had an unneeded "\" in your file name - AutoIt needs you to add "\" to paths quite often but this was not one of the times! Global variables: You need to declare the $NewWord Input as Global so both your functions can see it!I hope that is all clear - please ask if not. As you are just starting with Autoit, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading.I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. M23Edit: Typnig Edited March 4, 2010 by Melba23 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...
SjaakTV Posted March 4, 2010 Author Share Posted March 4, 2010 SjaakTV, Welcome to the AutoIt forum. A nice try for a first script. I have made a few changes here - take a look and then read why I made them below: expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("{ESC}", "Stop") Global $NewWord Func Stop() Exit 0 EndFunc ;==>Stop MENU() Func MENU() GUICreate("Stop spam", 400, 288) GUISetBkColor(0xaaaaaa) GUICtrlCreateLabel((@MON & "/" & @MDAY & "/" & @YEAR), 325, 10) $NewWord = GUICtrlCreateInput("New word", 30, 50, 200, 20, 1, 1) $add = GUICtrlCreateButton("Add", 270, 47, 33) GUISetState(@SW_SHOW) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $add AddWord() EndSwitch WEnd GUIDelete() EndFunc ;==>MENU Func AddWord() $a = GUICtrlRead($NewWord) $file1 = FileOpen("test1.txt", 1) FileWriteLine($file1, $a) FileClose($file1) EndFunc ;==>AddWord The changes: While...WEnd loop: I added the ability to close the GUI by clicking on the [X] - Windows gives you that option, so you might as well use it! I also changed the message to run the function - you were looking for $NewWord, you need to look for the $add button. I also used a Switch structure - if you have to checkmore than one thing, it is more elegant, easier to maintain and faster than using lots of If statements. AddWord function: You need the content of the Input, so you have to use GUICtrlRead - you were just getting the ControlID. You also had an unneeded "\" in your file name - AutoIt needs you to add "\" to paths quite often but this was not one of the times! Global variables: You need to declare the $NewWord Input as Global so both your functions can see it! I hope that is all clear - please ask if not. As you are just starting with Autoit, reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here. There are even video tutorials on YouTube if you prefer watching to reading. I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. M23 Edit: Typnig Thnx man. I now understand it. I'll try some more. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 4, 2010 Moderators Share Posted March 4, 2010 SjaakTV,Glad I could help. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read.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...
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