Jump to content
user4157124

Best practice suggestions

Recommended Posts

user4157124

As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?

Some suggestions :

  • Minimize logic in global scope,
  • separate data & settings from logic,
  • use of vertical space,
  • project organization (folder structure, resource- and include file management).

Example (loop variable-naming, minimizing logic in global scope and separation of settings from logic) :

#include <Array.au3>

Global Enum  $RANDOM_RETURNFLOAT, _
             $RANDOM_RETURNINTEGER
Global Enum  $EXITCODE_NONE

Global Const $g_sChar0   = '-'
Global Const $g_sChar1   = '+'
Global Const $g_iAmountX = 10
Global Const $g_iAmountY = $g_iAmountX

Main()

Func Main()
    Local $aArray[$g_iAmountY][$g_iAmountX]

    For $i1 = 0 To $g_iAmountY - 1

        For $i2 = 0 To $g_iAmountX - 1

            $aArray[$i1][$i2] = Random(0, 1, $RANDOM_RETURNINTEGER) ? $g_sChar1 : $g_sChar0

        Next

    Next

    _ArrayDisplay($aArray)
    Exit $EXITCODE_NONE
EndFunc

Example (project organization) :

+ project_folder
  + bak         [backup files]
  + bin         [distributed binaries and dependencies]
  + inc         [non-standard include files]
  + res         [resource files (icons, file+install files, etc.)]
  + usr         [configuration files, databases, etc.]
  - script.au3
  - script.exe

Example (use of vertical space) :

Func _DigitalRoot($iNum)
    Local $sNum = ''
    Local $aNum

    While $iNum > 9

        $sNum = String($iNum)
        $aNum = StringSplit($sNum, '')
        $iNum = 0

        For $i1 = 1 To $aNum[0]

            $iNum += Int($aNum[$i1])

        Next

    WEnd

    Return $iNum
EndFunc

Share this post


Link to post
Share on other sites
argumentum
On 10/6/2017 at 1:18 PM, user4157124 said:

enables SciTE selection-highlighting (requires minimum of 3 characters).

This is true. Thanks for the tip :) 

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

  • Similar Content

    • CarlD
      By CarlD
      Is there a reliable way to ensure that data assigned to variables in a script is overwritten or deleted when the script exits? I have scripts that encrypt/decrypt data and would like to ensure, if possible, that the encryption keys and decrypted data do not stay in memory after the script exits. Thanks.
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


    • ShakeelAhmad
      By ShakeelAhmad
      I've to upload different number of photos online in different assignments. There is a problem that all photos cannot be selected at once to upload. I have to choose and upload photos one by one. For this purpose I have made a script to automate whatever I have to do manually for choosing and uploading photos one by one.
      Please see my script below and check the last "MouseClick" command. This command clicks the button to choose and upload next photo. The problem I'm facing is; the last "MouseClick" works 1 step extra when all photos have been selected and uploaded. I mean if 7 photos are to be uploaded, this command opens the box from where next photo is selected and uploaded then it again opens the box and next photo is choosen and so on.... when last photo is selected and uploaded, this button once again opens the box. When all photos are uploaded, it should not click the button to select next photo. Please suggest how can I resolve this issue.
      #include <AutoItConstants.au3> Sleep(200) HotKeySet("{ESC}","Quit") ;Press ESC key to quit Send("{ALT DOWN}") Send("{TAB}") Send("{ALT UP}") Sleep(200) Local $photos = InputBox("Question", "How many photos to upload?", "#", "", _ - 1, -1, 0, 0) ; How many photos to upload Local $selector = 0 While $photos <> $selector MouseClick("Left", 281, 238, 1) ; mouse click on very first photo in the box. if $selector = 0 Then Send("{ENTER}") ; for selecting very first photo from "open" window. Sleep(800) Else sleep(200) Send("{RIGHT " & $selector & "}") ; for selecting 2nd to onward photos from "open" window. sleep(1000) Send("{ENTER}") sleep(1000) EndIf MouseClick("Left", 495, 198, 1) ; for clicking a button to choose next photo to upload $selector = $selector + 1 WEnd Beep(1500, 300) ; beep when all photos uploaded Exit Regards,
       
      Shakeel
    • Myicq
      By Myicq
      This may be a dumb question.. but my vertical screen space is fairly limited. I don't need (always) to see all the debug output from autoIT compiler, wrapper etc.
      Can I turn this part off: (optionally)
      >"D:\AutoIt3\SciTE\..\AutoIt3.exe" "D:\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\temp\xx.au3" +>11:35:44 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0 Keyboard:00000406 OS:WIN_7/Service Pack 1 CPU:X64 OS:X86 Environment(Language:0406) +> SciTEDir => D:\AutoIt3\SciTE UserDir => C:\Users\XXX\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\XXX\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.12.0) from:D:\AutoIt3 input:D:\temp\XX.au3 +>11:35:44 AU3Check ended.rc:0 >Running:(3.3.12.0):D:\AutoIt3\autoit3.exe "D:\temp\xx.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop  
×