Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/09/2016 in all areas

  1. @JohnOne, agreed on all points, and good call about the less experienced being unlikely to post. I'm certainly not criticizing you for contributing! This. I don't need ego stroking per se, but I was glad to see @tarretarretarre excited about this and hoped others would join him. But people are downloading it and hopefully using it successfully. That or it's not working for them and they're moving on. I guess if we really wanted to know, we'd create a poll. I personally didn't care that much when I posted my example. My position was very much "take it or leave it" and that probably showed. I'm happy to see this developed into something more useful; I'm just not willing to spend any more time on it myself.
    2 points
  2. Inspired by $ES_NUMBER, but not limited to numbers. May be useful for other types of controls (Combo, Edit, etc.), but not tested. What It Does This UDF is for making sure only valid characters or values are entered into an Input control. When a control is imposed for valid characters, it removes the offending characters, displays a balloon tip (similar to $ES_NUMBER), plays a beep, and waits for user activity (key press or mouse move) before the tooltip is cleared. Beep and tooltip parameters are controlled, and can even be completely disabled if the calling script prefers to handle the user notification in custom. A core concept in the UDF is the conditions array. this array contains string and/or numeric conditions (characters allowed/disallowed, etc.) and notification behaviour for tooltip and beep. The conditions array is managed by _InputImpose_Create, _InputImpose_Duplicate, and _InputImpose_Update. You can build a conditions array to be used for multiple input controls, or you can simply call _InputImpose with ad-hoc conditions, without creating an array. all techniques are demonstrated in the example script. How To Use after you create the Input control $gInput in the GUI $hGUI, create a conditions array. for example: Global $aCondition = _InputImpose_Create($__INIM_ALLOW_ANYWHERE, '0..9.-+*/^()') ; math expression you can specify any or all available conditions in the same array creation (see the UDF constants section). you can update the array later, duplicate it for other controls and modify the conditions, etc. to apply, put this line in the main loop of your script: _InputImpose($hGUI, $gInput, $aCondition) Parameters ; Parameters ....: $hGUI - Handle to the GUI in which the input control is located. ; $gInput - Control ID of the Input control to impose. ; $aCondition - Conditions array. if the conditions array defines no tooltip or beep, then the only indication the user has that an invalid character was removed is that... well... it was removed. This is useful if you want to handle the notification yourself. In this case, use the function return value to determine if a notification is due, for example: If _InputImpose(...) Then MsgBox(...) Example The attached example shows a GUI with 6 Input controls, each with its own conditions array (content and build technique) for valid characters, custom tooltip and beep behaviour. Enjoy! the UDF (v1.0) : #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: InputImpose ; AutoIt Version : 3.3.14.5 ; UDF Version ...: 1.0 ; Status ........: Production ; Language ......: English ; Description ...: Impose valid characters in an Input control - inspired by $ES_NUMBER, but not limited to numbers. ; May be useful for other types of controls (Combo, Edit, etc.), but not tested. ; When a control is imposed for valid characters, it removes the offending characters, displays a balloon tip ; (similar to $ES_NUMBER), plays a beep, and waits for user activity (key press or mouse move) before the ; tooltip is cleared. Beep and tooltip parameters are controlled, and can even be completely disabled if the ; calling script prefers to handle the user notification in custom. ; NOTE: Default values for tooltip and beep: ; - tooltip text: "Press any key or move mouse to continue" ; - tooltip title: "Unacceptabe Character" (same as $ES_NUMBER for English systems) ; - beep frequency: 430 ; - beep duration: 300 ; Dll ...........: kernel32.dll, user32.dll ; Author(s) .....: orbs ; Resources .....: ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== Global Enum _ $__INIM_ALLOW_ANYWHERE, $__INIM_ALLOW_FIRST, $__INIM_ALLOW_LAST, $__INIM_ALLOW_ONCE, _ ; allow conditions $__INIM_DISALLOW_ANYWHERE, $__INIM_DISALLOW_FIRST, $__INIM_DISALLOW_LAST, _ ; disallow conditions $__INIM_ENFORCE_NUMLOWERLIMIT, $__INIM_ENFORCE_NUMUPPERLIMIT, _ ; enforce numerical coditions $__INIM_TOOLTIP_TEXT, $__INIM_TOOLTIP_TITLE, _ ; tooltip contents $__INIM_TOOLTIP_TIMEOUT, $__INIM_TOOLTIP_BYCURSOR, _ ; tooltip behaviour $__INIM_BEEP_FREQUENCY, $__INIM_BEEP_DURATION, _ ; beep behaviour $__INIM_CONDITIONCOUNT ; conditons array size ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_InputImpose ;_InputImpose_Create ;_InputImpose_Duplicate ;_InputImpose_Update ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _InputImpose ; Description ...: Impose valid characters in an Input control. ; Syntax ........: _InputImpose($hGUI, $gInput, $aCondition[, $iElement0 = -1, $xValue0 = -1[ ... [, $iElement11 = -1, $xValue11 = -1]]]) ; Parameters ....: $hGUI - Handle to the GUI in which the input control is located. ; $gInput - Control ID of the Input control to impose. ; $aCondition - Conditions array as returned by _InputImpose_Create() or _InputImpose_Duplicate(). ; $iElement,$xValue pairs - (up to 12 pairs) Conditions that will be updated into the given conditions array. ; Return values .: Returns the given Control ID ($gInput) if impose was needed, returns 0 if impose was not needed. ; Author ........: orbs ; Modified ......: ; Remarks .......: If $aCondition is somehow invalid, it is independently created as a local variable. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _InputImpose($hGUI, $gInput, $aCondition, $iElement0 = -1, $xValue0 = -1, $iElement1 = -1, $xValue1 = -1, $iElement2 = -1, $xValue2 = -1, $iElement3 = -1, $xValue3 = -1, $iElement4 = -1, $xValue4 = -1, $iElement5 = -1, $xValue5 = -1, $iElement6 = -1, $xValue6 = -1, $iElement7 = -1, $xValue7 = -1, $iElement8 = -1, $xValue8 = -1, $iElement9 = -1, $xValue9 = -1, $iElement10 = -1, $xValue10 = -1, $iElement11 = -1, $xValue11 = -1) ; validate conditions array If Not IsArray($aCondition) Or UBound($aCondition, 0) > 1 Or UBound($aCondition) <> $__INIM_CONDITIONCOUNT Then $aCondition = _InputImpose_Create() _InputImpose_Update($aCondition, $iElement0, $xValue0, $iElement1, $xValue1, $iElement2, $xValue2) _InputImpose_Update($aCondition, $iElement3, $xValue3, $iElement4, $xValue4, $iElement5, $xValue5) _InputImpose_Update($aCondition, $iElement6, $xValue6, $iElement7, $xValue7, $iElement8, $xValue8) _InputImpose_Update($aCondition, $iElement9, $xValue9, $iElement10, $xValue10, $iElement11, $xValue11) ; if $hGUI not in focus then nothing to do => return OK If Not WinActive($hGUI) Then Return 0 ; if $gInput not in focus then nothing to do => return OK If Not __InputImpose_GUICtrlHasFocus($hGUI, $gInput) Then Return 0 ; if no text to check then nothing to do => return OK Local $sInput = GUICtrlRead($gInput) If $sInput = '' Then Return 0 ; main Local $sChar Local $sInputNew = '' Local $sOccurredOnce = '' Local $bError = False For $i = 1 To StringLen($sInput) $sChar = StringMid($sInput, $i, 1) If ($aCondition[$__INIM_ALLOW_ANYWHERE] <> '' And Not StringInStr($aCondition[$__INIM_ALLOW_ANYWHERE] & $aCondition[$__INIM_ALLOW_FIRST] & $aCondition[$__INIM_ALLOW_LAST] & $aCondition[$__INIM_ALLOW_ONCE], $sChar)) Or _ ($aCondition[$__INIM_ALLOW_FIRST] <> '' And $i > 1 And StringInStr($aCondition[$__INIM_ALLOW_FIRST], $sChar)) Or _ ($aCondition[$__INIM_ALLOW_LAST] <> '' And $i < StringLen($sInput) And StringInStr($aCondition[$__INIM_ALLOW_LAST], $sChar)) Or _ (StringInStr($sOccurredOnce, $sChar)) Or _ ($aCondition[$__INIM_DISALLOW_ANYWHERE] <> '' And StringInStr($aCondition[$__INIM_DISALLOW_ANYWHERE], $sChar)) Or _ ($aCondition[$__INIM_DISALLOW_FIRST] <> '' And $i = 1 And StringInStr($aCondition[$__INIM_DISALLOW_FIRST], $sChar)) Or _ ($aCondition[$__INIM_DISALLOW_LAST] <> '' And $i = StringLen($sInput) And StringInStr($aCondition[$__INIM_DISALLOW_LAST], $sChar)) Then $bError = True Else $sInputNew &= $sChar If StringInStr($aCondition[$__INIM_ALLOW_ONCE], $sChar) Then $sOccurredOnce &= $sChar EndIf Next If ($aCondition[$__INIM_ENFORCE_NUMLOWERLIMIT] <> Null And Number($sInput) < $aCondition[$__INIM_ENFORCE_NUMLOWERLIMIT]) Or _ ($aCondition[$__INIM_ENFORCE_NUMUPPERLIMIT] <> Null And Number($sInput) > $aCondition[$__INIM_ENFORCE_NUMUPPERLIMIT]) Then $bError = True $sInputNew = '' EndIf Local $aPos If $bError Then If $aCondition[$__INIM_TOOLTIP_BYCURSOR] Then $aPos = MouseGetPos() Else $aPos = __InputImpose_CaretPos() EndIf GUICtrlSetData($gInput, $sInputNew) ToolTip($aCondition[$__INIM_TOOLTIP_TEXT], $aPos[0], $aPos[1] + 15, $aCondition[$__INIM_TOOLTIP_TITLE], 3, 1) Beep($aCondition[$__INIM_BEEP_FREQUENCY], $aCondition[$__INIM_BEEP_DURATION]) __InputImpose_WaitForUser($aCondition[$__INIM_TOOLTIP_TIMEOUT]) ToolTip('') Return $gInput EndIf Return 0 EndFunc ;==>_InputImpose ; #FUNCTION# ==================================================================================================================== ; Name ..........: _InputImpose_Create ; Description ...: Creates a conditions array. Values are set to default - see Remarks. ; Syntax ........: _InputImpose_Create([$iElement0 = -1, $xValue0 = -1[ ... [, $iElement11 = -1, $xValue11 = -1]]]) ; Parameters ....: $iElement,$xValue pairs (up to 14 pairs) - [optional] Conditions that will be updated into the array. ; Return values .: Returns a zero-based, 14-elements array. ; Author ........: orbs ; Modified ......: ; Remarks .......: All strings values are blank by default. ; ToolTip values are set as follows: ; text = "Press any key or move mouse to continue" ; title = "Unacceptabe Character" ; by cursor = false (i.e. position by caret) ; timeout = 0 (no timeout) ; Beep values are set as follows: ; frequency = 430 [Hz] ; duration = 300 [ms] ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _InputImpose_Create($iElement0 = -1, $xValue0 = -1, $iElement1 = -1, $xValue1 = -1, $iElement2 = -1, $xValue2 = -1, $iElement3 = -1, $xValue3 = -1, $iElement4 = -1, $xValue4 = -1, $iElement5 = -1, $xValue5 = -1, $iElement6 = -1, $xValue6 = -1, $iElement7 = -1, $xValue7 = -1, $iElement8 = -1, $xValue8 = -1, $iElement9 = -1, $xValue9 = -1, $iElement10 = -1, $xValue10 = -1, $iElement11 = -1, $xValue11 = -1, $iElement12 = -1, $xValue12 = -1, $iElement13 = -1, $xValue13 = -1) Local $aCondition[$__INIM_CONDITIONCOUNT] = ['', '', '', '', '', '', '', Null, Null, 'Press any key or move mouse to continue', 'Unacceptabe Character', False, 0, 430, 300] _InputImpose_Update($aCondition, $iElement0, $xValue0, $iElement1, $xValue1, $iElement2, $xValue2) _InputImpose_Update($aCondition, $iElement3, $xValue3, $iElement4, $xValue4, $iElement5, $xValue5) _InputImpose_Update($aCondition, $iElement6, $xValue6, $iElement7, $xValue7, $iElement8, $xValue8) _InputImpose_Update($aCondition, $iElement9, $xValue9, $iElement10, $xValue10, $iElement11, $xValue11) _InputImpose_Update($aCondition, $iElement12, $xValue12, $iElement13, $xValue13) Return $aCondition EndFunc ;==>_InputImpose_Create ; #FUNCTION# ==================================================================================================================== ; Name ..........: _InputImpose_Duplicate ; Description ...: Duplicates a conditions array. ; Syntax ........: _InputImpose_Duplicate($aCondition[, $iElement0 = -1, $xValue0 = -1[ ... [, $iElement13 = -1, $xValue13 = -1]]]) ; Parameters ....: $aCondition - Conditions array to be duplicated. ; $iElement,$xValue pairs - (up to 14 pairs) Conditions that will be updated into the duplicated array. ; Return values .: Success - Returns a conditions array identical to the given conditions array, updated as ordered. ; Failure - Returns the conditions array and sets @error to 1. A partial update may have been performed. ; Author ........: orbs ; Modified ......: ; Remarks .......: There is no validation of array size or contents! ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _InputImpose_Duplicate($aCondition, $iElement0 = -1, $xValue0 = -1, $iElement1 = -1, $xValue1 = -1, $iElement2 = -1, $xValue2 = -1, $iElement3 = -1, $xValue3 = -1, $iElement4 = -1, $xValue4 = -1, $iElement5 = -1, $xValue5 = -1, $iElement6 = -1, $xValue6 = -1, $iElement7 = -1, $xValue7 = -1, $iElement8 = -1, $xValue8 = -1, $iElement9 = -1, $xValue9 = -1, $iElement10 = -1, $xValue10 = -1, $iElement11 = -1, $xValue11 = -1, $iElement12 = -1, $xValue12 = -1, $iElement13 = -1, $xValue13 = -1) If Not _InputImpose_Update($aCondition, $iElement0, $xValue0, $iElement1, $xValue1, $iElement2, $xValue2) Then Return SetError(1, 0, $aCondition) If Not _InputImpose_Update($aCondition, $iElement3, $xValue3, $iElement4, $xValue4, $iElement5, $xValue5) Then Return SetError(1, 0, $aCondition) If Not _InputImpose_Update($aCondition, $iElement6, $xValue6, $iElement7, $xValue7, $iElement8, $xValue8) Then Return SetError(1, 0, $aCondition) If Not _InputImpose_Update($aCondition, $iElement9, $xValue9, $iElement10, $xValue10, $iElement11, $xValue11) Then Return SetError(1, 0, $aCondition) If Not _InputImpose_Update($aCondition, $iElement12, $xValue12, $iElement13, $xValue13) Then Return SetError(1, 0, $aCondition) Return $aCondition EndFunc ;==>_InputImpose_Duplicate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _InputImpose_Update ; Description ...: Updates an element of a given conditions array. ; Syntax ........: _InputImpose_Update(Byref $aCondition[, $iElement1, $xValue1[, $iElement2 = -1, $xValue2 = -1[, $iElement3 = -1, $xValue3 = -1)]]]) ; Parameters ....: $aCondition - [in/out] Conditions array. ; $iElement,$xValue pairs - (up to 3 pairs) Values that will be updated for their respective elements. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1. In this case, a partial update may have been performed. ; Author ........: orbs ; Modified ......: ; Remarks .......: There is no validation of array size or contents! ; $iElement1, $iElement2, and $iElement3 are referenced by the global constants declared in this UDF. You can ; update up to 3 elements in a single call to this function. For readability, it is recommended you use a single ; call for several $__INIM_ALLOW_* conditions, another distinct call for $__INIM_DISALLOW_*, another call for ; $__INIM_TOOLTIP_*, and another call for $__INIM_BEEP_* conditions. ; REGARDING THE CONDITION STRINGS: ; Only single characters are imposed. A string cannot be imposed. ; Characters can be grouped by specifying double-dot between limits. For example: ; - Condition string "0..9" implies all digits. ; - Condition string "A..Za..z" implies all english letters, uppercase and lowercase. ; REGARDING THE BALLOON TOOLTIP AND BEEP: ; If you specify empty strings for the tooltip and zero values for the beep, then the only indication the user ; has that an invalid character was removed is that... well... it was removed. This is useful if you want to ; handle the notification yourself. In this case, use the _InputImpose function return value to determine if a ; notification is due, for example: If _InputImpose(...) Then MsgBox(...) ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _InputImpose_Update(ByRef $aCondition, $iElement1 = -1, $xValue1 = -1, $iElement2 = -1, $xValue2 = -1, $iElement3 = -1, $xValue3 = -1) ; update array If $iElement1 <> -1 Then $aCondition[$iElement1] = $xValue1 If $iElement2 <> -1 Then $aCondition[$iElement2] = $xValue2 If $iElement3 <> -1 Then $aCondition[$iElement3] = $xValue3 ; parse full valid characters string for all string elements Local $aStringElement For $iCondition = 0 To 6 If StringRight($aCondition[$iCondition], 2) = '..' Or StringInStr($aCondition[$iCondition], '...') Then Return SetError(1, 0, 0) $aStringElement = StringSplit($aCondition[$iCondition], '..', 1) If $aStringElement[0] > 1 Then $aCondition[$iCondition] = '' For $iStringElement = 1 To $aStringElement[0] - 1 $aCondition[$iCondition] &= $aStringElement[$iStringElement] For $iChar = Asc(StringRight($aStringElement[$iStringElement], 1)) + 1 To Asc(StringLeft($aStringElement[$iStringElement + 1], 1)) - 1 $aCondition[$iCondition] &= Chr($iChar) Next Next $aCondition[$iCondition] &= $aStringElement[$aStringElement[0]] EndIf Next Return 1 EndFunc ;==>_InputImpose_Update ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__InputImpose_GUICtrlHasFocus ;__InputImpose_CaretPos ;__InputImpose_WaitForUser ;__InputImpose_GetIdleTime ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __InputImpose_GUICtrlHasFocus ; Description ...: Checks if a specific control in a specific GUI has focus. ; Syntax ........: __InputImpose_GUICtrlHasFocus($hGUI, $gControl) ; Parameters ....: $hGUI - Handle to the GUI in which the control is located. ; $gControl - Control ID of the control to check. ; Return values .: Returns 1 if the control has focus. ; Returns 0 if the control does not have focus. ; Author ........: ; Modified ......: ; Remarks .......: Adopted from the link below. Several versions of this functions exist in the forum. ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/topic/162416-edit-control-post-processing-to-checkformat-the-input/ ; Example .......: No ; =============================================================================================================================== Func __InputImpose_GUICtrlHasFocus($hGUI, $gControl) Local $hControl = ControlGetHandle($hGUI, "", ControlGetFocus($hGUI)) If $hControl <> ControlGetHandle($hGUI, "", $gControl) Then Return 0 ; lose focus If $hControl = ControlGetHandle($hGUI, "", $gControl) Then Return 1 ; has focus EndFunc ;==>__InputImpose_GUICtrlHasFocus ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __InputImpose_CaretPos ; Description ...: Returns the coordinates of the caret in the foreground window. ; Syntax ........: __InputImpose_CaretPos() ; Parameters ....: None ; Return values .: Success - Returns a 2-element array containing the following information: ; $array[0] = X coordinate ; $array[1] = Y coordinate ; Failure - Returns an empty 2-element array and sets @error to 1 ; Author ........: ; Modified ......: ; Remarks .......: Adopted from the AutoIt help example for WinGetCaretPos() ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __InputImpose_CaretPos() Local $aReturnIfError[2] Opt("CaretCoordMode", 0) ;relative mode Local $c = WinGetCaretPos() ;relative caret coords Local $w = WinGetPos("") ;window's coords Local $f = ControlGetFocus("", "") ;text region "handle" Local $e = ControlGetPos("", "", $f) ;text region coords Local $t[2] If IsArray($c) And IsArray($w) And IsArray($e) Then $t[0] = $c[0] + $w[0] + $e[0] $t[1] = $c[1] + $w[1] + $e[1] Return $t ;absolute screen coords of caret cursor Else Return SetError(1, 0, $aReturnIfError) EndIf EndFunc ;==>__InputImpose_CaretPos ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __InputImpose_WaitForUser ; Description ...: Waits until user activity (key press or mouse move) occurs. ; Syntax ........: __InputImpose_WaitForUser([$nTimeout = 0[,$nInterval = 100]]) ; Parameters ....: $nTimeout - [optional] Timeout [sec] for return even if no user activity occurred. Default is 0 (no timeout). ; $nInterval - [optional] Internal loop sleep parameter [ms]. Default is 100. ; Return values .: None ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __InputImpose_WaitForUser($nTimeout = 0, $nInterval = 100) Local $nIdleTimeStart, $nIdleTimeCurrent Local $hTimer = TimerInit() While True Sleep($nInterval) If $nTimeout > 0 And TimerDiff($hTimer) > $nTimeout * 1000 Then Return $nIdleTimeCurrent = __InputImpose_GetIdleTime() If $nIdleTimeCurrent < $nIdleTimeStart Then Return $nIdleTimeStart = $nIdleTimeCurrent WEnd EndFunc ;==>__InputImpose_WaitForUser ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __InputImpose_GetIdleTime ; Description ...: Returns the number of ticks since last user activity (key press or mouse move). ; Syntax ........: __InputImpose_GetIdleTime() ; Parameters ....: None ; Return values .: Success - Returns time since last activity, in ticks (approx milliseconds). ; Also sets @extended to 1 if rollover of ticks counter has occured. ; Failure - Returns 0 and sets @error and @extended as set by internal DLL calls. ; Author ........: ; Modified ......: ; Remarks .......: This function is exact copy of _Timer_GetIdleTime() from the Timers UDF. It was copied here in order to avoid ; needlessly including another UDF. ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __InputImpose_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); Local $aResult = DllCall("user32.dll", "bool", "GetLastInputInfo", "struct*", $tStruct) If @error Or $aResult[0] = 0 Then Return SetError(@error, @extended, 0) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "dword", "GetTickCount") If @error Or Not $aResult[0] Then Return SetError(@error, @extended, 0) ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff < 0 Then Return SetExtended(1, $avTicks[0]) ; Rollover of ticks counter has occured ; Normal return Return $iDiff EndFunc ;==>__InputImpose_GetIdleTime the example script: #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include "InputImpose.au3" #cs example input #1: using $ES_NUMBER for user experience reference example input #2 and #3: create conditions array, update it (by human-logical groups), impose it in main loop example input #4: simultaneously duplicate and update a conditions array, impose it in main loop example input #5: simultaneously create and update a conditions array, simultaneously apply a temporary update and impose it in main loop example input #6: single function call to temporary create, update and impose the conditions in main loop #ce Global $hGUI = GUICreate('InputImpose Example', 310, 185) GUISetBkColor(0xFEDCBA) Global $y = 5 GUICtrlCreateLabel('$ES_NUMBER:', 10, $y + 3) Global $gInput0 = GUICtrlCreateInput('', 100, $y, 200, 20, $ES_NUMBER) $y += 30 GUICtrlCreateLabel('Positive,Decimal:', 10, $y + 3) Global $gInput1 = GUICtrlCreateInput('', 100, $y, 200, 20) ; only digits and decimal point, custom tooltip text, no tooltip title, timeout 3 sec., higher pitch beep Global $aCondition1 = _InputImpose_Create() _InputImpose_Update($aCondition1, $__INIM_ALLOW_ANYWHERE, '0..9', $__INIM_ALLOW_ONCE, '.') _InputImpose_Update($aCondition1, $__INIM_TOOLTIP_TEXT, 'Only a Positive number (Whole or Decimal) is allowed', $__INIM_TOOLTIP_TIMEOUT, 3) _InputImpose_Update($aCondition1, $__INIM_BEEP_FREQUENCY, 700) $y += 30 GUICtrlCreateLabel('Negative,Whole:', 10, $y + 3) Global $gInput2 = GUICtrlCreateInput('', 100, $y, 200, 20) ; only digits and leading minus, custom tooltip text & title Global $aCondition2 = _InputImpose_Create() _InputImpose_Update($aCondition2, $__INIM_ALLOW_ANYWHERE, '0..9', $__INIM_ALLOW_FIRST, '-') _InputImpose_Update($aCondition2, $__INIM_ENFORCE_NUMLOWERLIMIT, -100, $__INIM_ENFORCE_NUMUPPERLIMIT, 100) _InputImpose_Update($aCondition2, $__INIM_TOOLTIP_TEXT, 'Only a Whole number (Positive or Negative) is allowed, in range -100 to 100 (included).', $__INIM_TOOLTIP_TITLE, 'Invalid Entry') $y += 30 GUICtrlCreateLabel('Negative,Decimal:', 10, $y + 3) Global $gInput3 = GUICtrlCreateInput('', 100, $y, 200, 20) ; same as before, but with a decimal point allowed, and naturally a matching tooltip text to match Global $aCondition3 = _InputImpose_Duplicate($aCondition2, $__INIM_ALLOW_ONCE, '.', $__INIM_TOOLTIP_TEXT, 'Only a number is allowed.') $y += 30 GUICtrlCreateLabel('Math Expression:', 10, $y + 3) Global $gInput4 = GUICtrlCreateInput('', 100, $y, 120, 20) ; any math expression Global $aCondition4 = _InputImpose_Create($__INIM_ALLOW_ANYWHERE, '0..9.-+*/^()') Global $gInput4_Calc = GUICtrlCreateButton('=', 225, $y, 20, 20) GUICtrlSetCursor(-1, 0) GUICtrlSetTip(-1, 'Evaluate Expression') GUICtrlSetState(-1, $GUI_DEFBUTTON) Global $gOutput4 = GUICtrlCreateInput('', 250, $y, 50, 20, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $ES_RIGHT)) Global $sResult GUICtrlSetBkColor(-1, 0xD4D4D4) $y += 30 GUICtrlCreateLabel('File Name:', 10, $y + 3) Global $gInput5 = GUICtrlCreateInput('', 100, $y, 200, 20) GUISetState() Global $msg = 0 While $msg <> $GUI_EVENT_CLOSE _InputImpose($hGUI, $gInput1, $aCondition1) _InputImpose($hGUI, $gInput2, $aCondition2) _InputImpose($hGUI, $gInput3, $aCondition3) _InputImpose($hGUI, $gInput4, $aCondition4, $__INIM_TOOLTIP_TEXT, '') ; no tooltip (blank text implies blamk title), just beep _InputImpose($hGUI, $gInput5, -1, $__INIM_DISALLOW_ANYWHERE, '\/:*?"<>|', $__INIM_TOOLTIP_TEXT, 'The following characters are not allowed: ' & @CR & '\ / : * ? " < > |', $__INIM_TOOLTIP_TITLE, 'Invalid Entry') $msg = GUIGetMsg() If $msg = $gInput4_Calc Then $sResult = Execute(GUICtrlRead($gInput4)) If @error Then GUICtrlSetData($gOutput4, '') MsgBox(16, 'Evaluation Error', 'The expression could not be evaluated. You can NOT rely on InputImpose to validate a math expression!', 0, $hGUI) Else GUICtrlSetData($gOutput4, $sResult) EndIf EndIf WEnd
    1 point
  3. Syntax is like this: So I think this should look like this: #include "include\personaludf.au3"
    1 point
  4. spudw2k, that's a good idea but perhaps a bit extreme in the absence of any apparent threat. White-listing has the virtue of offering complete control of access, but comes with problems of its own.
    1 point
  5. You could configure your firewall to block all traffic and start "white listing". An aggressive approach to a problem which begs for it.
    1 point
  6. JohnOne

    AU4 Library

    I think you might be missing the point of this. C++ code is everything, this is about converting AutoIt to C++.
    1 point
  7. All I do is check "On resume, display logon screen" in my screen saver settings. This effectively locks the computer if your screen saver starts. My script is them simply, launch screensaver. #Include <WinAPI.au3> #Include <WindowsConstants.au3> Global Const $SC_SCREENSAVE = 0XF140 _SendMessage(_WinAPI_GetDesktopWindow(), $WM_SYSCOMMAND, $SC_SCREENSAVE, 0)
    1 point
  8. Interesting... Is the computer configured to use an MS Live account for auth or is it a local account? Just for my curiosity.
    1 point
  9. careca, Works fine for me: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScrollbarConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() GUIRegisterMsg($WM_MOUSEWHEEL, "_WM_MOUSEWHEEL") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Local $iDirn = ( (BitShift($wParam, 16) > 0) ? ($SB_LINEUP) : ($SB_LINEDOWN) ) Switch $iDirn Case $SB_LINEDOWN ConsoleWrite("Down" & @CRLF) Case $SB_LINEUP ConsoleWrite("Up" & @CRLF) EndSwitch Return $GUI_RUNDEFMSG EndFunc M23
    1 point
  10. jguinch

    A way to store arrays

    Sorry iloveyou, it was a bug. I edited my UDF. Can you retry ? @czardas : I didn't see your post in #7 : cool !
    1 point
  11. @JohnOne I'm assuming (as I think spudw2k is referring to) that you're just seeing network traffic, not necessarily uploading to the web specifically. Am I correct? I can tell you that certificate propagation can be disabled unless you are using smart cards in your environment; while on it is checking in with A.D. to see if there is a GPO that affects smartcard certs, so it may generate some traffic (can't see it being 15MB but you may have a combo of things going on). BITS uses background bandwidth to transfer files between PCs, so you could definitely be seeing some traffic from that one. A lot of applications use BITS, beyond the MS apps like Windows Updates, so you'll have to test disabling it. Lastly, the IP Helper service does some background work for IPv4 to IPv6 tunneling. If you are not using IPv6 you can probably test disabling it. I have seen where that generates some traffic.
    1 point
  12. My first guess would be BITS. Have you disabled AU Uploads? http://www.howtogeek.com/224981/how-to-stop-windows-10-from-uploading-updates-to-other-pcs-over-the-internet/ There are a few services listed that are network-centric, but I'd be shocked if they we're uploading to the web. Having said that, I can't rule it out for sure. I'm not familiar enough with the Cert Propagatation service to know if it does web communication, but it's a candidate as well (15MB worth though...unsure).
    1 point
  13. You can use the macros @MDAY, @Month , @Year and concatenating operator & for assigning data to variable. Therfore it would be helpfull to read the Language Reference in Helpfile (Datatypes, Variables, Macros, Operators)
    1 point
  14. JohnOne

    Help making a code

    To get you started, here is some modified code to work like I imagine you thought it would. $sPath = "C:\Documents and Settings\User\Desktop\test.txt" $sFile = "test.txt" Loading_values() Func Loading_values() If FileExists($sPath) Then ShellExecute($sPath) WinWaitActive($sFile) Sleep(750) Send("{SHIFTDOWN}" & "{END}" & "{DOWN 64}" & "{SHIFTUP}" & "{APPSKEY}" & "{c}" & "{DEL}") EndIf EndFunc ;==>Loading_values
    1 point
  15. czardas

    A way to store arrays

    Perhaps you should try _ArrayToDeclarationString() and _ArrayDeclareFromString() by jguinch. I quite like that. https://www.autoitscript.com/forum/topic/179779-_arraydeclarefromstring-_arraytodeclarationstring-_arrayshufflemultidim-_arraycompare-_arrayenumvalues-_arrayassign/
    1 point
  16. When you need to access Excel files without Excel being installed you could use ADO: Or check my ADO tutorial in the wiki including example scripts. Or check mLipok's ADO UDF (but it is still a Beta version):
    1 point
  17. #include <File.au3> #include <Array.au3> ; List all the files in the current script directory. Local $aScriptDir = _FileListToArray(@ScriptDir) ; Create a file in the users %TEMP% directory. Local $sFilePath = @TempDir & "\Examples.txt" ; Write array to a file by passing the file name. _FileWriteFromArray($sFilePath, $aScriptDir, 1) ; Display the file. ShellExecute($sFilePath) Local $aNewScriptDir _FileReadToArray($sFilePath, $aNewScriptDir) _ArrayDisplay($aNewScriptDir)
    1 point
  18. You can also use paexec, or scheduled task, on your vm/remote session, to have the script run behind the desktop on session 0. paexec also has the added ability to copy your compiled script to the other session, and then execute it.
    1 point
  19. Maybe something with admin rights? Do you have #requireadmin in your script? @edit: Have you tried to start it manually - doest it work ? Try shellexecute instead of RUN.
    1 point
  20. RTFC

    How computers work

    Hey, don't put yourself down like that, JohnOne. It's a good question; it's just that a CPU is an incredibly sophisticated and complicated piece of kit (other chips on the motherboard are much simpler beasts, with the possible exception of the GPU), so the moment you leave the highest abstraction layer, you slide down the rabbit hole and have to deal with odd analogies to get a handle on what's going on (funnily enough, when you dig even deeper to the core hardware, things appear to get simpler, but then quantum effects start to kick in and then you're truly lost). But if everyone were satisfied just clicking buttons and sharing cat videos, we'd never get anywhere interesting and new.
    1 point
  21. Haven't looked at your code. But for the connection string have a look here : https://www.connectionstrings.com/teradata/ And for the access have a look at this DB2 example #include <Date.au3> ; Global Variables Global $adUseServer = 2 Global $adUseClient = 3 ; Initialize COM error handler Global $oMyError = ObjEvent('AutoIt.Error', 'MyErrFunc') Global $provider = 'IBMDADB2', $IP, $port, $userID, $password, $connection_Obj ;~ Global $DSN = 'DSPZ4988' ;~ Global $DSN = 'DSPP1102' ;~ Global $DSN = 'DSPP6011' ;~ Global $DSN = 'DSPI4962' ;~ Global $DSN = 'DSPI4845' ;~ Global $DSN = 'DSPS4964' ;~ Global $DSN = 'DSPW4937' ;~ Global $DSN = 'DSPP4924' Global $DSN = 'DSPP6011' If StringInStr($DSN, 'DSPP') <> 0 Then $userID = 'db2read' $password = 'xxx' Else $userID = 'xgcoge1' $password = 'xxx' EndIf $connection_Obj = _connectDB($provider, $IP, $port, $DSN, $userID, $password) If $connection_Obj = -1 Then Exit (1) ;~ Local $sqlRs = ObjCreate('ADODB.Recordset') ;~ _displayTable($connection_Obj, 'SELECT * FROM "DSPTSPT"."DIM_ZEIT"') While 1 Local $sqlRs = ObjCreate('ADODB.Recordset') If Not @error Then $sqlRs.open('SELECT TXT_SCHLUESSEL_ERLAEUTERUNG FROM "DSPTMCP"."WERTEBEREICHE_DEFINITION" WHERE "BEZ_SCHLUESSEL" = ''TSP_ETL3_RUN''', $connection_Obj) ;~ $sqlRs.open('SELECT max(ID_ZEIT) FROM "DSPTSPT"."DIM_ZEIT"', $connection_Obj) If Not @error Then $re_A = $sqlRs.GetRows() If $re_A[0][0] <> 'Transformer läuft...' Then MsgBox(64, 'Transformer', 'Transformer beendet um : ' & $re_A[0][0]) $connection_Obj.close Exit (0) EndIf ConsoleWrite($re_A[0][0] & ': ' & _Now() & @CRLF) $sqlRs.close EndIf EndIf Sleep(10000 * 3) WEnd ;~ _displayTable($connection_Obj, 'SELECT TXT_SCHLUESSEL_ERLAEUTERUNG FROM "DSPTMCP"."WERTEBEREICHE_DEFINITION" WHERE "BEZ_SCHLUESSEL" = ''TSP_ETL3_RUN''') Func _connectDB($provider, $IP, $port, $DSN, $userID, $password) Local $sqlCon = ObjCreate('ADODB.Connection') ;~ $sqlCon.Mode = 16 ; Erlaubt im MultiUser-Bereich das öffnen anderer Verbindungen ohne Beschränkungen [Lesen/Schreiben/Beides] $sqlCon.Mode = 0 ; Erlaubt im MultiUser-Bereich das öffnen anderer Verbindungen ohne Beschränkungen [Lesen/Schreiben/Beides] $sqlCon.CursorLocation = 2;$adUseClient ; client side cursor Schreiben beim Clienten ;~ $sqlCon.Open('Provider=' & $provider & ';IP=' & $IP & ';Port=' & $port & ';DSN=' & $DSN & ';User ID=' & $userID & ';Password=' & $password) ; XP $sqlCon.Open('Provider=' & $provider & ';Server=' & $IP & ':' & $port & ';DSN=' & $DSN & ';UID=' & $userID & ';PWD=' & $password) ; win 7 If @error Then Return -1 Return $sqlCon EndFunc ;==>_connectDB Func _getColumns($sqlCon, $SQL) Local $sqlRs = ObjCreate('ADODB.Recordset') If Not @error Then $sqlRs.open($SQL, $sqlCon) If Not @error Then For $i = 0 To $sqlRs.Fields.Count - 1 ConsoleWrite($sqlRs.Fields($i).Name & @CRLF) Next $sqlRs.close EndIf EndIf EndFunc ;==>_getColumns Func _displayTable($sqlCon, $SQL) Local $sqlRs = ObjCreate('ADODB.Recordset') If Not @error Then $sqlRs.open($SQL, $sqlCon) If Not @error Then Local $header[$sqlRs.Fields.Count], $rows For $i = 0 To $sqlRs.Fields.Count - 1 $header[$i] = $sqlRs.Fields($i).Name Next $rows = $sqlRs.GetRows() $sqlRs.close EndIf EndIf _ArrayDisplay_WithHeader($rows, $header) EndFunc ;==>_displayTable Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, 'COM Test', 'We intercepted a COM Error !' & @CRLF & @CRLF & _ 'err.description is: ' & @TAB & $oMyError.description & @CRLF & _ 'err.windescription:' & @TAB & $oMyError.windescription & @CRLF & _ 'err.number is: ' & @TAB & $HexNumber & @CRLF & _ 'err.lastdllerror is: ' & @TAB & $oMyError.lastdllerror & @CRLF & _ 'err.scriptline is: ' & @TAB & $oMyError.scriptline & @CRLF & _ 'err.source is: ' & @TAB & $oMyError.source & @CRLF & _ 'err.helpfile is: ' & @TAB & $oMyError.helpfile & @CRLF & _ 'err.helpcontext is: ' & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns EndFunc ;==>MyErrFunc ;~ _executeSQLonDB2Recordset($Obj, "insert into " & "Autoit" & "values('Xenobiologist', 'User')") Func _executeSQLonDB2Recordset($sqlCon, $SQL) Local $sqlRs = ObjCreate('ADODB.Recordset') $sqlRs.open('SELECT * FROM Autoit', $sqlCon) If Not @error Then $sqlRs.Source = "Select * From Autoit" ; ganze Tabelle $sqlRs.AddNew ;'Neuen Datensatz erzeugen ;~ 'Beispiele für Zuweisung von Werten an Tabellenfelder $sqlRs.Fields("Name") = "MEGA" $sqlRs.Fields("Job") = "MEGAMAN" $sqlRs.Update $sqlRs.close EndIf EndFunc ;==>_executeSQLonDB2Recordset ;$OptionVal = $sqlRs.Fields ('LAST_NAME' ).Value ;~ MsgBox(0, 'Record Found', 'Name: ' & $OptionName );& @CRLF & 'Value: ' & $OptionVal) ;~ $sqlRs.FIELDS(''' & $OptionName & ''') = '.F.' ; ADDED THIS LINE ; $sqlRs.Update ; ADDED THIS LINE ;~ Driver=IBMDADB2 ;~ _getColumns($connection_Obj, 'SELECT * FROM "BI1VSNR"."AGENTURMANDANT"') ;~ _displayTable($connection_Obj, 'SELECT * FROM "BI1VSNR"."AGENTURMANDANT"') ;~ _getColumns($connection_Obj, 'update "BI1TSNR"."AGENTURMANDANT" set "SL_BATCH_STATUS"=39 where "NR_MANDANT"=CAST(10300201 AS INTEGER)') ;~ _displayTable($connection_Obj, 'SELECT * FROM "DSPTXMC"."DIM_KNZ_GRUPPE"') ;~ _SQL_Execute($connection_Obj, "insert into DSPTXMC.FAKT_KENNZAHLEN values ('501', '2002-12-31-12.00.00.000000', '2010-11-20-13.39.13.000000', '4983', '2500000', NULL, '22.0', NULL)") ;~ _displayTable($connection_Obj, 'SELECT * FROM "DSPTMCP"."WERTEBEREICHE_DEFINITION" WHERE "BEZ_SCHLUESSEL" = ''TSP_ETL3_RUN''') ;~ _getColumns($connection_Obj, 'SELECT * FROM "DSPTMCP"."WERTEBEREICHE_DEFINITION" WHERE "BEZ_SCHLUESSEL" = ''TSP_ETL3_RUN''') Func _ArrayDisplay_WithHeader(Const ByRef $avArray, $header, $sTitle = "Array: ListView Display", $iItemLimit = -1, $iTranspose = 0, $sSeparator = "", $sReplace = "|") If Not IsArray($avArray) Then Return SetError(1, 0, 0) ; Dimension checking Local $iDimension = UBound($avArray, 0), $iUBound = UBound($avArray, 1) - 1, $iSubMax = UBound($avArray, 2) - 1 If $iDimension > 2 Then Return SetError(2, 0, 0) ; Separator handling ;~ If $sSeparator = "" Then $sSeparator = Chr(1) If $sSeparator = "" Then $sSeparator = Chr(124) ; Declare variables Local $i, $j, $vTmp, $aItem, $avArrayText, $sHeader = "Row", $iBuffer = 64 Local $iColLimit = 250, $iLVIAddUDFThreshold = 4000, $iWidth = 640, $iHeight = 480 Local $iOnEventMode = Opt("GUIOnEventMode", 0), $sDataSeparatorChar = Opt("GUIDataSeparatorChar", $sSeparator) ; Swap dimensions if transposing If $iSubMax < 0 Then $iSubMax = 0 If $iTranspose Then $vTmp = $iUBound $iUBound = $iSubMax $iSubMax = $vTmp EndIf ; Set limits for dimensions If $iSubMax > $iColLimit Then $iSubMax = $iColLimit If $iItemLimit = 1 Then $iItemLimit = $iLVIAddUDFThreshold If $iItemLimit < 1 Then $iItemLimit = $iUBound If $iUBound > $iItemLimit Then $iUBound = $iItemLimit If $iLVIAddUDFThreshold > $iUBound Then $iLVIAddUDFThreshold = $iUBound ; Set header up For $i = 0 To UBound($header) - 1 $sHeader &= $sSeparator & $header[$i] Next ; Convert array into text for listview Local $avArrayText[$iUBound + 1] For $i = 0 To $iUBound $avArrayText[$i] = "[" & $i & "]" For $j = 0 To $iSubMax ; Get current item If $iDimension = 1 Then If $iTranspose Then $vTmp = $avArray[$j] Else $vTmp = $avArray[$i] EndIf Else If $iTranspose Then $vTmp = $avArray[$j][$i] Else $vTmp = $avArray[$i][$j] EndIf EndIf ; Add to text array $vTmp = StringReplace($vTmp, $sSeparator, $sReplace, 0, 1) $avArrayText[$i] &= $sSeparator & $vTmp ; Set max buffer size $vTmp = StringLen($vTmp) If $vTmp > $iBuffer Then $iBuffer = $vTmp Next Next $iBuffer += 1 ; GUI Constants Local Const $_ARRAYCONSTANT_GUI_DOCKBORDERS = 0x66 Local Const $_ARRAYCONSTANT_GUI_DOCKBOTTOM = 0x40 Local Const $_ARRAYCONSTANT_GUI_DOCKHEIGHT = 0x0200 Local Const $_ARRAYCONSTANT_GUI_DOCKLEFT = 0x2 Local Const $_ARRAYCONSTANT_GUI_DOCKRIGHT = 0x4 Local Const $_ARRAYCONSTANT_GUI_EVENT_CLOSE = -3 Local Const $_ARRAYCONSTANT_LVIF_PARAM = 0x4 Local Const $_ARRAYCONSTANT_LVIF_TEXT = 0x1 Local Const $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH = (0x1000 + 29) Local Const $_ARRAYCONSTANT_LVM_GETITEMCOUNT = (0x1000 + 4) Local Const $_ARRAYCONSTANT_LVM_GETITEMSTATE = (0x1000 + 44) Local Const $_ARRAYCONSTANT_LVM_INSERTITEMA = (0x1000 + 7) Local Const $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE = (0x1000 + 54) Local Const $_ARRAYCONSTANT_LVM_SETITEMA = (0x1000 + 6) Local Const $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT = 0x20 Local Const $_ARRAYCONSTANT_LVS_EX_GRIDLINES = 0x1 Local Const $_ARRAYCONSTANT_LVS_SHOWSELALWAYS = 0x8 Local Const $_ARRAYCONSTANT_WS_EX_CLIENTEDGE = 0x0200 Local Const $_ARRAYCONSTANT_WS_MAXIMIZEBOX = 0x00010000 Local Const $_ARRAYCONSTANT_WS_MINIMIZEBOX = 0x00020000 Local Const $_ARRAYCONSTANT_WS_SIZEBOX = 0x00040000 Local Const $_ARRAYCONSTANT_tagLVITEM = "int Mask;int Item;int SubItem;int State;int StateMask;ptr Text;int TextMax;int Image;int Param;int Indent;int GroupID;int Columns;ptr pColumns" Local $iAddMask = BitOR($_ARRAYCONSTANT_LVIF_TEXT, $_ARRAYCONSTANT_LVIF_PARAM) Local $tBuffer = DllStructCreate("char Text[" & $iBuffer & "]"), $pBuffer = DllStructGetPtr($tBuffer) Local $tItem = DllStructCreate($_ARRAYCONSTANT_tagLVITEM), $pItem = DllStructGetPtr($tItem) DllStructSetData($tItem, "Param", 0) DllStructSetData($tItem, "Text", $pBuffer) DllStructSetData($tItem, "TextMax", $iBuffer) ; Set interface up Local $hGUI = GUICreate($sTitle, $iWidth, $iHeight, 10, 10, BitOR($_ARRAYCONSTANT_WS_SIZEBOX, $_ARRAYCONSTANT_WS_MINIMIZEBOX, $_ARRAYCONSTANT_WS_MAXIMIZEBOX)) Local $aiGUISize = WinGetClientSize($hGUI) Local $hListView = GUICtrlCreateListView($sHeader, 0, 0, $aiGUISize[0], $aiGUISize[1] - 26, $_ARRAYCONSTANT_LVS_SHOWSELALWAYS) Local $hCopy = GUICtrlCreateButton("Copy Selected", 3, $aiGUISize[1] - 23, $aiGUISize[0] - 6, 20) GUICtrlSetResizing($hListView, $_ARRAYCONSTANT_GUI_DOCKBORDERS) GUICtrlSetResizing($hCopy, $_ARRAYCONSTANT_GUI_DOCKLEFT + $_ARRAYCONSTANT_GUI_DOCKRIGHT + $_ARRAYCONSTANT_GUI_DOCKBOTTOM + $_ARRAYCONSTANT_GUI_DOCKHEIGHT) GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_GRIDLINES, $_ARRAYCONSTANT_LVS_EX_GRIDLINES) GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT, $_ARRAYCONSTANT_LVS_EX_FULLROWSELECT) GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETEXTENDEDLISTVIEWSTYLE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE, $_ARRAYCONSTANT_WS_EX_CLIENTEDGE) ; Fill listview For $i = 0 To $iLVIAddUDFThreshold GUICtrlCreateListViewItem($avArrayText[$i], $hListView) Next For $i = ($iLVIAddUDFThreshold + 1) To $iUBound $aItem = StringSplit($avArrayText[$i], $sSeparator) DllStructSetData($tBuffer, "Text", $aItem[1]) ; Add listview item DllStructSetData($tItem, "Item", $i) DllStructSetData($tItem, "SubItem", 0) DllStructSetData($tItem, "Mask", $iAddMask) GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_INSERTITEMA, 0, $pItem) ; Set listview subitem text DllStructSetData($tItem, "Mask", $_ARRAYCONSTANT_LVIF_TEXT) For $j = 2 To $aItem[0] DllStructSetData($tBuffer, "Text", $aItem[$j]) DllStructSetData($tItem, "SubItem", $j - 1) GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_SETITEMA, 0, $pItem) Next Next ; ajust window width $iWidth = 0 For $i = 0 To $iSubMax + 1 $iWidth += GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETCOLUMNWIDTH, $i, 0) Next If $iWidth < 250 Then $iWidth = 230 WinMove($hGUI, "", Default, Default, $iWidth + 20) ; Show dialog GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $_ARRAYCONSTANT_GUI_EVENT_CLOSE ExitLoop Case $hCopy Local $sClip = "" ; Get selected indices [ _GUICtrlListView_GetSelectedIndices($hListView, True) ] Local $aiCurItems[1] = [0] For $i = 0 To GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($hListView, $_ARRAYCONSTANT_LVM_GETITEMSTATE, $i, 0x2) Then $aiCurItems[0] += 1 ReDim $aiCurItems[$aiCurItems[0] + 1] $aiCurItems[$aiCurItems[0]] = $i EndIf Next ; Generate clipboard text If Not $aiCurItems[0] Then For $sItem In $avArrayText $sClip &= $sItem & @CRLF Next Else For $i = 1 To UBound($aiCurItems) - 1 $sClip &= $avArrayText[$aiCurItems[$i]] & @CRLF Next EndIf ClipPut($sClip) EndSwitch WEnd GUIDelete($hGUI) Opt("GUIOnEventMode", $iOnEventMode) Opt("GUIDataSeparatorChar", $sDataSeparatorChar) Return 1 EndFunc ;==>_ArrayDisplay_WithHeader ;~ _printDB2Recordset($Obj, 'SELECT * FROM "BI1VSNR"."AGENTURMANDANT"') ;~ Func _printDB2Recordset($sqlCon, $SQL) ;~ Local $sqlRs = ObjCreate('ADODB.Recordset') ;~ If Not @error Then ;~ $sqlRs.open($SQL, $sqlCon) ;~ If Not @error Then ;~ ;Loop until the end of file ;~ While Not $sqlRs.EOF ;~ ;Retrieve data from the following fields ;~ ConsoleWrite($sqlRs.Fields('Nr_Mandant' ).Value & @CRLF) ;~ ConsoleWrite($sqlRs.Fields(1).Value & @CRLF) ;~ ConsoleWrite($sqlRs.Fields('COUNTRY' ).Value & @CRLF) ;~ $sqlRs.MoveNext ;~ WEnd ;~ $sqlRs.close ;~ EndIf ;~ EndIf ;~ EndFunc ;==>_printDB2Recordset
    1 point
  22. orbs

    Com port Query

    alternative, using WMI: code adapted from: http://artisgeek.com/weblog/scripts/-getdevices-autoit/ #include <Array.au3> $aDeviceList=_getDevices('Silicon Labs CP210x USB to UART Bridge',1) _ArrayDisplay($aDeviceList) ;Function Name: Get (Connected) Devices ;Written By: Amin Babaeipanah ;Usage: _getDevices(1,'') ;_getDevices("search for", flag) ;"search for": can be set to empty to list everything ;flag: ; 1 = List Device Name(s) ; 2 = List Device ID(s) ; 3 = List Device Name(s) @ Device ID(s) ;Example 1: ; Code below will list all the connected devices by name ; _getDevices('',1) ; Code below will list all the connected devices by ID ; _getDevices('',2) ; Code below will list all the connected devices by name that has the word "COM" ; _getDevices('COM',1) ; adaptation: replace ConsoleWrite with array return ; adaptation by: orbs ; original source at: http://artisgeek.com/weblog/scripts/-getdevices-autoit/ Func _getDevices($name,$type) Dim $aDeviceList[1]=[0] Local $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2') Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%"&$name&"%'", "WQL", 48) If IsObj($colItems) Then If $type = 1 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.Name ;ConsoleWrite($objItem.Name&@LF) Next ElseIf $type = 2 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.PNPDeviceID ;ConsoleWrite($objItem.PNPDeviceID&@LF) Next ElseIf $type = 3 Then For $objItem In $colItems $aDeviceList[0]+=1 ReDim $aDeviceList[$aDeviceList[0]+1] $aDeviceList[$aDeviceList[0]]=$objItem.Name&'@'&$objItem.PNPDeviceID ;ConsoleWrite($objItem.Name&'@'&$objItem.PNPDeviceID&@LF) Next EndIf EndIf Return $aDeviceList EndFunc the function returns an array of all devices by criteria (name or type). calling he function with your device name will return (hopefully) only one result, then use string manipulation - like _StringBetween() - to parse the port.
    1 point
  23. Another way: use array alternatives (object) like i.e. System.Collections.ArrayList or Scripting.Dictionary. So you can increase/decrease your array object without ReDim. Here an example: $ObjList = ObjCreate("System.Collections.ArrayList") ; create $ObjList.Add($VALUE) ; add value $VALUE = $ObjList.Item($Index) ; get value $ObjList.Remove($VALUE) ; delete by name $ObjList.RemoveAt($Index) ; delete by index $Array = $ObjList.ToArray ; list to array ; and more... $oDICT = ObjCreate('Scripting.Dictionary') $oDICT.Add($KEY, $VALUE) ; add pair (key/value) $VALUE = $oDICT.Item($KEY) ; get value $oDICT.Item($KEY) = $VALUE ; set value $oDICT.Remove($KEY) ; delete key $oDICT.RemoveAll ; delete all keys ; and more...
    1 point
×
×
  • Create New...