Jump to content
Sign in to follow this  
minxomat

StringAPL UDF - Powerful calculations, Minimal code

Recommended Posts

minxomat

Hi there.

 

Abstract

 

This UDF enables the use of all reference APL features in AutoIt. Is uses the original APL symbols. The code is interpreted via a sandbox ngn-apl interface which relies on JavaScript. Execution is done via IE objects.

 

What's APL?

 

APL is a formal, imperative language. Because it is imperative, a sentence may be called an instruction, and may be executed to produce a result. StringAPL() has one main parameter, which is the APL source code. Thus:

 

 

StringAPL("2×(3+4)") = "14"

Unlike traditionally structured programming languages, code in APL is typically structured as chains of monadic or dyadic functions and operators acting on arrays. As APL has many nonstandard primitives (functions and operators, indicated by a single symbol or a combination of a few symbols), it does not have function or operator precedence.

 

The APL environment is called a workspace. In a workspace the user can define programs and data, i.e. the data values exist also outside the programs, and the user can manipulate the data without the necessity to define a program. For example,

 

 

StringAPL("N ← 4 5 6 7")

will initialize a vector "N" containing 4 elements according to the command. After each StringAPL call, the workspace is deleted completely, so you have to use multi-instructions if you want to reuse macros, functions or variables. Now that we have "N" we can manipulate it. Here's just a small example, you can do much more with APL (later more):

 

 

N+4

Will perform an addition. Every element in N is increased by (int)4. Easy, at least for now ;-)

 

What's possible?

 

Everything. If you feel like it, just draw a mandelbrot fractal using only one line 'o code. Or solve the n-Queen problem, or determine the first hundred prime numbers, or parse a html file. APL is like RegEx on crack. Some really advanced examples are included within the example file.

 

Now, why isn't APL more popular?

 

Because it uses a very, very strange charset. In fact, you have to install the APL Unicode font (https://sites.google.com/site/baavector/fonts) and set SciTe to use this font (CTRL+1 -> Change Monospace Font), before you can even view the examples! In addition to that, you scripts have to be UTF8 BOM encoded, which in return causes Au3Check to crash whenever custom includes are used. I'm planning on replacing the APL chrs with hum-readable english commands, but that may take some time :-)

 

Just look at the mandelbrot drawing code, it's absolutely ridiculous!:

apltestb773.png

 

I'd call it abstract art :D .

 

Examples

 

There are a few examples included. For the basic stuff please visit the Wikipedia APL page und Wikipedia APL reference:

 

examplese923.png

 

Remarks

 

Please do not use the second parameter yet, it is unfinished and experimental. Also, to use multiline-code, use . in-command to start a new line, just like the examples.

 

Download

 

Example file (INSTALL APL FONT AND ENCODE UTF8BOM!!!)

UDF (doesn't need any special treatment, doesn't contain APL chrs)

https://github.com/Perseus-Developers/StringAPL

 

Does not work in 3.3.9.5. Developed in 3.3.8.1. No further testing, please report bugs only if they occur in a stable version.

Edited by minx
  • Like 1

I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites
jchd

Very nice!

You have all APL specific characters in the DejaVu Sans Mono (it is perfect for most fixed-pitch uses, e.g. editors).

  • Like 1

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
mLipok

I just reading about APL

here is some intresting links:

http://forum.apl2000.com/viewtopic.php?f=28&t=942

edit:

http://www.chilton.com/~jimw/setgame.html

edit2:

btw. works on 3.3.10.2 and 3.3.13.19

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
minxomat

Is that font really certified? I didn't try every single one, but most of them seem to have problems with some characters (such as downstile etc.). But if it works: great!

@mLipok Great tutorial here, too: http://www.jsoftware.com/papers/APLDictionary1.htm , also features a great reference.

Edited by minx

I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites
jchd

One of my first freelance projects was on an IBM 5120 APL... Never worked with APL since but this is a good occasion to start learning the function set again, well if free time permits.

Anyway for those curious enough, this may add significant computing power to AutoIt. I wonder if it would be possible to skip html + IE and launch the .js directly.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jchd

minx,

You're right. There are some functional symbols missing (represented by a thin square), at least in the version I have. I'll try to find a more complete version.

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
minxomat

Yes, you are right, the bottleneck is IE. Actually, you can spot a google.com tag in the code. This is to bypass the ActiveX filter. But the Site still has to go trough that filter. I think a 3rd party JS compiler will do the job.

Sadly, MS' ScriptControl stopped JS support at version 1.2, so this won't work.


I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites
mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
minxomat

It isn't limited to math, though. Also, a short description would seem to be helpful (inline APL interpreter or so).


I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites
jchd

minx,

I believe you should have mentionned "steepest_learning_curve_language_ever" in the keyword list of your post :mad2:

More seriously I checked the DejaVu site and the last snapshot has a version of DejaVu Sans Mono where all APL symbols defined in Unicode are available (and look correct AFAICT). I don't know which subset implemented in apl.js but that font should cover all practical uses.

I downloaded dejavu-fonts-ttf-2.34-20140118-2580.zip and all worked like a charm. I don't have the setup to compile from latest sources but it doesn't make a big difference for me: work in (slow) progress is on fixing kernings, adding ideographs I can't name and details that don't prevent me from sleeping well.

In SciTE I can see all these 70 APL symbols:

02336    ⌶    APL FUNCTIONAL SYMBOL I-BEAM
02337    ⌷    APL FUNCTIONAL SYMBOL SQUISH QUAD
02338    ⌸    APL FUNCTIONAL SYMBOL QUAD EQUAL
02339    ⌹    APL FUNCTIONAL SYMBOL QUAD DIVIDE
0233A    ⌺    APL FUNCTIONAL SYMBOL QUAD DIAMOND
0233B    ⌻    APL FUNCTIONAL SYMBOL QUAD JOT
0233C    ⌼    APL FUNCTIONAL SYMBOL QUAD CIRCLE
0233D    ⌽    APL FUNCTIONAL SYMBOL CIRCLE STILE
0233E    ⌾    APL FUNCTIONAL SYMBOL CIRCLE JOT
0233F    ⌿    APL FUNCTIONAL SYMBOL SLASH BAR
02340    ⍀    APL FUNCTIONAL SYMBOL BACKSLASH BAR
02341    ⍁    APL FUNCTIONAL SYMBOL QUAD SLASH
02342    ⍂    APL FUNCTIONAL SYMBOL QUAD BACKSLASH
02343    ⍃    APL FUNCTIONAL SYMBOL QUAD LESS-THAN
02344    ⍄    APL FUNCTIONAL SYMBOL QUAD GREATER-THAN
02345    ⍅    APL FUNCTIONAL SYMBOL LEFTWARDS VANE
02346    ⍆    APL FUNCTIONAL SYMBOL RIGHTWARDS VANE
02347    ⍇    APL FUNCTIONAL SYMBOL QUAD LEFTWARDS ARROW
02348    ⍈    APL FUNCTIONAL SYMBOL QUAD RIGHTWARDS ARROW
02349    ⍉    APL FUNCTIONAL SYMBOL CIRCLE BACKSLASH
0234A    ⍊    APL FUNCTIONAL SYMBOL DOWN TACK UNDERBAR
0234B    ⍋    APL FUNCTIONAL SYMBOL DELTA STILE
0234C    ⍌    APL FUNCTIONAL SYMBOL QUAD DOWN CARET
0234D    ⍍    APL FUNCTIONAL SYMBOL QUAD DELTA
0234E    ⍎    APL FUNCTIONAL SYMBOL DOWN TACK JOT
0234F    ⍏    APL FUNCTIONAL SYMBOL UPWARDS VANE
02350    ⍐    APL FUNCTIONAL SYMBOL QUAD UPWARDS ARROW
02351    ⍑    APL FUNCTIONAL SYMBOL UP TACK OVERBAR
02352    ⍒    APL FUNCTIONAL SYMBOL DEL STILE
02353    ⍓    APL FUNCTIONAL SYMBOL QUAD UP CARET
02354    ⍔    APL FUNCTIONAL SYMBOL QUAD DEL
02355    ⍕    APL FUNCTIONAL SYMBOL UP TACK JOT
02356    ⍖    APL FUNCTIONAL SYMBOL DOWNWARDS VANE
02357    ⍗    APL FUNCTIONAL SYMBOL QUAD DOWNWARDS ARROW
02358    ⍘    APL FUNCTIONAL SYMBOL QUOTE UNDERBAR
02359    ⍙    APL FUNCTIONAL SYMBOL DELTA UNDERBAR
0235A    ⍚    APL FUNCTIONAL SYMBOL DIAMOND UNDERBAR
0235B    ⍛    APL FUNCTIONAL SYMBOL JOT UNDERBAR
0235C    ⍜    APL FUNCTIONAL SYMBOL CIRCLE UNDERBAR
0235D    ⍝    APL FUNCTIONAL SYMBOL UP SHOE JOT
0235E    ⍞    APL FUNCTIONAL SYMBOL QUOTE QUAD
0235F    ⍟    APL FUNCTIONAL SYMBOL CIRCLE STAR
02360    ⍠    APL FUNCTIONAL SYMBOL QUAD COLON
02361    ⍡    APL FUNCTIONAL SYMBOL UP TACK DIAERESIS
02362    ⍢    APL FUNCTIONAL SYMBOL DEL DIAERESIS
02363    ⍣    APL FUNCTIONAL SYMBOL STAR DIAERESIS
02364    ⍤    APL FUNCTIONAL SYMBOL JOT DIAERESIS
02365    ⍥    APL FUNCTIONAL SYMBOL CIRCLE DIAERESIS
02366    ⍦    APL FUNCTIONAL SYMBOL DOWN SHOE STILE
02367    ⍧    APL FUNCTIONAL SYMBOL LEFT SHOE STILE
02368    ⍨    APL FUNCTIONAL SYMBOL TILDE DIAERESIS
02369    ⍩    APL FUNCTIONAL SYMBOL GREATER-THAN DIAERESIS
0236A    ⍪    APL FUNCTIONAL SYMBOL COMMA BAR
0236B    ⍫    APL FUNCTIONAL SYMBOL DEL TILDE
0236C    ⍬    APL FUNCTIONAL SYMBOL ZILDE
0236D    ⍭    APL FUNCTIONAL SYMBOL STILE TILDE
0236E    ⍮    APL FUNCTIONAL SYMBOL SEMICOLON UNDERBAR
0236F    ⍯    APL FUNCTIONAL SYMBOL QUAD NOT EQUAL
02370    ⍰    APL FUNCTIONAL SYMBOL QUAD QUESTION
02371    ⍱    APL FUNCTIONAL SYMBOL DOWN CARET TILDE
02372    ⍲    APL FUNCTIONAL SYMBOL UP CARET TILDE
02373    ⍳    APL FUNCTIONAL SYMBOL IOTA
02374    ⍴    APL FUNCTIONAL SYMBOL RHO
02375    ⍵    APL FUNCTIONAL SYMBOL OMEGA
02376    ⍶    APL FUNCTIONAL SYMBOL ALPHA UNDERBAR
02377    ⍷    APL FUNCTIONAL SYMBOL EPSILON UNDERBAR
02378    ⍸    APL FUNCTIONAL SYMBOL IOTA UNDERBAR
02379    ⍹    APL FUNCTIONAL SYMBOL OMEGA UNDERBAR
0237A    ⍺    APL FUNCTIONAL SYMBOL ALPHA
02395    ⎕    APL FUNCTIONAL SYMBOL QUAD
 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
minxomat

Then why bother downloading another font, when there is a more official fully-APL compatible font which is linked in the first post? I can't quite follow your logic there. For the testing of the symbols, just C&P the JSoftware Page I've linked (the last three tables contain the reference) and see if everything is the same. It is for the APL Unicode font (as expected).


I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites
jchd

Because the APL fonts is not a good generic programming font and it doesn't contains characters for languages other than limited Latin, limited Greek and limited Cyrillic. It lacks diacritics, modifying letters, way too many symbols and much more. I don't want to have to switch fonts in SciTE so I prefer a "one size fits all" solution.

The advantage of DejaVu Sans Mono is that many of its glyphs have been specifically designed for programming, albeit I agree that APL functionnal symbols are much better rendered in APL385 than elsewhere.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

  • Similar Content

    • PuneetTewani
      By PuneetTewani
      Mouse click (using coordinates) not working on NSE NOW software. Works well everywhere else.
    • TheDcoder
      By TheDcoder
      Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start!
      Declaring arrays!
      Declaring arrays is a little different than other variables: 
      ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it
      Resizing Arrays
      Its easy! Just like declaring an empty array! ReDim is our friend here:
      #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program.
      Best practice of using "Enum"
      You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers):
      Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums :
      ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat!
      Looping through an Array
      Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt!
      Simple Way:
      ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way:
      ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro!
      Interpreting Multi-Dimensional Arrays
      Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions...
      Ok, Lets start... You can imagine an array as a (data) mine of information:

      ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy!
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. What are Arrays?
      A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes.
      Q #2. Help! I get an error while declaring an Array!?
      A. You tried to declare an array like this:
      $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work:
      Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array?
      A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound
      Q #4. Why is my For...Next loop throwing an error while processing an Array?
      A.  You might have done something like this:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment:
      #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array?
      A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array:
      ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work!  
      More FAQs coming soon!
    • simonc8
      By simonc8
      I have a script which executes sleep for a couple of hours then carries out instructions. Does the running AutoIt script prevent the computer from entering sleep mode during this time? If not, is there something I can add to the AutoIt script to keep the computer awake?
      Grateful for advice.
    • gahhon
      By gahhon
      Hi,
      I have a program that is read data from the .txt file, since the .txt file is only readable, viewable and editable for the admin user.
      But how could I lock it with password, or some other technique that can helps to achieve this?
      Thanks for the advanced information.
    • gahhon
      By gahhon
      Hi,
      How can I the trigger the another button functions without waiting the previous function to finish execute?
      Any advise?
      I couldn't find any relevant topics via google.
      Thanks a lot.
×