9 posts in this topic
As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?
Some suggestions :
For...To...Step...Next -loop variable-naming like $iN ($i1, $i2, etc.) : conforms to recommended naming convention, identifies level (albeit inverted to ExitLoop and ContinueLoop's convention) and enables SciTE selection-highlighting (requires minimum of 3 characters). 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 $iNum += Int($aNum[$i1]) Next WEnd Return $iNum EndFunc
I need this for a project and I don't find a method for the next problem.
I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
Do you have an idea ?
Thank you for your attention !
I've ported these two functions from PHP to AU3 to work with URLs.
Made them for those who work with libraries like HTTP.au3 (not the one I coded), that needs passing the server domain, path, etc., instead of the full URL.
Grab the lib here.
ParseURL( $sURL )
Parses the URL and splits it into defined parts. Returns an array:
 = Full URL (same as $sURL)  = Protocol (i.e.: http, https, ftp, ws...)  = Domain  = Port (or null if not specified)  = Path (or null if not specified)  = Query string (everything after the ? - or null if not specified) Example:
$aExample = ParseURL("https://google.com:8080/?name=doe") MsgBox(0, "Test", "URL: " & $aExample & @CRLF & _ "Protocol: " & $aExample & @CRLF & _ "Domain: " & $aExample & @CRLF & _ "Port: " & $aExample & @CRLF & _ "Path: " & $aExample & @CRLF & _ "Query string: " & $aExample)
ParseStr( $sStr )
Parses a query string (similar to the  of the previous function) and returns a multidimensional array, where:
 = number of variables found  = ununsed  = key name of the first variable  = first variable value (already URL decoded) [n] = key name of the nth variable [n] = nth variable value (already URL decoded) Example:
include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib _ArrayDisplay(ParseStr("foo=bar&test=lol%20123")) #cs Result is:  = 2  = ununsed  = foo  = bar  = test  = lol 123 #ce Feel free to fork!
It's been a while since I've posted but here is a simple little function I thought I'd share that allows you to keep a script process active for a minimum amount of time.
I use this to ensure the process is active to ensure any TrayTips remain visible. But I'm sure there is far more interesting uses for this.
How it Works
The coder calls the KeepAlive function with the number of seconds he/she wants to ensure the process will remain active for the next n seconds. Let's say you just called the TrayTip function with 15 seconds display time. You might call KeepAlive with 18 seconds to ensure the process stays active for the next 18 seconds. If the process is closed after that, then the process will close normally.
#Region - KeepAlive Functions ;## Function used to ensure the process stays active for the next n seconds. This is useful to ensure ToolTips ect remain visible. #cs - Example TrayTip(@ScriptName, "This Tip will be called just prior to exit of process.", 5) KeepAlive(8) Exit #ce - Example Func KeepAlive($Seconds = 5) Global $KeeyAlive_IsActive = False Global $KeeyAlive_Init = 0 Global $KeeyAlive_Timeout = 0 ;## Check if there is a previously set timer and only set the new value if it is more than the previously set value. If $KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init) < $Seconds * 1000 Then $KeeyAlive_Init = TimerInit() $KeeyAlive_Timeout = $Seconds * 1000 EndIf ;## If the callback is not yet regerister to execute on exit, register it now. If Not $KeeyAlive_IsActive Then $KeeyAlive_IsActive = True OnAutoItExitRegister("__KeepAlive_OnExit") EndIf EndFunc ;## Private On Exit Function used to ensure program remains active for a previously defined number of seconds. Func __KeepAlive_OnExit() ;## If closeing due to Loffoff or shutdown. Allow it without Delay. If @exitMethod > 2 Then Return ;## Check for reasons that process should be clsoed immediatly without delay. If @exitMethod > 2 Or Not IsDeclared("KeeyAlive_IsActive") Or Not IsDeclared("KeeyAlive_Init") Or Not IsDeclared("KeeyAlive_Timeout") Or TimerDiff($KeeyAlive_Init) > $KeeyAlive_Timeout Then Return ;## Pause Process for the time remaining. ConsoleWrite("Keeping Alive for " & Int($KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init)) & "ms" & @CRLF) Sleep($KeeyAlive_Timeout - TimerDiff($KeeyAlive_Init)) EndFunc #EndRegion Enjoy!
I just thought of this... Do Constants and Variables have any differences other than Constants cannot be changed? I know that Python does not have such things like Constants... But is there a difference between them? any advantages when using Constants whenever we can?
The uses of Constants which I have discovered so far are:
Coding practices (You know what things are not supposed to be changed while the program is running). Preventing code from modifying their value. So, is there anything more than what meets the eye? I think the developers of AutoIt can answer this question.