Jump to content

Autoit Tutorial #1


McGod
 Share

Recommended Posts

My first (but hopefully not last) Autoit tutorial! Today we will be doing the basics of autoit. We will be using today

  • Variables
  • If Statement
  • Inputbox Function
  • MsgBox Function
  • Exit Function
  • Basic syntax
This script will ask for your name, they say hello!

So we need to start off by declaring a variable. There are three different scopes you can use to declare a variable: Global, Dim and Local. Global scope is used when you wish to use your variable throughout the script. You could use this for such things as names. So instead of having to type in the name of your script everywhere, you use type in your variable. Dim is usually used for declaring the variable before using it. Local is used mostly in functions when you wish to have a temporary variable. When you declare a Local variable within a function, it will automatically be destroyed when the function ends. By the way, you can tell variables because they have a $ infront of the variable name!

Couple Examples:

Global $autoit = "Rocks"
Local $tutorial = 1
Dim $vari
oÝ÷ Ù*-¡· z.­Ê{*.Â)eºÇ)¬r^~íëÚ®&殶­s`¤FÒb33c¶æÖP oÝ÷ Øé,¢z0Ê ¢Ö¯j¸nWyÉZ­çezÛ)ºÛ(çZµ¨§¶«{}Ò£§£«z
"hºÇ¨º»Þ¯'â®Ë_ºw-È­R¢Z()àjÚ.®Úî²Ü¡jwrè{¬yëajÛaz·­ëp¢wuçij¶¦z׫³}î®oÝ÷ Ù.­æ¥'hmçjYmêZ­©µê춫{^Ø^­ëmçè­ëaz«jg­z¸­æ§²+ljz)¶*'jZZ­©µêÒ£§yçm¢ë"zn´1z.­ÊzÊ0zwvÚv+hº»Ú®&æòi×bazö«¦å{­Ø^z«Ë"v®¶­s`¤FÒb33c¶æÖP¢b33c¶æÖRÒçWD&÷gV÷Cµ÷W"æÖRgV÷C²ÂgV÷CµvB2÷W"æÖSògV÷C²oÝ÷ Ø2¢çÇ!ûa{'§µêÞvz-)à{axéºÐhÆØ^¤É-é¨}ý÷jëh×6
Dim $name
$name = InputBox ( "Your name", "What is your name?" )
If $name = "" Then
MsgBox ( 1, "Error", "You did not enter a name!" )
Exit
oÝ÷ Úêå

Thats pretty much it, if you have trouble understanding just PM me ill be happy to explain.

(WASNT SURE WERE TO POST)

Edited by Chip
Link to comment
Share on other sites

Global scope is used when you wish to use your variable without the script. You could use this for such things as names. So instead of having to type in the name of your script everywhere, you use type in your variable.

Did you mean throughout?

I know what you meant but it just sounds wrong IMHO!

Edited by ChrisL
Link to comment
Share on other sites

Did you mean throughout?

I know what you meant but it just sounds wrong IMHO!

TY, I didn't notice that :">

Link to comment
Share on other sites

So we need to start off by declaring a variable. There are three different scopes you can use to declare a variable: Global, Dim and Local. Global scope is used when you wish to use your variable throughout the script. You could use this for such things as names. So instead of having to type in the name of your script everywhere, you use type in your variable. Dim is usually used for declaring the variable before using it. Local is used mostly in functions when you wish to have a temporary variable. When you declare a Local variable within a function, it will automatically be destroyed when the function ends. By the way, you can tell variables because they have a $ infront of the variable name!

Nice effort on the tutorial. :whistle:

I am concerned of your understanding of declaration keywords as to the scope that they use on variables. I have done some modification to your above paragraph that I understand as correct. I made smaller paragraphs to make it easier to read.

So we need to start off by declaring a variable. There are three different keywords you can use to declare a variable: Global, Dim and Local. There are two scopes: Global scope and Local scope. Global variables use Global scope and the variables are seen anywhere within the script. Local declared variables use Local scope and are seen only within the functions that they were declared within.

The Global keyword is used when you want to use your variable anywhere within the script. You could use this for such things as names. Instead of typing in the name of your script anywhere, you can use the Global variable instead.

The Dim keyword is used within functions for conditionally declaring the variable as Global if the variable is already declared Global, else the Dim keyword declares the variable as Local.

The Local keyword is used in functions when you wish to have a variable seen only within the function. A Local variable within a function will automatically be destroyed when the function returns.

By the way, you can tell of which are variables because they have a $ symbol infront of the variable name.

As for the conditional scope that the Dim keyword uses, then I would highly recommend using Global or Local, and only use Dim if the script can handle the scope that it may use. Edited by MHz
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...