Sign in to follow this  
Followers 0
n4n0

Understanding of AutoIt variables

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks a lot for the answers!

Also, how do you insert a script like this?

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0