Annonyreeder Posted April 6, 2013 Share Posted April 6, 2013 Hi, Im new to AutoID and ive just been messing around with it as im going to be using AutoID for a project. Ive managed to create a GUI with some simple buttons, Im trying to make it so when you click on 'Button1' it will bring up a another window where you can enter some information (This part i have done so far) Im having trouble after this in using the information inputted by the user, is it possible to store this in a string like with C+? Scenario: User is giving a survey and is inputting the information given by the surveyor after hitting 'Go' it should load up the page (ive used Google for testing as im not at work) and then type in the information given earlier. Here is an example of my script. expandcollapse popup#include <GUIConstants.au3> Opt("GuiOnEventMode", 1) GUICreate("Gui", 500, 500) GuiSetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $Button1 = GUICtrlCreateButton ( "Button 1", 5, 5, 100, 200) GUICtrlSetOnEvent(-1, "OKPressed") $Button2 = GUICtrlCreateButton ( "Button 2", 100, 5, 100, 200) GUICtrlSetOnEvent(-1, "OKPressedd") GUISetState() While 1 Sleep(10) WEnd Exit Func OKPressed() ;Startifscruot $gui = GUICreate("Input storecode and Name", 640, 280) $input = GUICtrlCreateInput("Store Code", 10, 10, 620, 20) $edit = GUICtrlCreateEdit("Name", 10, 40, 620, 200) $button = GUICtrlCreateButton("Go", 10, 250, 620, 20) GUICtrlSetOnEvent(-1, "Gopressed") GUISetState(@SW_SHOW) Sleep(2000) ;Endofit EndFunc Func Gopressed() WinActivate("Google - Windows Internet Explorer") MouseMove( 490, 502) MouseClick("left") FilewriteLine($input, GUICtrlRead EndFunc Func OKPressedd() Run("notepad.exe C:\Users\Anthony\Desktop\Startofday\Passwords") sleep(1000) $URL = "www.google.com" $fd = FileOpen(@TEMPDir & "url.url",2) if $fd = -1 Then Exit FileWriteLine($fd,"[InternetShortcut]") FileWriteLine($fd,"URL=" & $URL) FileClose($fd) Run(@comspec & " /c " & chr(34) & @TEMPDir & "url.url" & chr(34)) sleep(5000) WinActivate("Google - Windows Internet Explorer") WinSetState("[ACTIVE]", "", @SW_MAXIMIZE) EndFunc Func SpecialEvents() If @GUI_CTRLID = $GUI_EVENT_CLOSE Then Exit EndFunc Thanks for any assistance. Ant Link to comment Share on other sites More sharing options...
FireFox Posted April 7, 2013 Share Posted April 7, 2013 (edited) Hi, Welcome to the AutoIt forum with a T not a D I don't really understand what you mean, give it a try : expandcollapse popup#include <GUIConstantsEx.au3> #include <FileConstants.au3> Opt("GUIOnEventMode", 1) Global $sWhatever = "" #region GUI Local Const $hGUI = GUICreate("MyGUI") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local Const $iButton1 = GUICtrlCreateButton("Button 1", 5, 5, 100, 200) GUICtrlSetOnEvent($iButton1, "_Button1") Local Const $iButton2 = GUICtrlCreateButton("Button 2", 110, 5, 100, 200) GUICtrlSetOnEvent($iButton2, "_Button2") GUISetState(@SW_SHOW, $hGUI) #endregion #region GUI2 Global Const $hGUI2 = GUICreate("Input storecode and Name", 640, 280) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global Const $iInput = GUICtrlCreateInput("Store Code", 10, 10, 620, 20) Local Const $iEdit = GUICtrlCreateEdit("Name", 10, 40, 620, 200) Local Const $iButtonGo = GUICtrlCreateButton("Go", 10, 250, 620, 20) GUICtrlSetOnEvent($iButtonGo, "_Gopressed") #endregion While 1 Sleep(10) WEnd Func _Gopressed() ;Startifscruot WinActivate("Google - Windows Internet Explorer") MouseMove(490, 502) MouseClick("left") Local Const $sWhatever = GUICtrlRead($iInput) ConsoleWrite("$sWhatever content: " & $sWhatever & @CrLf) ;Endofit EndFunc Func _Button1() GUISetState(@SW_SHOW, $hGUI2) EndFunc Func _Button2() Run("notepad.exe C:\Users\Anthony\Desktop\Startofday\Passwords") Sleep(1000) Local Const $sURL = "www.google.com" Local Const $hfd = FileOpen(@TempDir & "\url.url", $FO_OVERWRITE) If $hfd = -1 Then Exit FileWriteLine($hfd, "[InternetShortcut]") FileWriteLine($hfd, "URL=" & $sURL) FileClose($hfd) Run(@ComSpec & " /c " & Chr(34) & @TempDir & "\url.url" & Chr(34)) Sleep(5000) Local Const $hWnd = WinGetHandle("Google - Windows Internet Explorer") WinActivate($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndFunc Func _Exit() Exit EndFunc If you have any questions please ask Do not forget to read the help file for any function. Br, FireFox. Edited April 7, 2013 by FireFox Link to comment Share on other sites More sharing options...
Annonyreeder Posted April 7, 2013 Author Share Posted April 7, 2013 Hi, Thanks for reply however this isnt quite what i mean, let me give you a new example, After pressing 'Button1' it will open a new window, you then input your Name and Email address and it should then open up notepad and write your name and email address in notepad, however at the moment it just makes notepad active and clicks it, it won't print the information. Hope you understand better now thanks Ant expandcollapse popup#include #include Opt("GUIOnEventMode", 1) Global $sWhatever = "" #region GUI Local Const $hGUI = GUICreate("MyGUI") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Local Const $iButton1 = GUICtrlCreateButton("Button 1", 5, 5, 100, 200) GUICtrlSetOnEvent($iButton1, "_Button1") Local Const $iButton2 = GUICtrlCreateButton("Button 2", 110, 5, 100, 200) GUICtrlSetOnEvent($iButton2, "_Button2") GUISetState(@SW_SHOW, $hGUI) #endregion #region GUI2 Global Const $hGUI2 = GUICreate("Input storecode and Name", 640, 280) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global Const $iInput = GUICtrlCreateInput("Input your Name", 10, 10, 620, 20) Local Const $iEdit = GUICtrlCreateEdit("Input your Email", 10, 40, 620, 20) Local Const $iButtonGo = GUICtrlCreateButton("Go", 10, 250, 620, 20) GUICtrlSetOnEvent($iButtonGo, "_Gopressed") #endregion While 1 Sleep(10) WEnd Func _Gopressed() ;Startifscruot run("notepad.exe") WinActivate("Untitled - Notepad") MouseMove(490, 502) MouseClick("left") Local Const $sWhatever = GUICtrlRead($iInput) ConsoleWrite("First Name: " & $sWhatever & @CrLf) ;Endofit EndFunc Func _Button1() GUISetState(@SW_SHOW, $hGUI2) EndFunc Func _Button2() Run("notepad.exe C:\Users\Anthony\Desktop\Startofday\Passwords") Sleep(1000) Local Const $sURL = "www.google.com" Local Const $hfd = FileOpen(@TempDir & "\url.url", $FO_OVERWRITE) If $hfd = -1 Then Exit FileWriteLine($hfd, "[InternetShortcut]") FileWriteLine($hfd, "URL=" & $sURL) FileClose($hfd) Run(@ComSpec & " /c " & Chr(34) & @TempDir & "\url.url" & Chr(34)) Sleep(5000) Local Const $hWnd = WinGetHandle("Google - Windows Internet Explorer") WinActivate($hWnd) WinSetState($hWnd, "", @SW_MAXIMIZE) EndFunc Func _Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2013 Moderators Share Posted April 7, 2013 Annonyreeder,ConsoleWrite writes to the lower pane of the SciTE window when you run the script - to get your text into Notepad you need to use the Send function. And I would remove all the Const keywords from your script as all those values are actually variables. Const should only be used for fixed values which will never change during the script's life - the value of Pi for example. 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...
Annonyreeder Posted April 7, 2013 Author Share Posted April 7, 2013 (edited) Thanks again for the fast reply, I see what i did wrong now and i feel im 1 step closer to achieving my goal, for some reason it won't let me insert autoit code on my work machine some sort of javaerror. How can i actually send the input data? Func OKPressed() ;Creates the GUI for form (Incomplete) $gui = GUICreate("Input storecode and Name", 640, 280) $input = GUICtrlCreateInput("Store Code", 10, 10, 620, 20) $edit = GUICtrlCreateEdit("Name", 10, 40, 620, 20) $button = GUICtrlCreateButton("Go", 10, 250, 620, 20) GUICtrlSetOnEvent(-1, "Gopressed") GUISetState(@SW_SHOW) Sleep(5000) ;Endofit EndFunc Func Gopressed() run("Notepad.exe") sleep(500) controlsend($input) EndFunc Edited April 7, 2013 by Annonyreeder Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2013 Moderators Share Posted April 7, 2013 Annonyreeder,Use GUICtrlRead to read the content of the input and use that as the argumane to ControlSend - rather then using its ControlID. As a beginner to AutoIt (as we all were at one point ) might I suggest reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) as this will help you enormously. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). I know you want to start coding NOW, but a little study will save you a lot of trouble - and us a lot of wear and tear on the typing finger(s). 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...
FireFox Posted April 7, 2013 Share Posted April 7, 2013 @Melba23 What's wrong with the constants in my snippet ? Even it's "variables", they should not be changed. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2013 Moderators Share Posted April 7, 2013 FireFox,I agree that the values will not change in this instance - however using Const as you did in that script would in my opinion not be considered good practice. Use of the Const keyword should be reserved for cases where the value is a true "constant" - as I indicated. Try creating a second child GUI here:#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Child", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton _Child() EndSwitch WEnd Func _Child() Global Const $hChild = GUICreate("Child", 200, 200) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hChild) Return EndSwitch WEnd EndFuncFeel free to use Const in that manner in your own scripts, but I would ask that you do not do so when responding to new members as it is very ikely to cause problems later on when they use it unnecessarily. 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...
FireFox Posted April 7, 2013 Share Posted April 7, 2013 (edited) Try creating a second child GUI hereNot needed, I know what will happend. That's why I created the GUI before.I would ask that you do not do so when responding to new members as it is very ikely to cause problems later on when they use it unnecessarily. I understand, it's not appropriate to new members as the script gets too much complicated for nothing.Edit: I never declare a Global variable in a function (moreover a Global Const), don't try to trap me Edited April 7, 2013 by FireFox Link to comment Share on other sites More sharing options...
Annonyreeder Posted April 8, 2013 Author Share Posted April 8, 2013 Thanks for your help guys, i have been going through tutorials and help files and guides and it has helped me understand a lot more but i can't find anything specifically for what im looking for, I can find examples of people using CtrlRead in there scripts however although it reads the data it doesn’t seem to utilize it in anyway. If someone could give me an example script of a GUI with a single box for someone to write in, after hitting 'Go' or 'Start' it will write whatever the user wrote in the box in a Notepad file? And i think ill be able to learn it from that. Thanks again you guys are great! Ant. Link to comment Share on other sites More sharing options...
FireFox Posted April 8, 2013 Share Posted April 8, 2013 There is plenty of examples. Another one : expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> Local $hGUI = 0, $iInput = 0, $iBtnGo = 0 $hGUI = GUICreate("MyGUI") $iInput = GUICtrlCreateInput("", 20, 20, 200, 20, $ES_AUTOHSCROLL) $iBtnGo = GUICtrlCreateButton("Go", 20, 50, 100, 22) GUISetState(@SW_SHOW, $hGUI) Local $sInputRead = "", $hWnd = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iBtnGo $sInputRead = GUICtrlRead($iInput) ControlSetText("[CLASS:Notepad]", "", "[CLASS:Edit; INSTANCE:1]", $sInputRead) ;or ;~ ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit; INSTANCE:1]", $sInputRead, 1) ;or ;~ $hWnd = WinGetHandle("[CLASS:Notepad]") ;~ If WinActive($hWnd) = 0 Then ;~ WinActivate($hWnd) ;~ WinWaitActive($hWnd) ;~ EndIf ;~ Send($sInputRead, 1) EndSwitch Sleep(10) WEnd GUIDelete($hGUI) 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