Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/02/2022 in all areas

  1. Yes we can Unfortunately, the Jscript function you provided in your last post gave bad timers on my antique computer. Please everybody, be nice and don't ask why I'm not changing my computer for a more recent one. I don't want to start a debate on the usefulness of doing it when the end of life is nearly knocking at my door, thank you. Back to your script, this is how I tested it, after commenting your __Example1() and adding an __Example2() + Func _Generate_All() #cs #include <Array.au3> __Example1() Func __Example1() ; Local $arry[][] = [['D0',4,'D2'],['F0',6,'F2'],['A0',1,'A2'],['E0',5,'E2'],['C0',3,'C2'],['B0',2,'B2']] Local $arry[][] = [['D0',6,'DD2'],['F0',4,'FF2'],['A0',1,'A2'],['E0',5,'E2'],['C0',3,'C2'],['B0',2,'B2']] _ArrayDisplay($arry, "UNsorted") Local $hTimer1 = TimerInit() ; Local $x_Result = __ArraySortJs($arry, 1) ; sort on col 1 (Jugador) Local $x_Result = __ArraySortJs($arry, 0, False) ; sort on col 0, not numeric If @error Then Exit Msgbox(0, "__ArraySortJs", "error " & @error) ConsoleWrite("time = " & TimerDiff($hTimer1) & @CRLF) _ArrayDisplay($x_Result, "sorted") EndFunc #ce #include <Array.au3> #include "RandomArray.au3" ; LarsJ Opt("MustDeclareVars", 1) Global $g_iRows = 1000, $g_iCols = 6, $g_aArray __Example2() Func __Example2() _Generate_All($g_aArray) _ArrayDisplay($g_aArray, "UNsorted", Default, Default, Default, _ "Strings|Integers*|Floats*|Dates*|Times*|R/C*") Local $hTimer2 = TimerInit() Local $x_Result2 = __ArraySortJs($g_aArray, 0, False) ; sort on col 0, not numeric If @error Then Exit Msgbox(0, "__ArraySortJs", "error " & @error) ConsoleWrite("JScript: sorted in = " & Int(TimerDiff($htimer2)) & " ms" & @crlf) _ArrayDisplay($x_Result2, "sorted", Default, Default, Default, _ "Strings|Integers*|Floats*|Dates*|Times*|R/C*") EndFunc ;=========================================== Func _Generate_All(ByRef $g_aArray) ; LarsJ ConsoleWrite("$g_iRows = " & $g_iRows & " $g_iCols = " & $g_iCols & @CRLF) $g_aArray = FAS_Random2DArrayAu3($g_iRows, "sifdtr", "abcdefghijklmnopqrstuvwxyz") EndFunc ;==>_Generate_All ; #FUNCTION# ============================================================================= ; Name...........: __ArraySortJs ; ======================================================================================== Func __ArraySortJs($o_array, $o_Column = 0, $o_Numeric = True, $o_ascending = True) ;==== If Not IsArray($o_array) Then Return SetError(1, 0, -1) If (UBound($o_array, 2) = 1) And ($o_Column > 0) Then Return SetError(1, 0, -1) If (UBound($o_array, 2) > 1) And ($o_Column > UBound($o_array, 2) - 1) Then Return SetError(1, 0, -1) ;==== ;==== Local $o_CBlock = 'function GetArray(arr){' & @CRLF & _ 'var oArray = new VBArray(arr)' & @CRLF & _ 'return oArray.toArray()' & @CRLF & _ '}' & @CRLF & _ @CRLF & _ 'function NumSort(a, b){' & @CRLF & _ 'if (a === b) {' & @CRLF & _ 'return 0' & @CRLF & _ '}' & @CRLF & _ 'else {' & @CRLF & _ 'return (a < b) ? -1 : 1' & @CRLF & _ '}' & @CRLF & _ '}' & @CRLF & _ @CRLF & _ 'function ArraySorting(arr, oNumeric, oascending){' & @CRLF & _ 'var JsArray = GetArray(arr)' & @CRLF & _ 'if (oNumeric) {' & @CRLF & _ 'JsArray.sort(NumSort)' & @CRLF & _ '}' & @CRLF & _ 'else {' & @CRLF & _ 'JsArray.sort()' & @CRLF & _ '}' & @CRLF & _ 'if (oascending) {' & @CRLF & _ 'return JsArray.toString()' & @CRLF & _ '}' & @CRLF & _ 'else {' & @CRLF & _ 'return JsArray.reverse().toString()' & @CRLF & _ '}' & @CRLF & _ '}' ;==== ;==== Local $ObjErr = ObjEvent("AutoIt.Error", "_ErrorHandler") Local $o_Obj = 0 $o_Obj = ObjCreate("ScriptControl") $o_Obj.Language = "JScript" $o_Obj.AddCode($o_CBlock) ;==== ;==== If UBound($o_array, 2) = 0 Then Local $o_SortData = $o_Obj.run("ArraySorting" , $o_array, $o_Numeric, $o_ascending) $o_Obj = 0 Local $o_SortArry = StringSplit($o_SortData, ',', 2) Return $o_SortArry EndIf ;==== ;==== Local $o_ExtColmn[UBound($o_array)] For $i = 0 To UBound($o_array) - 1 $o_ExtColmn[$i] = $o_array[$i][$o_Column] Next Local $o_SortData = $o_Obj.run("ArraySorting" , $o_ExtColmn, $o_Numeric, $o_ascending) $o_Obj = 0 ;==== ;==== Local $o_SortArry = StringSplit($o_SortData, ',', 2) Local $o_TempStr = '' Local $o_Index[Ubound($o_array)][Ubound($o_array, 2)] For $i = 0 To Ubound($o_SortArry) - 1 For $j = 0 To Ubound($o_ExtColmn) - 1 If ($o_SortArry[$i] = $o_ExtColmn[$j]) AND Not StringRegExp($o_TempStr, '\b'& $j &'\b') Then $o_TempStr &= $j & '|' For $k = 0 To Ubound($o_array, 2) - 1 $o_Index[$i][$k] = $o_array[$j][$k] Next ExitLoop(1) Endif Next Next Return $o_Index ;==== EndFunc Func _ErrorHandler($oError) EndFunc Console results : $g_iRows = 1000 $g_iCols = 6 JScript: sorted in = 6749 ms (6s) $g_iRows = 2000 $g_iCols = 6 JScript: sorted in = 16642 ms (16s) $g_iRows = 4000 $g_iCols = 6 JScript: sorted in = 62014 ms (1min) $g_iRows = 8000 $g_iCols = 6 JScript: sorted in = 242022 ms (4min) So I stopped at 8000 rows of course (I'd never make it for 100.000 rows). Let's compare with the results when using the dll + code found in one of my preceding post (the one stipulating: quickly sort a string column in a 2D array $g_iRows = 100000 $g_iCols = 6 Preparing concatenated string = 774 ms Writing structure = 39 ms DllCall = 1574 ms Generating sorted 2D array = 6912 ms i.e. 3s + 7s for 100.000 rows, with use of AutoIt code and dll (3s) + final autoit code to fill all the other columns (7s), that's a plain total of 10s for rewriting the complete array of 100.000 rows with its string column sorted... on a slow computer. This time of 10s should be divided by 5 (at least) on recent computers (thanks to Jugador for his timers testing in the following posts) Now it's me asking you to please run __Example2() from your preceding script with 1000, 2000, 4000, 8000 (as I did) then maybe more rows if you wish, just to tell us what indicate the timers on your recent computer. I'm pretty sure there will be a huge difference with the tests I did on my antique one. I attach below LarsJ's original files so you won't have to search them on the Forum. Good luck Why not trying what I did one month ago when I knew nada about C++ ? I simply downloaded the well-known (free) CodeBlocks IDE which includes a compiler and I could easily compile since day #1 The actual version for recent computers is 20.03 (if I remember well), the preceding version (17.12) is for older computers. Guess which one I downloaded And it works really fine, no crash no nothing ! RandomArray.au3 Random2DArray.txt
    2 points
  2. Hello guys. I recently saw some posts that Windows 10 provides OCR API. So I decided to create a UDF. What's UWPOCR? UWPOCR UDF is a simple library to use Universal Windows Platform Optical character recognition API. Features. Get Text From Image File. Get Text From GDI+ Bitmap. Easy to use. Usage: #include "..\UWPOCR.au3" _Example() Func _Example() Local $sOCRTextResult = _UWPOCR_GetText(FileOpenDialog("Select Image", @ScriptDir & "\", "Images (*.jpg;*.bmp;*.png;*.tif;*.gif)")) MsgBox(0,"",$sOCRTextResult) EndFunc Get Words Rect(Example): More examples here. Check UWPOCR UDF on GitHub. Saludos
    1 point
  3. Using CryptoNG, as suggested by Danyfirex, it would look something like this: #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d #include <Constants.au3> #include <CryptoNG.au3> Const $RAND = "Some random value", _ $AUTH_KEY = "This is a test auth key value", _ $ENCRYPTED_PASSWORD = Binary("0x1ABE71DDDEDE44B3BC0B127F4581319A") ;Password123! aes_cbc_decrypt_example() Func aes_cbc_decrypt_example() Local $sDecryptedMessage = "" Local $xHash = Binary(""), _ $xEncryptionKey = Binary(""), _ $xIV = Binary("") ;Create a 256-bit/32-byte hash value using HMAC-SHA256 $xHash = _CryptoNG_HashData($CNG_BCRYPT_SHA256_ALGORITHM, $RAND, True, $AUTH_KEY) If @error Then Exit ConsoleWrite("HASH ERROR: " & _CryptoNG_LastErrorMessage()) ;Split hash value into encryption key (1st 16 bytes) & iv (last 16 bytes) $xEncryptionKey = BinaryMid($xHash, 1, 16) $xIV = BinaryMid($xHash, 17) ;Decrypt encrypted message $sDecryptedMessage = _CryptoNG_AES_CBC_DecryptData($ENCRYPTED_PASSWORD, $xEncryptionKey, $xIV) If @error Then Exit ConsoleWrite("DECRYPT ERROR: " & _CryptoNG_LastErrorMessage()) ;Display results ConsoleWrite(@CRLF) ConsoleWrite("CryptoNG AES CBC Data Decryption Example" & @CRLF & @CRLF) ConsoleWrite("Encrypted Password = " & $ENCRYPTED_PASSWORD & @CRLF) ConsoleWrite("Encrypted Password (BASE64) = " & _CryptoNG_CryptBinaryToString($ENCRYPTED_PASSWORD, $CNG_CRYPT_STRING_BASE64) & @CRLF) ConsoleWrite("RAND = " & $RAND & @CRLF) ConsoleWrite("AUTH Key = " & $AUTH_KEY & @CRLF & @CRLF) ConsoleWrite("HMAC-SHA256 Value = " & $xHash & @CRLF & @CRLF) ConsoleWrite("Encrypt Key = " & $xEncryptionKey & @CRLF) ConsoleWrite("Encrypt Key (Base64) = " & _CryptoNG_CryptBinaryToString($xEncryptionKey, $CNG_CRYPT_STRING_BASE64) & @CRLF) ConsoleWrite("IV = " & $xIV & @CRLF) ConsoleWrite("IV (Base64) = " & _CryptoNG_CryptBinaryToString($xIV, $CNG_CRYPT_STRING_BASE64) & @CRLF) ConsoleWrite("Decrypted Password = " & $sDecryptedMessage & @CRLF) EndFunc Console Output: CryptoNG AES CBC Data Decryption Example Encrypted Password = 0x1ABE71DDDEDE44B3BC0B127F4581319A Encrypted Password (BASE64) = Gr5x3d7eRLO8CxJ/RYExmg== RAND = Some random value AUTH Key = This is a test auth key value HMAC-SHA256 Value = 0x9674193E8C503BE24EA76FE74883FCAEE36DA19CCF8FF2A49DEA0087D9BECBEC Encrypt Key = 0x9674193E8C503BE24EA76FE74883FCAE Encrypt Key (Base64) = lnQZPoxQO+JOp2/nSIP8rg== IV = 0xE36DA19CCF8FF2A49DEA0087D9BECBEC IV (Base64) = 422hnM+P8qSd6gCH2b7L7A== Decrypted Password = Password123! Validation:
    1 point
  4. You can use _GUICtrlListBox_SetCurSel() to set the current selection to the last entry in the listbox and scroll it into view. #include <GuiListBox.au3> . . . Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") _GUICtrlListBox_SetCurSel($idMylist, _GUICtrlListBox_GetCount($idMylist) - 1)
    1 point
  5. pixelsearch

    Sort question in C++

    @jugador: thanks also to you for re-testing on a fast computer. As expected, your computer speed is 5 times quicker than mine. Look at our compared results for the 2000, 4000, 8000 rows : 2000 :  3s vs  16s 4000 : 12s vs  62s 8000 : 50s vs 242s The good news is that the "10s" time described in my precedent post... i.e. 3s + 7s for 100.000 rows, with use of AutoIt code and dll (3s) + final autoit code to fill all the other columns (7s), that's a plain total of 10s for rewriting the complete array of 100.000 rows with its string column sorted... on a slow computer. ... should be divided by 5 on your computer, i.e 2s to sort a string column from an array of 100.000 rows x 6 columns (i.e to rewrite the whole array), great ! We're talking here about the rewriting of the whole 2D array, which is very different of the creation of an index to sort a column in a virtual listview (as in ArrayDisplay beta) which doesn't rewrite anything in the array (the latter is even much faster of course). The problem is that the code in the JavaScript function isn't optimized as it constantly tries to match each element of the 1D sorted array, versus all the elements of the non-sorted array : Local $m = 0 For $i = 0 To Ubound($o_SortArry) - 1 ; 1D array of sorted elements For $j = 0 To Ubound($o_ExtColmn) - 1 ; 1D array of UNsorted elements $m += 1 ConsoleWrite($m & @crlf) If ($o_SortArry[$i] = $o_ExtColmn[$j]) AND Not StringRegExp($o_TempStr, '\b'& $j &'\b') Then $o_TempStr &= $j & '|' ConsoleWrite("$o_TempStr = " & $o_TempStr & @crlf) For $k = 0 To Ubound($o_array, 2) - 1 $o_Index[$i][$k] = $o_array[$j][$k] Next ExitLoop(1) Endif Next Next An example on 10 rows with __Example2() would show this in the Console : 55 tests made when they should have been only 10. Also the RegEx test to constantly check that a row hasn't already be picked etc... all this takes time. Console display with a test on 10 rows : ... 48 49 $o_TempStr = 9|2|0|4|3|8|1|6|7| 50 51 52 53 54 55 $o_TempStr = 9|2|0|4|3|8|1|6|7|5| The solution should be to match each sorted element with its corresponding row in "1 pass" (no loop) as explained in the preceding posts : keep somewhere the index (i.e. row) of each element as it was before the sort.
    1 point
  6. ad777

    7zip Gui Compressor -

    @Giggo just replace this: $cmd = Run($7zDir & ' a -mx="' & $livello & '" "' & GUICtrlRead($Out) & '" "' & '"-p"' & GUICtrlRead($pass) & '" "' & GUICtrlRead($Inp) & '\*"') with: $cmd = Run($7zDir & ' a -mx="' & $livello & '" "' & GUICtrlRead($Out) & '" "' & '"-p"' & GUICtrlRead($pass) & '" "' & GUICtrlRead($Inp) & '*"') the script will be: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Constants.au3> $FormName = "7-Zip Press" $Form1 = GUICreate($FormName, 550, 275, -1, -1) ;-GUISetBkColor(0xFFFFFF) GUISetIcon("shell32.dll", 160) $Inp = GUICtrlCreateInput("", 8, 8, 465, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetBkColor($Inp,0xFFFFFF) GUICtrlSetColor(-1, 0x001E1E1E) GUICtrlSetTip(-1, "Input") $Out = GUICtrlCreateInput("", 8, 40, 465, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetBkColor($Out,0xFFFFFF) GUICtrlSetColor(-1, 0x001E1E1E) GUICtrlSetTip(-1, "Output") $Pass = GUICtrlCreateInput("password", 40, 72, 433, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE)) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetColor(-1, 0xFFFF00) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetTip(-1, "Protect the file with password") $BtnBrowse = GUICtrlCreateButton("", 480, 6, 25, 25, $BS_ICON) GUICtrlSetImage(-1, @ScriptDir & "\Bin\icons\i1.ico", -1) GUICtrlSetTip(-1, "select folder") $BtnBrowseFile = GUICtrlCreateButton("", 515, 6, 25, 25, $BS_ICON) GUICtrlSetImage(-1, @ScriptDir & "\Bin\icons\i2.ico", -1) GUICtrlSetTip(-1, "select file") $BtnSave = GUICtrlCreateButton("", 480, 38, 25, 25, $BS_ICON) GUICtrlSetImage(-1, @ScriptDir & "\Bin\icons\i3.ico", -1) GUICtrlSetTip(-1, "save file") $BtnCompress = GUICtrlCreateButton("", 480, 70, 25, 25, $BS_ICON) GUICtrlSetImage(-1, @ScriptDir & "\Bin\icons\i4.ico", -1) GUICtrlSetTip(-1, "Compress") $BtnCancPass = GUICtrlCreateButton("", 8, 70, 25, 25, $BS_ICON) GUICtrlSetImage(-1, @ScriptDir & "\Bin\icons\i5.ico", -1) GUICtrlSetTip(-1, "Cancel password") $Group1 = GUICtrlCreateGroup("Sets level of compression", 8, 120, 257, 145) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") $Slider = GUICtrlCreateSlider(20, 146, 230, 25) GUICtrlSetLimit(-1, 5) $CompLabel = GUICtrlCreateLabel("Ultra", 31, 182, 116, 15) GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetColor(-1, 0x000080) GUICtrlSetData($Slider, '3') $LabelSize = GUICtrlCreateLabel("", 31, 226, 200, 29) GUICtrlSetTip(-1, "Size of the selected directory, folder or file") GUICtrlSetFont(-1, 9, 400, 0, "Courier New") GUICtrlSetColor(-1, 0x000080) GUICtrlSetColor(-1, 0x000080) GUISetState(@SW_SHOW) ;~~~~~~$sFileName = @ScriptDir &"\pass.txt" ;~~~~~~$hFilehandle = FileOpen($sFileName, $FO_OVERWRITE) Local $7zDir = '"' & @ScriptDir & '\Bin\7zG.exe"' $SliderCorrente = 5 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $BtnBrowse $sSelectFolder = FileSelectFolder("Select Folder", "") If @error Then continueloop GUICtrlSetData($Inp, $sSelectFolder) $iSize = DirGetSize($sSelectFolder) GUICtrlSetData($LabelSize,"Dim: " & _GetDisplaySize($iSize)) Case $BtnBrowseFile $sFileOpenDialog = FileOpenDialog("Select files", @DesktopDir , "All (*.*)", $FD_FILEMUSTEXIST) If @error Then continueloop GUICtrlSetData($Inp, $sFileOpenDialog) $iSize = FileGetSize($sFileOpenDialog) GUICtrlSetData($LabelSize,"Dimensione: " & _GetDisplaySize($iSize)) Case $BtnSave $sFileSaveDialog = FileSaveDialog("Save the file with name", @DesktopDir, "Format (*.7z)|Format (*.zip)", 2, "_Zipped") GUICtrlSetData($Out, $sFileSaveDialog) If @error Then continueloop Case $BtnCompress If GUICtrlRead($Inp) = "" Then MsgBox(48, $FormName, "The boxes must not be empty!") ContinueLoop EndIf If GUICtrlRead($Out) = "" Then MsgBox(48, $FormName, "The boxes must not be empty!") ContinueLoop EndIf _Seven_Zip() Case $BtnCancPass GUICtrlSetData($pass,"") EndSwitch If GUICtrlRead($Slider) <> $SliderCorrente Then $SliderCorrente = GUICtrlRead($Slider) Select Case $SliderCorrente = 5 GUICtrlSetData($CompLabel, "Ultra") $livello = 9 Case $SliderCorrente = 4 GUICtrlSetData($CompLabel, "Maximum") $livello = 7 Case $SliderCorrente = 3 GUICtrlSetData($CompLabel, "Normal") $livello = 5 Case $SliderCorrente = 2 GUICtrlSetData($CompLabel, "Fast") $livello = 3 Case $SliderCorrente = 1 GUICtrlSetData($CompLabel, "Fastest") $livello = 1 Case $SliderCorrente = 0 GUICtrlSetData($CompLabel, "Copy") $livello = 0 EndSelect EndIf WEnd Func _GetDisplaySize($iSize, $iPlaces = 2) Local $aBytes[5] = [' Bytes', ' KB', ' MB', ' GB', ' TB'] For $i = 4 To 1 Step -1 If $iSize >= 1024 ^ $i Then Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i] EndIf Next Return $iSize & ' Bytes' EndFunc Func _Seven_Zip() If GUICtrlRead($pass) = "" Then $cmd = Run($7zDir & ' a -mx="' & $livello & '" "' & GUICtrlRead($Out) & '" "' & GUICtrlRead($Inp) & '"') else $cmd = Run($7zDir & ' a -mx="' & $livello & '" "' & GUICtrlRead($Out) & '" "' & '"-p"' & GUICtrlRead($pass) & '" "' & GUICtrlRead($Inp) & '*"') endif EndFunc
    1 point
  7. jugador

    Sort question in C++

    Console results (it's slow.... 😫 😞 $g_iRows = 1000 $g_iCols = 6 JScript: sorted in = 837 ms $g_iRows = 2000 $g_iCols = 6 JScript: sorted in = 3177 ms $g_iRows = 4000 $g_iCols = 6 JScript: sorted in = 12623 ms $g_iRows = 8000 $g_iCols = 6 JScript: sorted in = 50061 ms here the Console output (if omit the loop but it make the code meaningless) #cs Local $o_TempStr = '' ...... ...... Return $o_Index #ce $g_iRows = 8000 $g_iCols = 6 JScript: sorted in = 55 ms $g_iRows = 100000 $g_iCols = 6 JScript: sorted in = 763 ms $g_iRows = 500000 $g_iCols = 6 JScript: sorted in = 4924 ms @pixelsearch thanks for testing so no point of dragging it as I don't have idea to improve the loop
    1 point
  8. @Danp2i was able to figure it out. I created an If and Else statement and then inserted a for loop.
    1 point
×
×
  • Create New...