Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/18/2016 in all areas

  1. Simple snowfall using GDI+ & ASM. Thanks to Eukalyptus for the ASM codes. If the script runs too slow reduce the amount of flakes in line 115. You can switch now between local MP3 stream and internet stream. Further you can also set the scrolling text. Command line options: -local "<path to local MP3 file>" -url "<URL to a MP3 file>" -text "<your individual text>" Max. text length are 500 chars. Don't forget the double quotes after the parameters! Download: click me Happy snowing and romantic moments...
    1 point
  2. czardas

    _ArrayForceDim

    A question came up regarding _ArrayTranspose(). Strictly speaking this function is only suitable for 2D arrays: transposition of a 1D array should return the same array, or an error. Why? - because there is no second dimension available to make the transposition. The workaround for this is to force the return of a 2D array containing a single row, which is all well and good until you want to reverse the process. Should the original 1D array be returned, or a 2D array containing a single column? A Possible Solution After some discussion in the MVP forum, I have concluded that this type of problem is more common than people are led to believe. The help file clearly states that ReDim does not allow you to modify the number of dimensions in an array, and nobody questions this. Here is a function (similar to ReDim) which allows you to return the first column of a 2D array as a 1D array (and similar changes). You can add, or remove, up to 5 dimensions. The maximum supported number of dimensions is 6. Arrays with more than 4 dimensions are very rare. #include <Array.au3> ; For _ArrayDisplay Global $aArray1D[5] = [10, 20, 30, 40, 50] Global $aArray2D[3][5] = [[10, 20, 30, 40, 50], [11, 21, 31, 41, 51], [12, 22, 32, 42, 52]] Global $aArray3D[3][4][2] = [[["000", "001"], ["010", "011"], ["020", "021"], ["030", "031"]], _ [["100", "101"], ["110", "111"], ["120", "121"], ["130", "131"]], _ [["200", "201"], ["210", "211"], ["220", "221"], ["230", "231"]]] _ArrayForceDim($aArray3D, 2) ; Convert to 2D _ArrayDisplay($aArray3D, '3D coverted to 2D') _ArrayDisplay($aArray2D, "2D (before)") _ArrayForceDim($aArray2D, 1) _ArrayDisplay($aArray2D, "2D converted to 1D (after)") _ArrayForceDim($aArray1D, 6) ; 1D converted to 6D For $i = 0 To UBound($aArray1D, 1) -1 ConsoleWrite($aArray1D[$i][0][0][0][0][0] & @LF) Next ; #FUNCTION# =================================================================================================================== ; Name...........: _ArrayForceDim ; Description ...: Changes the size of an array by adding, or removing, dimensions. ; Syntax.........: _ArrayForceDim($aArray, $iDimensions) ; Parameters.....; $aArray - The original array. ; $iDimensions - The number of dimensions in the returned array. ; Return values .: Returns the modified array ByRef. ; Failure sets @error as follows: ; |@error = 1 The first parameter is not an array. ; |@error = 2 The requested array has more than 6 dimensions. ; |@error = 3 The original array has more than 6 dimensions. ; Author.........: czardas ; Comments ......; This function works for up to 6 dimensions. ; New dimensions are added at the end in a standard sequence: $aArray[7][6] may become $aArray[7][6][1] ; Dimensions are removed in reverse sequence: $aArray[7][6] will become $aArray[7] ; ============================================================================================================================== Func _ArrayForceDim(ByRef $aArray, $iDimensions) If Not IsArray($aArray) Then Return SetError(1) $iDimensions = Int($iDimensions) If $iDimensions < 1 Or $iDimensions > 6 Then Return SetError(2) Local $iPreDims = UBound($aArray, 0) ; current number of dimensions If $iPreDims = $iDimensions Then Return ; no change If $iPreDims > 6 Then Return SetError(3) ; too many dimensions ; get the size of each original dimension Local $a[$iPreDims +1] For $i = 1 To $iPreDims $a[$i] = UBound($aArray, $i) Next   ReDim $a [$iDimensions +1] ; modify the number of dimensions ; assign the size of each new dimension ...[1][1][1] etc... For $i = $iPredims + 1 To $iDimensions $a[$i] = 1 Next Local $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0 ; varibale names are associated with dimensions Local $sElement = '$aArray' & StringLeft('[$1][$2][$3][$4][$5][$6]', $iPredims * 4) ; to access the original array elements ; add or remove dimensions Switch $iDimensions Case 1 Local $aNewArray[$a[1]] For $1 = 0 To $a[1] -1 $aNewArray[$1] = Execute($sElement) Next Case 2 Local $aNewArray[$a[1]][$a[2]] For $1 = 0 To $a[1] -1 For $2 = 0 To $a[2] -1 $aNewArray[$1][$2] = Execute($sElement) Next Next Case 3 Local $aNewArray[$a[1]][$a[2]][$a[3]] For $1 = 0 To $a[1] -1 For $2 = 0 To $a[2] -1 For $3 = 0 To $a[3] -1 $aNewArray[$1][$2][$3] = Execute($sElement) Next Next Next Case 4 Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]] For $1 = 0 To $a[1] -1 For $2 = 0 To $a[2] -1 For $3 = 0 To $a[3] -1 For $4 = 0 To $a[4] -1 $aNewArray[$1][$2][$3][$4] = Execute($sElement) Next Next Next Next Case 5 Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]] For $1 = 0 To $a[1] -1 For $2 = 0 To $a[2] -1 For $3 = 0 To $a[3] -1 For $4 = 0 To $a[4] -1 For $5 = 0 To $a[5] -1 $aNewArray[$1][$2][$3][$4][$5] = Execute($sElement) Next Next Next Next Next Case 6 Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]] For $1 = 0 To $a[1] -1 For $2 = 0 To $a[2] -1 For $3 = 0 To $a[3] -1 For $4 = 0 To $a[4] -1 For $5 = 0 To $a[5] -1 For $6 = 0 To $a[6] -1 $aNewArray[$1][$2][$3][$4][$5][$6] = Execute($sElement) Next Next Next Next Next Next EndSwitch $aArray = $aNewArray EndFunc ;==> _ArrayForceDimIn terms of expanding an array, this function is useful when you know how many dimensions are needed, but you don't know how large the array will eventually become. Dimensions are added with the minimum size.
    1 point
  3. 1 point
  4. I don't know well about treeviews but this seems to work Func TreeView_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $tv1 If Not IsHWnd($tv1) Then $hWndTreeview = GUICtrlGetHandle($tv1) Static $hItem0 $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local $cntr = 0 Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $TVN_SELCHANGEDW ; Insert your code here $hItem = _GUICtrlTreeView_GetSelection ($hWndTreeview) If $hItem <> $hItem0 Then ConsoleWrite("Clicked " & _GUICtrlTreeView_GetText($hWndTreeview, $hItem) & @CRLF) $hItem = $hItem0 EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edit There is probably certainly an easier way
    1 point
  5. 31290, Glad I could help. M23
    1 point
  6. 31290, Not very difficult - look for the <<<<<<<<<<<< lines: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListView.au3> ; Read file into array $aLines = FileReadToArray("EPES18.txt") ; Deal with title line $aLines[0] = StringRegExpReplace($aLines[0], "(\x20+)", "|") ; Now the other lines For $i = 1 To UBound($aLines) - 1 ; Extract line $sLine = $aLines[$i] ; Replace tabs with spaces $sLine = StringReplace($sLine, @TAB, " ") ; Extract possible name field $sName = StringRegExpReplace($sLine, "(?U)^.*(\x20.*\x20)(connected|notconnect|err-disabled).*$", "$1") ; Convert multiple spaces to singles $sStrippedName = StringRegExpReplace($sName, "\x20+", " ") ; Set placeholder if no name field If $sStrippedName = " " Then $sStrippedName = " ~ " ; Replace original name string in line with stripped version - add spaces to ensure multiple spaces before and after $sLine = StringReplace($sLine, $sName, " " & $sStrippedName & " ") ; Set delimiters by replacing multiple spaces $sLine = StringRegExpReplace($sLine, "(\x20{2,19})", "|") ; Remove placeholders $sLine = StringReplace($sLine, "~", "") ; Replace existing line with delimited line $aLines[$i] = $sLine Next ; Read IP Phone ID file $sID = Fileread("id.txt") $hGUI = GUICreate("Test", 500, 500) ; Create ListView with first 4 headers plus "IP Phone" $cLV = GUICtrlCreateListView(StringRegExpReplace($aLines[0], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & "|IP Phone", 10, 10, 480, 380) ; Set column widths For $i = 0 To 4 _GUICtrlListView_SetColumnWidth($cLV, $i, 90) Next ; Add content of first 4 fields in each line plus the IP Phone result For $i = 1 To UBound($aLines) - 1 ; Assume not IP Phone $sIPPhone = "|Not set" ; Look for the port ID in the file - it will be preceded by a space and followed by either a comma or an EOL If StringRegExp($sID, " " & StringRegExpReplace($aLines[$i], "(?U)^(.*)\|.*$", "$1") & "[,\x0D]") Then ; If found change the set value $sIPPhone = "|Set" EndIf ; Add fields and IP Phone to the ListView $cLVItem = GUICtrlCreateListViewItem(StringRegExpReplace($aLines[$i], "(?U)^(.*\|.*\|.*\|.*)\|.*$", "$1") & $sIPPhone, $cLV) Next $cDummyCheckRow = GUICtrlCreateDummy() ; Create dummy control <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() ; Set sort state Local $aSortSense[_GUICtrlListView_GetColumnCount($cLV)] While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cDummyCheckRow ; Fired by the handler, but only once the handler has exited <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $iRow = GUICtrlRead($cDummyCheckRow) ; Read the row value <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox($MB_SYSTEMMODAL, $iRow, StringReplace(_GUICtrlListView_GetItemTextString($cLV, $iRow), "|", @CRLF)) ; Display the row data <<<<<<<<<<<<<<<<< EndSwitch WEnd Func _WM_NOTIFY($hWnd, $imsg, $wParam, $lParam) ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) Switch $iCode Case $LVN_COLUMNCLICK ; Get column index Local $iCol = DllStructGetData($tStruct, 5) If $iCol <> 0 Then ; Sort column _GUICtrlListView_SimpleSort($cLV, $aSortSense, $iCol) EndIf Case $NM_DBLCLK $iRow = DllStructGetData($tStruct, 4) GUICtrlSendToDummy($cDummyCheckRow, $iRow) ; Send the row value to the dummy control and fire it once returned <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec") ; Item index Local $iSubItem = DllStructGetData($tNMLVCUSTOMDRAW, "iSubItem") ; Subitem index ; Gte text of item $sText = _GUICtrlListView_GetItemText($cLV, $iItem, $iSubItem) ; Set default back colour $iBkColour = 0xC4C4C4 ; Now check for our spoecific items Switch $iSubItem Case 2 ; connection Switch $sText Case "connected" $iBkColour = 0x00FF00 Case "notconnect" $iBkColour = 0x0000FF Case "err-disabled" $iBkColour = 0xC4C4C4 EndSwitch Case 3 ; vlan Switch $sText Case "trunk" $iBkColour = 0x00FFFF Case "1" $iBkColour = 0xFFFF00 Case "10" $iBkColour = 0xC4FFC4 Case "13" $iBkColour = 0xFF00FF EndSwitch EndSwitch ; Set required back colour DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", $iBkColour) Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndFunc ;==>_WM_NOTIFY Now you can move the MsgBox around as much as you like. M23
    1 point
  7. Here it is #include <MsgBoxConstants.au3> #include <StringConstants.au3> $txt = StringStripWS(FileRead("1.txt"), $STR_STRIPALL) ; If StringRegExp($txt, '(.)\1\1$') Then Msgbox($MB_OK,"", "the 3 last ones are the same") If StringRegExp($txt, '4...$') Then Msgbox($MB_OK,"", 'there is a "4" before the 3 last ones')
    1 point
  8. @addjon, many ask for an Arrayfied Json. Here is my take at it, that works with your string. ( may not work with others ) #include <JSon.au3> #include <Array.au3> Local $sJson_1 = '{"response":{"status":1,"httpStatus":200,"data":[{"id":"10445","categories":{"6":{"id":"6","name":"D"},"27":{"id":"27","name":"I"}}},{"id":"10159","categories":{"20":{"id":"20","name":"W"}}}],"errors":[],"errorMessage":null}}' Local $sJson_2 = '{"response":{"status":1,"httpStatus":200,"data":[{"id":"11930","countries":{"CH":{"id":"756","code":"CH","name":"Switzerland","regions":[]}}},{"id":"11928","countries":{"UK":{"id":"826","code":"UK","name":"United Kingdom","regions":[]},"HR":{"id":"191","code":"HR","name":"Croatia","regions":[]}}}],"errors":[],"errorMessage":null}}' Local $aReturned = JsonArrayfied($sJson_1) _ArrayDisplay($aReturned, "$aReturned") $aReturned = JsonArrayfied($sJson_2) _ArrayDisplay($aReturned, "$aReturned") Func JsonArrayfied($sJsonString, $iEcho = 0) Local $sConsoleWriteJson = ConsoleWriteJson($sJsonString, "", $iEcho) Local $n, $aLines = StringSplit($sConsoleWriteJson, @LF, 1) Local $aTemp, $iRow = 0, $iCol = 0, $m, $aJsonArrayfied[UBound($aLines) + 1][100] ; a lazy but efficient way to go about it For $n = 1 To $aLines[0] If StringInStr($aLines[$n], ":") + 2 > StringLen($aLines[$n]) Then ContinueLoop $aLines[$n] = StringReplace($aLines[$n], "][", "|") $aLines[$n] = StringReplace($aLines[$n], "]", "|") $aLines[$n] = StringReplace($aLines[$n], "[", "|") $aTemp = StringSplit($aLines[$n], "|") $iRow += 1 For $m = 1 To $aTemp[0] - 1 If $iCol < $m Then $iCol = $m $aJsonArrayfied[$iRow][$m - 1] = StringReplace($aTemp[$m], '"', '') Next $aJsonArrayfied[$iRow][$aTemp[0] - 1] = StringTrimLeft($aTemp[$aTemp[0]], StringInStr($aTemp[$aTemp[0]], ":") + 1) $aJsonArrayfied[$iRow][0] = StringMid($aTemp[$aTemp[0]], 5, StringInStr($aTemp[$aTemp[0]], ":") - 5) Next $aJsonArrayfied[0][0] = $iRow $aJsonArrayfied[0][1] = $iCol ReDim $aJsonArrayfied[$iRow + 1][$iCol + 1] Return $aJsonArrayfied EndFunc ;==>JsonArrayfied ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; added by me Func ConsoleWriteJson($sJsonString, $sDesc = "", $iEcho = 1) Local $sOutGlobal If $sDesc = "" Then $sDesc = 'ConsoleWriteJson' Local $obj = Json_Decode($sJsonString) Json_Iterate($sOutGlobal, $obj, '', $sDesc, $iEcho) Return $sOutGlobal EndFunc ;==>ConsoleWriteJson Func Json_Iterate(ByRef $sOutGlobal, $obj, $string, $pre = "", $iEcho = 1) Local $sOut = "" Local $temp, $i, $b If ($pre <> "") Then $sOut &= $pre & ": " If $iEcho Then ConsoleWrite($pre & ": ") EndIf $a = Json_Get_ShowResult($obj, $string, $sOutGlobal, $iEcho) If IsArray($a) Then For $i = 0 To UBound($a) - 1 Json_Iterate($sOutGlobal, $obj, $string & '[' & $i & ']', $pre, $iEcho) Next ElseIf IsObj($a) Then $b = Json_ObjGetKeys($a) For $temp In $b Json_Iterate($sOutGlobal, $obj, $string & '["' & $temp & '"]', $pre, $iEcho) Next EndIf Return $sOutGlobal EndFunc ;==>Json_Iterate Func Json_Get_ShowResult($Var, $Key, ByRef $sOutGlobal, $iEcho) Local $sOut = "" Local $Ret = Json_Getr($Var, $Key) If @error Then Switch @error Case 1 $sOut &= "Error 1: key not exists" & @LF If $iEcho Then ConsoleWrite($sOut) Case 2 $sOut &= "Error 2: syntax error" & @LF If $iEcho Then ConsoleWrite($sOut) EndSwitch Else $sOut &= $Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF If $iEcho Then ConsoleWrite($sOut) EndIf $sOutGlobal &= $sOut ;& $Ret Return $Ret EndFunc ;==>Json_Get_ShowResult Func Json_Getr($Var, $Key) If Not $Key Then Return $Var Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3) If IsArray($Match) Then Local $Index = Json_Decode($Match[1]) $Key = StringTrimLeft($Key, StringLen($Match[0])) If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then Local $Ret = Json_Getr(Json_ObjGet($Var, $Index), $Key) Return SetError(@error, 0, $Ret) ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then Local $Ret = Json_Getr($Var[$Index], $Key) Return SetError(@error, 0, $Ret) Else Return SetError(1, 0, "") EndIf EndIf Return SetError(2, 0, "") EndFunc ;==>Json_Getr Hope it helps to get what you look for.
    1 point
  9. You can try this $txt = StringStripWS(FileRead("1.txt"), 8) If StringRegExp($txt, '(.)\1\1$') Then Msgbox(0,"", "the 3 last ones are the same")
    1 point
  10. "From what I've notice, whenever I press and hole Ctrl button, the script pauses as well." Probably a bluestacks issue, never heard of an autoit feature like that.
    1 point
  11. I applaud you for taking on this challenge, as this no easy task. It's great that you have chosen AutoIt, but if the reason for your choice is because it's an "easy" language to understand and not because it's the right tool, then you might want to do some research a little bit. How I would do it would be... PHP 7 backend using the Laravel framework for all that goodness MySQL database for storing products and customer data. As a starting point 3 tables, customers, products and orders, in which the orders table would have a relationship between the customer and product tables. (Of course I don't know the business requirements) HTML5/CSS3/JavaScript (ideally ES2015 transpiled to ES5) frontend From there I would add certain roles and access rights, in that multiple employees could use the system, but not mess it up. Anyway, you get the idea.
    1 point
  12. maniootek, No bug. Look up "floating point arithmetic" and you will see it is a result of how computers store doubles. The solution? Convert to integers and then reconvert the result: $Result = 0 For $i = 0 To UBound($array) - 1 $Result += 100 * $array[$i] Next MsgBox(0, 0, $Result / 100) M23
    1 point
  13. Some time ago I was dealing with some Net Controls and I wrote this simple funtion. I hope it helps. _NetControlClick($hWindow, "BUTTON", 5) ;this should work for you Func _NetControlClick($hWindow, $sControlType, $IDNumber) Local $sClassName = _WinAPI_GetClassName($hWindow) Local $sApp = StringMid($sClassName, StringInStr($sClassName, ".app")) $sClassName = StringMid($sClassName, 1, StringInStr($sClassName, ".")) Return ControlClick($hWindow, "", $sClassName & $sControlType & $sApp & $IDNumber) EndFunc ;==>_NetControlClick Saludos
    1 point
×
×
  • Create New...