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

    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next