n4n0 Posted May 4, 2014 Share Posted May 4, 2014 Hi! I am pretty new with AutoIt, and wanted to ask help about the script, but managed to make it work myself. I am not sure why it works so I wanted to ask why and how it works as it does. Here's the script: HotKeySet("{PGDN}", "ExitIt") HotKeySet("{PGUP}", "JustAnotherFunc") Func ExitIt() Exit EndFunc $aa = 0 ; Why can't I just use 0 in While ? $bb = 101 ; The start of numbers sent $cc = 300 ; Where the numbers stop after 1-step Run("notepad.exe") WinWaitActive("Untitled - Notepad") Func JustAnotherFunc() While $aa < $cc ; Why and how does it work? Send($bb + 1) ; 1-step spam up to $cc Send("{ENTER}") $bb = $bb + 1 $aa = $bb ; The script continues infinite without this line. Why? WEnd EndFunc While 1 Sleep(100) WEnd Thanks in advance. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 4, 2014 Moderators Share Posted May 4, 2014 See additional comments below: HotKeySet("{PGDN}", "ExitIt") HotKeySet("{PGUP}", "JustAnotherFunc") Func ExitIt() Exit EndFunc $aa = 0 ; Why can't I just use 0 in While ? ***You could, but then it will loop forever*** $bb = 101 ; The start of numbers sent $cc = 300 ; Where the numbers stop after 1-step Run("notepad.exe") WinWaitActive("Untitled - Notepad") Func JustAnotherFunc() While $aa < $cc ;Why and how does it work? ***You are saying, Run this loop as long as $aa is less than $cc*** Send($bb + 1) ; 1-step spam up to $cc Send("{ENTER}") $bb += 1 ;***More compact than $bb = $bb + 1*** $aa = $bb ;The script continues infinite without this line. Why? ***Without this line, the value of $aa (0) never changes, so it will always be less than the value ;of $cc, and the loop never ends. WEnd EndFunc While 1 Sleep(100) WEnd You could also do something like this to shorten things up: HotKeySet("{PGDN}", "ExitIt") HotKeySet("{PGUP}", "JustAnotherFunc") Func ExitIt() Exit EndFunc $bb = 101 $cc = 300 Run("notepad.exe") WinWaitActive("Untitled - Notepad") Func JustAnotherFunc() While $bb < $cc Send($bb) Send("{ENTER}") $bb += 1 WEnd EndFunc While 1 Sleep(100) WEnd "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted May 4, 2014 Share Posted May 4, 2014 Welcome to AutoIt and the forum! To get a better understanding of how variables work in AutoIt I suggest to read the wiki. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
n4n0 Posted May 4, 2014 Author Share Posted May 4, 2014 Thanks a lot for the answers! Also, how do you insert a script like this? Link to comment Share on other sites More sharing options...
water Posted May 4, 2014 Share Posted May 4, 2014 You mean to insert the script into the thread with formatting and colouring? Use the AutoIt icon (the blue A) in the editor and insert your code. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted May 4, 2014 Share Posted May 4, 2014 You mean to insert the script into the thread with formatting and colouring? Use the AutoIt icon (the blue A) in the editor and insert your code. More info >here. "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation 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