
aleeksunder
Members-
Posts
6 -
Joined
-
Last visited
Content Type
Forums
Downloads
Forum Articles
Events
Everything posted by aleeksunder
-
Thanks, i've noticed that Local $a = [ 0 ] Always works. But does that means that I have to always declare Scope when I assign any array variable?
-
Hello! Can anyone explain what's going on here: ; Initializing an array Local $a = [ 0 ] ; Lately in code I want to assign new array to $a variable $a = [ 1 ] and got this error at compile time ==> Error in expression.: $a = [ 1 ] $a = ^ ERROR What is it and why? And I've mentioned that I can't pass "manual" array to function as parameter: a( [ 0 ] ) Func a( $a ) _ArrayDisplay( $a ) EndFunc still the same error ==> Error in expression.: a( [ 0 ] ) a( ^ ERROR
-
Hello! I've found some not obvious behaivor of RegDelete() function. So If we already have created registry key 'HKEY_LOCAL_MACHINE\SYSTEM\Test' _without_ 'value' in it. RegDelete() will will raise an Error with code = 1 ( according to documentation 1 means - Unable to open requested key ), instead of code = -2 ( unable to delete requested key/value ). This code running under account without administrative right, will return @error = 1 even if 'HKEY_LOCAL_MACHINE\SYSTEM\Test' already existing key and no 'value' in it. $i_regdelete_result = RegDelete( 'HKEY_LOCAL_MACHINE\SYSTEM\Test' , 'value' ) ; = 2 MsgBox( 0 , 'ERROR' , @error ) ; = 1 Maybe this is due to RegDelete() tries to open target key with write access and gets denied. So I thought that this is not so obvious as it can be. And naturally $i_regdelete_result must have 0 in this scenario ( according to documenatation 0 means Special return value of RegDelete when key/value does not exist )
-
Hello! I've just finished a function and decided to share it. Maybe you know some better alternatives or can give some advices to optimize it, since finally it completely blows up my brain Function retruns array of paths that match the entire pattern. You pattern can be wild as you wish. Usage: ; Get <any files and folders that matches *.exe> inside <anydrive> \ <anyfolder that match 'W*nd*s'> \ <anyfolder that match 'Sys'> _ArrayDisplay( GetWildPath( '*:\W*nd*s\Sys*\*.exe' ) ) ; Get <anyfolder that match 'W*nd*s'> inside <anydrive> _ArrayDisplay( GetWildPath( '*:\Wind*s' , $FLTA_FOLDERS ) ) ; If pattern begins with '\' function interprets it as _root_ of a working directory's drive or directory passed as 3rd paramter _ArrayDisplay( GetWildPath( '\*Te*\*34.*t*t*' , $FLTA_FOLDERS ) ) ; If pattern not begins with '\' function interprets it as relative path to working directory or directory passed as 3rd paramter _ArrayDisplay( GetWildPath( '*Te*\*3*.*t*' , $FLTA_FILESFOLDERS , 'D:\' ) ) Function itself, maybe a bit hard-coded but as is: #include-once #include <script\autoit\AutoItConstants.au3> #include <script\autoit\StringConstants.au3> #include <script\autoit\File.au3> #include <script\autoit\Array.au3> Func GetWildPath( $s_pattern , $i_flag = $FLTA_FILESFOLDERS , $s_working_directory = @WorkingDir ) $s_working_directory = StringRegExpReplace( $s_working_directory , '[\\/]+$' , '' ) Local $a_split = StringSplit( $s_pattern , ':' ) If Not @error Then $s_drive = $a_split[1] $s_path = $a_split[2] Else $s_drive = StringSplit( $s_working_directory , ':' )[1] $s_path = $a_split[1] EndIf If $s_drive = '*' Then Local $a_drives = DriveGetDrive( $DT_ALL ) Else Local $a_drives[1] $a_drives[0] = _ArrayAdd( $a_drives , $s_drive & ':' ) EndIf Local $a_result = [] For $i_drive = 1 To $a_drives[0] If StringLeft( $s_path , 1 ) = '\' Or StringLeft( $s_path , 1 ) = '/' Then $s_path_root = StringUpper( $a_drives[ $i_drive ] ) & '\' $s_path_relative = StringTrimLeft( $s_path , 1 ) Else $s_path_root = StringUpper( $a_drives[ $i_drive ] ) & StringSplit( $s_working_directory , ':' )[2] $s_path_relative = $s_path EndIf Local $a_path = StringSplit( $s_path_relative , '\/' ) Local $a_final = [] If $a_path[ 0 ] > 1 Then Local $a_relative = _FileListToArray( $s_path_root , $a_path[ 1 ] , $FLTA_FOLDERS , True ) If Not @error Then For $i_path = 2 To $a_path[ 0 ] If $i_path < $a_path[ 0 ] Then Local $a_relative_result = [] For $i_relative = 1 To $a_relative[ 0 ] Local $a = _FileListToArray( $a_relative[ $i_relative ] , $a_path[ $i_path ] , $FLTA_FOLDERS , True ) If Not @error Then _ArrayConcatenate( $a_relative_result , $a , 1 ) EndIf Next $a_relative_result[0] = UBound( $a_relative_result ) - 1 $a_relative = $a_relative_result Else For $i_relative = 1 To $a_relative[0] Local $a = _FileListToArray( $a_relative[ $i_relative ] , $a_path[ $i_path ] , $i_flag , True ) If Not @error Then _ArrayConcatenate( $a_final , $a , 1 ) EndIf Next $a_final[0] = UBound( $a_final ) - 1 EndIf Next EndIf Else Local $a_final = _FileListToArray( $s_path_root , $a_path[ 1 ] , $i_flag , True ) EndIf _ArrayConcatenate( $a_result , $a_final , 1 ) $a_result[0] = UBound( $a_result ) - 1 Next Return $a_result EndFunc Since I'm new to AutoIt all of your comments and ideas are welcome
-
How to wrap a function with optional parameters?
aleeksunder replied to aleeksunder's topic in Developer General Discussion
Nice! Thanks a lot- 2 replies
-
- autoit
- optional parameter
-
(and 1 more)
Tagged with:
-
Hello! I'm a newbie in AutoIt and want to wrap some internal autoit functions like RegWrite() in way function will display MsgBox with of error happens. I want to wrap because write error handler becomes really annoying when it comes to code, and I have to write the same code after every RegWrite() call and this becomes really ugly. So I just want this: Local $s_key = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' Local $s_value_name = 'value1' Local $s_value_type = 'REG_SZ' Local $value_data = 'data1' RegWrite( $s_key , $s_value_name , $s_value_type, $value_data ) If @error Then MsgBox( $MB_ICONERROR , 'ERROR' , 'Error writing registry:' & @CRLF & 'Key: ' & $s_key & @CRLF & 'Value: ' & $s_value_name & @CRLF & 'Type: ' & $s_value_type & @CRLF & 'Data: ' & $value_data & @CRLF & 'ErrorCode: ' & @error ) EndIf Local $s_key = 'HKEY_CURRENT_USER\Software\MyApp' RegWrite( $s_key ) If @error Then MsgBox( $MB_ICONERROR , 'ERROR' , 'Error writing registry:' & @CRLF & 'Key: ' & $s_key & 'ErrorCode: ' & @error ) EndIf Becomes into this: RegistryWrite( 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control' , 'value1' , 'REG_SZ' , 'data1' ) RegistryWrite( 'HKEY_CURRENT_USER\Software\MyApp' ) Func RegistryWrite( $s_key , $s_value_name = NULL , $s_value_type = NULL , $value_data = NULL ) RegWrite( $s_key , $s_value_name , $s_value_type, $value_data ) If @error Then MsgBox( $MB_ICONERROR , 'ERROR' , 'Error writing registry:' & @CRLF & 'Key: ' & $s_key & @CRLF & 'Value: ' & $s_value_name & @CRLF & 'Type: ' & $s_value_type & @CRLF & 'Data: ' & $value_data & @CRLF & 'ErrorCode: ' & @error ) EndIf EndFunc And I'm just confused how to properly pass the optional parameters to target function as documentation says that NULL can be evaluated as 0 in mathematical expressions. Maybe "Default" or something else is more suitable? I undersand that I can write separate wrappers for each number of arguments or handle each optional argument value and call target function with exact arguments number, but the goal is to keep code as clean and as simple as possible. So i have two questions: 1. What is the _proper_ and maybe universal way to pass optional parameters to wrapped functions? 2. Can I achive the same result without wrapping every function? Maybe some AutoIt execution flags to always popup a error that happens and stop execution?
- 2 replies
-
- autoit
- optional parameter
-
(and 1 more)
Tagged with: