Leaderboard
Popular Content
Showing content with the highest reputation on 02/19/2022 in all areas
-
Here how your _Generate function should look like : Func _Generate() Local $sLib, $sResult, $aLib Local $iCount = GUICtrlRead($Combo1) If $iCount < 0 Or Not StringIsInt($iCount) Then Return If GUICtrlRead($cbxUpper) = $GUI_CHECKED Then $sLib &= $sUpper If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $sLib &= GUICtrlRead($txtOthers) If $sLib = "" Then Return $aLib = StringSplit($sLib, "") For $i = 1 To $iCount $sResult &= $aLib[Random(1, $aLib[0], 1)] Next GUICtrlSetData($txtPassword, $sResult) EndFunc ;==>_Generate1 point
-
Local $oDic = ObjCreate("Scripting.Dictionary") $oDic("USA") = "United States of America" $oDic("UK") = "United Kingdom" $oDic("CAN") = "Canada" $oDic.Remove("UK") ConsoleWrite($oDic.count & @CRLF)1 point
-
Window that changes
mininja reacted to SOLVE-SMART for a topic
Hi @mininja, you already use the option WinTitleMatchMode, so just set that option to 2 😉 . Opt("WinTitleMatchMode", 2) ; 1 = start, 2 = subStr, 3 = exact, 4 = advanced, -1 to -4 = Nocase "2 = Match any substring in the title" This is just one approach, but I am sure there are better ways to handle this. But maybe it's already enough for fitting your requirements? --------------------------------- By the way: Are you sure you want to set the found window to a negative X position? Why? In case you want to hide the window, you could do it differently 😀 . Best regards Sven ________________ Stay innovative!1 point -
Sort question in C++
jugador reacted to pixelsearch for a topic
Hi everybody Here are 2 working AutoIt scripts related to the C++ code of the preceding post : 1) SortAll.au3 : it's an include file with 1 function SortAll() which is called when a script needs a fast sorting. #include-once #include "AutoItConstants.au3" #include "MsgBoxConstants.au3" ;================================================================== Func SortAll(ByRef $aArray, $iSortCol = 0, $iType = 1, $iSense = 0) If $iSortCol = Default Then $iSortCol = 0 ; 1st column = 0 If $iType = Default Then $iType = 1 ; 0 = String sort, 1 = Numeric sort If $iSense = Default Then $iSense = 0 ; 0 = ascending, 1 = descending If Not IsArray($aArray) Then MsgBox($MB_TOPMOST, "Error : variable $aArray is not an Array", _ "Its type is : " & VarGetType($aArray)) Return SetError(1, 0, 0) EndIf Local $iDims = UBound($aArray, $UBOUND_DIMENSIONS) If $iDims < 1 Or $iDims > 2 Then MsgBox($MB_TOPMOST, "Error : Dimensions = " & $iDims, _ "Array is not 1D or 2D") Return SetError(2, 0, 0) EndIf Local $iRows = UBound($aArray, $UBOUND_ROWS) If $iRows < 2 Then MsgBox($MB_TOPMOST, "Nothing to sort", _ "Array doesn't have 2 rows") ; no matter 1D or 2D Return 1 ; success anyway EndIf Local $iCols = UBound($aArray, $UBOUND_COLUMNS) ; always 0 for 1D array. If $iDims = 2 Then If $iCols = 0 Then MsgBox($MB_TOPMOST, "Error", _ "2D Array got 0 columns") Return SetError(3, 0, 0) ElseIf $iSortCol < 0 Or $iSortCol > $iCols - 1 Then MsgBox($MB_TOPMOST, "Error : sort column " & $iSortCol, _ "Please choose between 0 and " & $iCols - 1) Return SetError(4, 0, 0) EndIf EndIf If $iType < 0 Or $iType > 1 Then MsgBox($MB_TOPMOST, "Unknown Type of sort " & $iType, _ "It should be : 0 = String sort, 1 = Numeric sort") Return SetError(5, 0, 0) EndIf If $iSense < 0 Or $iSense > 1 Then MsgBox($MB_TOPMOST, "Unknown Sense of sort " & $iSense, _ "It should be : 0 = Ascending, 1 = Descending") Return SetError(6, 0, 0) EndIf Local $hDLLSort = DllOpen("sortall.dll") ; as no path indicated, dll is searched first in path environment, then in script path. ; if path is indicated (@ScriptDir for example), then it's the contrary. If $hDLLSort = -1 Then MsgBox($MB_TOPMOST, "Error", _ "sortall.dll can't be opened") Return SetError(20, 0, 0) EndIf Local $tStruct2 = DllStructCreate("int[" & $iRows & "]") ; will be filled by dll If @error Then MsgBox($MB_TOPMOST, "DllStructCreate : error " & @error, _ "Check AutoIt help file for this error") DllClose($hDLLSort) Return SetError(21, 0, 0) EndIf Local $sData = "", $sDelim = Chr(1) ; don't change Chr(1), it's used in the dll too If $iDims = 1 Then ; 1D If $iType = 1 And StringLeft(StringStripWS($aArray[0], 1), 2) = "0x" Then ; $STR_STRIPLEADING = 1 For $i = 0 To $iRows - 1 $sData &= Number(StringStripWS($aArray[$i], 1)) & $sDelim ; $sDelim also at end of string (used by dll +++) Next Else For $i = 0 To $iRows - 1 $sData &= $aArray[$i] & $sDelim Next EndIf Else ; 2D If $iType = 1 And StringLeft(StringStripWS($aArray[0][$iSortCol], 1), 2) = "0x" Then For $i = 0 To $iRows - 1 $sData &= Number(StringStripWS($aArray[$i][$iSortCol], 1)) & $sDelim Next Else For $i = 0 To $iRows - 1 $sData &= $aArray[$i][$iSortCol] & $sDelim Next EndIf EndIf Local $aBackup = $aArray ; backup the array before the sort (extremely fast !) Local $aRet = DllCall($hDLLSort, "int:cdecl", "sortall", "str", $sData, "ptr", DllStructGetPtr($tStruct2), _ "str", $sDelim, "int", $iRows, "int", $iSense, "int", $iType) If @error Then MsgBox($MB_TOPMOST, "DllCall : error " & @error, _ "Check AutoIt help file for this error") DllClose($hDLLSort) Return SetError(22, 0, 0) EndIf If $aRet[0] <> 0 Then MsgBox($MB_TOPMOST, "sortall.dll : error " & $aRet[0], _ "Check C++ code in dll") DllClose($hDLLSort) Return SetError(23, 0, 0) EndIf Local $iIndex If $iDims = 1 Then ; 1D For $i = 0 To $iRows - 1 $iIndex = DllStructGetData($tStruct2, 1, $i + 1) ; row index before sorting ; If $i <> $iIndex Then ; test not really useful when original array is 1D $aArray[$i] = $aBackup[$iIndex] ; EndIf Next Else ; 2D For $i = 0 To $iRows - 1 $iIndex = DllStructGetData($tStruct2, 1, $i + 1) ; row index before sorting If $i <> $iIndex Then For $j = 0 To $iCols - 1 $aArray[$i][$j] = $aBackup[$iIndex][$j] Next EndIf Next EndIf DllClose($hDLLSort) Return 1 ; success EndFunc ;==>SortAll 2) Test.au3 : a test on a 1D array of 100.000 numeric elements (integers, floats or doubles) #include <Array.au3> #include <SortAll.au3> ; pixelsearch's sortall.dll Opt("MustDeclareVars", 1) Local $iRows = 100000, $aArray[$iRows] ConsoleWrite("$iRows = " & $iRows & @CRLF) ;~ GenerateArrayInt($aArray, $iRows) GenerateArrayDouble($aArray, $iRows) ;~ GenerateArrayFloat($aArray, $iRows) _ArrayDisplay($aArray, "UNsorted", Default, Default, Default, _ "Numbers*") ; * at end of header means numeric sort ;==================================== Local $hTimer = TimerInit() Local $iSortCol = 0 ; value not important when 1D Local $iRet = SortAll($aArray, $iSortCol, 1, 0) ; numeric sort, ascending If $iRet Then ; 1 = success, 0 = fail with @error > 0 ConsoleWrite("Generating sorted 1D array = " & Int(TimerDiff($htimer)) & " ms" & @crlf) _ArrayDisplay($aArray, "sorted (col " & $iSortCol & ")", Default, Default, Default, _ "Numbers*") ; * at end of header means numeric sort EndIf ;==================================== Func GenerateArrayInt(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Random(-1000000, +1000000, 1) Next EndFunc ;==>GenerateArrayInt ;==================================== Func GenerateArrayDouble(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Random(-1000000, +1000000) ; $aArray[$i] = Random(-1, 1) Next EndFunc ;==>GenerateArrayDouble ;==================================== Func GenerateArrayFloat(ByRef $aArray, $iRows) For $i = 0 To $iRows - 1 $aArray[$i] = Number("" & Random(-1000000, +1000000, 1) & "." & Random(0,99,1), 3) Next EndFunc ;==>GenerateArrayFloat Console : $iRows = 100000 Generating sorted 1D array = 3058 ms Timer to be divided by 5 (or more) if your computer is recent => less than 1s to rewrite a whole 1D sorted array of 100.000 elements, yes ! For readers who are interested and got a compiler, you should be able to compile the C++ code of the preceding post, then place the resulting dll (named "sortall.dll") in one of the folders of your PATH environment (or in the folder of the test file "test.au3") If the dll isn't found in one of these folders, then this error will appear when you run the test file : Personally, I placed the dll in my Windows folder (which isn't really recommended) and the include file... in AutoIt's include files folder, which isn't recommended either ! I'll probably change that soon. Good luck.1 point -
Yep Local $oDic = ObjCreate("Scripting.Dictionary") $oDic("USA") = "United States of America" $oDic("UK") = "United Kingdom" $oDic("CAN") = "Canada" For $obj in $oDic.keys Msgbox(0,"Key: " & $obj, " Value: " & $oDic($obj)) Next https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dictionary-object1 point