Sign in to follow this  
Followers 0
Rickname

Some big questions about au3 syntax ! Must see !

4 posts in this topic

#1 ·  Posted (edited)

Im relative new to this awesome script language and every day Im mindblowed but what things I discover and didn't know about the au3 syntax but I have some questions :

#1. What is ByRef and what it does/why to use it/where to use it :think:

#2. Is this really really true that the first character after the $ sign in the variable name means the type of the variable ??? :shocked: :shocked: ( Like $iVar = int and $sVar = char types from C ? )

What about if I declare $Random instead ? If the above is true, then why all my created programs are working with random names without the correct specific type declared :shocked: ? Like $pink = 5 + 5 does works despite the 'p' representing the pointer type !

#3. Why I need to unregister things or close any handles like DllClose after a DllOpen OR _GDIPlus_Shutdown() after my script exists ?

#4. And last but not the least why this :

#include <Misc.au3>

;Global declarations
;...

Func ()

Func()
; the code
Endfunc

and not this instead :

#include <Misc.au3>

;Global declarations
;...

; the code

Will there be any problems whatsoever if the last variant ?

Edited by Rickname

Share this post


Link to post
Share on other sites



Rickname,

Here we go: :)

ByRef: When you pass parameters to a function you can do it in 2 ways:

- By value (the default) where the function makes a copy of the variable to use and destroys it at then end of the function leaving the original unchanged.

- By reference (ByRefwhere the function is told where the original variable is located. Any changes to this original made by the function remain after the function ends.

If you look at the Variables - using Global, Local and ByRef tutorial in the Wiki, you will see some examples showing this in action.

Letter after the $: You can call your variables whatever you like (as long as you use alphanumeric characters and underscores) but as AutoIt is not a typed language, coders often use the first letter to indicate what type variable is being held in that particular name. My personal usage is:

$a = Array
$b = Binary
$c = ControlID
$f = Boolean flag (True/False)
$h = Handle
$i - Integer number
$m = Menu item
$n = Floating point number
$p = Pointer
$s = String
%t = Struct
$v = Undefined

but you can obviously vary this according to you personal preference. You do not need to do it at all, but experience has shown that it is a good idea.

Tidying up: Autoit is extremely well-behaved and does a lot of housekeeping after a script ends to make sure that most of the mess (such as open handles) is tidied away. However it behoves the careful coder to do as much clearing up as possible within the script - not only is this good practice, but it prepares you for when you move on to less-forgiving languages. In certain cases, such as when you use AutoIt to create very complex items like DLL callbacks and GDI handles, AutoIt will not correctly clear up when it is shut down and it is imperative that the coder tidies up the code. If not the system could become unstable or exhibit memory leaks.

Functions: There are no problems with your second example, although there is with the first! Most of the Help file examples have the code within a function - this is done deliberately to reduce the number of Global variables, which is generally regarded as good coding practice. In longer more complex scripts you will certainly need functions - in small scripts you can often do without.

Does that make it all clearer? Please ask if you have any more (or indeed any supplementary) questions. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Rickname,

Here we go: :)

ByRef: When you pass parameters to a function you can do it in 2 ways:

- By value (the default) where the function makes a copy of the variable to use and destroys it at then end of the function leaving the original unchanged.

- By reference (ByRefwhere the function is told where the original variable is located. Any changes to this original made by the function remain after the function ends.

If you look at the Variables - using Global, Local and ByRef tutorial in the Wiki, you will see some examples showing this in action.

Letter after the $: You can call your variables whatever you like (as long as you use alphanumeric characters and underscores) but as AutoIt is not a typed language, coders often use the first letter to indicate what type variable is being held in that particular name. My personal usage is:

$a = Array
$b = Binary
$c = ControlID
$f = Boolean flag (True/False)
$h = Handle
$i - Integer number
$m = Menu item
$n = Floating point number
$p = Pointer
$s = String
%t = Struct
$v = Undefined

but you can obviously vary this according to you personal preference. You do not need to do it at all, but experience has shown that it is a good idea.

Tidying up: Autoit is extremely well-behaved and does a lot of housekeeping after a script ends to make sure that most of the mess (such as open handles) is tidied away. However it behoves the careful coder to do as much clearing up as possible within the script - not only is this good practice, but it prepares you for when you move on to less-forgiving languages. In certain cases, such as when you use AutoIt to create very complex items like DLL callbacks and GDI handles, AutoIt will not correctly clear up when it is shut down and it is imperative that the coder tidies up the code. If not the system could become unstable or exhibit memory leaks.

Functions: There are no problems with your second example, although there is with the first! Most of the Help file examples have the code within a function - this is done deliberately to reduce the number of Global variables, which is generally regarded as good coding practice. In longer more complex scripts you will certainly need functions - in small scripts you can often do without.

Does that make it all clearer? Please ask if you have any more (or indeed any supplementary) questions. :)

M23

So awesome Melba ! Really awesome thanks alot ! You really explained everything the best and all my problems got resolved ! :)

So ByRef is like the & variable address referance type like in Borland C => very helpful thing in AutoIt !!

Letter after variable is not a must to show what type of data will be saved like you must declare the types in C, so this also awesome because AutoIt will auto-find what type of data is

Tyding up : "If not the system could become unstable or exhibit memory leaks." -> now I understand why is so important :)

Thanks alot ! Very helpful :)

Edited by Rickname

Share this post


Link to post
Share on other sites

Rickname,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. ;)

because AutoIt will auto-find what type of data is

No, AutoIt does not "autofind" anything - it is just an aide-memoire for the coder. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Similar Content

    • Atoxis
      By Atoxis
      Howdy, this is my first post, massive fan of autoit. 
      I've searched and tried and I would just like people who are better at this than me to let me know if this is even a thing.

      I'd like to perform just a variable. For example, it would be. *see inserted code*
      So what i'm wanting is, create the constant $test, and that variable would be what is followed after the = . Then perform the _FileCreate. Then perform the variable.  Logically or in my head rather.. That variable is declared and is equal to what it is set to above, therefore just placing the variable plainly in the script, it should be equal to what it was declared as.  So what am I doing wrong, and or how can I have autoit just perform the variable.  

       
      #include <File.au3> Const $test = FileWriteLine(@DesktopDir & "\Log.txt", @CRLF ) _FileCreate(@DesktopDir & "\Log.txt") $test  
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • ur
      By ur
      I have a script , during compilation and test execution, it worked perfectly but sometimes I am getting error as "Variable used without being declared."
       
      I understood somewhere in the branching logic this is happening.
       
      But not able to find it exactly.
       
      As I am using multiple include statements.the line number is also not giving accurately.
       

       
      Can anyone suggest what is the approach to resolve this?