Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/23/2016 in all areas

  1. 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
    2 points
  2. Since I disovered FreeBasic I decided to create a DLL to implement much faster image processing functionality to AutoIt. Following functions are implemented yet: _GDIPlus_BitmapApplyFilter_BWJJNDithering _GDIPlus_BitmapApplyFilter_BWBayerOrderedDithering _GDIPlus_BitmapApplyFilter_Cartoon1 _GDIPlus_BitmapApplyFilter_ColorAccent _GDIPlus_BitmapApplyFilter_Convolution_AnotherBlur _GDIPlus_BitmapApplyFilter_Convolution_BoxBlur _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection1 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection2 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection3 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection4 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection5 _GDIPlus_BitmapApplyFilter_Convolution_EdgeDetection6 _GDIPlus_BitmapApplyFilter_Convolution_Emboss1 _GDIPlus_BitmapApplyFilter_Convolution_Emboss45Degree _GDIPlus_BitmapApplyFilter_Convolution_EmbossTopLeftBottomRight _GDIPlus_BitmapApplyFilter_Convolution_Gaussian3x3 _GDIPlus_BitmapApplyFilter_Convolution_Gaussian5x5_1 _GDIPlus_BitmapApplyFilter_Convolution_Gaussian5x5_2 _GDIPlus_BitmapApplyFilter_Convolution_GaussianBlur _GDIPlus_BitmapApplyFilter_Convolution_IntenseEmboss _GDIPlus_BitmapApplyFilter_Convolution_Kirsch _GDIPlus_BitmapApplyFilter_Convolution_Laplace1 _GDIPlus_BitmapApplyFilter_Convolution_Laplace2 _GDIPlus_BitmapApplyFilter_Convolution_Laplace3 _GDIPlus_BitmapApplyFilter_Convolution_LaplacianOfGaussian _GDIPlus_BitmapApplyFilter_Convolution_ManualMatrix _GDIPlus_BitmapApplyFilter_Convolution_MotionBlur _GDIPlus_BitmapApplyFilter_Convolution_Outline3x3 _GDIPlus_BitmapApplyFilter_Convolution_Prewitt _GDIPlus_BitmapApplyFilter_Convolution_Sharpen1 _GDIPlus_BitmapApplyFilter_Convolution_Sharpen2 _GDIPlus_BitmapApplyFilter_Convolution_Sobel _GDIPlus_BitmapApplyFilter_Convolution_SovelVsPrewitt _GDIPlus_BitmapApplyFilter_Convolution_TriangleBlur _GDIPlus_BitmapApplyFilter_Convolution_Unsharp _GDIPlus_BitmapApplyFilter_Convolution_Unsharp5x5 _GDIPlus_BitmapApplyFilter_Delaunay _GDIPlus_BitmapApplyFilter_Dilatation _GDIPlus_BitmapApplyFilter_DistortionBlur _GDIPlus_BitmapApplyFilter_Edges _GDIPlus_BitmapApplyFilter_Erosion _GDIPlus_BitmapApplyFilter_FakeGreyscale _GDIPlus_BitmapApplyFilter_FishEye _GDIPlus_BitmapApplyFilter_Indexed _GDIPlus_BitmapApplyFilter_Jitter _GDIPlus_BitmapApplyFilter_Kuwahara _GDIPlus_BitmapApplyFilter_Linellism _GDIPlus_BitmapApplyFilter_Median _GDIPlus_BitmapApplyFilter_Median2 _GDIPlus_BitmapApplyFilter_Mosaic _GDIPlus_BitmapApplyFilter_OilPainting _GDIPlus_BitmapApplyFilter_Open _GDIPlus_BitmapApplyFilter_PenSketch _GDIPlus_BitmapApplyFilter_PenSketch2 _GDIPlus_BitmapApplyFilter_Pixelate _GDIPlus_BitmapApplyFilter_Pointillism _GDIPlus_BitmapApplyFilter_RadialBlur _GDIPlus_BitmapApplyFilter_Raster _GDIPlus_BitmapApplyFilter_Spiral _GDIPlus_BitmapApplyFilter_Swirl _GDIPlus_BitmapApplyFilter_SymmetricNearestNeighbour _GDIPlus_BitmapApplyFilter_TiltShift _GDIPlus_BitmapApplyFilter_TimeWarp _GDIPlus_BitmapApplyFilter_Ver _GDIPlus_BitmapApplyFilter_Wave _GDIPlus_BitmapApplyFilter_XRay Since I am absolutely a newbie in FreeBasic, the DLL may contain errors. Please report any bug. FreeBasic source code can be found here: https://pastebin.com/Lugp6rCR To do: add function headers with descriptions speed-up FB code -> partly done add more filters -> ongoing Credits to: Jakub Szymanowski rdc Dewald Esterhuizen Santhosh G_ Christian Graus www.gutgames.com Have fun. You can compare the speed with AutoIt version: #AutoIt3Wrapper_Version=b #include <Array.au3> #include <GDIPlus.au3> Global $sFile = FileOpenDialog("Select an image", "", "Images (*.jpg;*.png;*.gif;*.bmp)") If @error Then Exit _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global Const $hImage = _GDIPlus_ImageLoadFromFile($sFile) Global Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Global Const $hGUI = GUICreate("GDI+ Image Filters", $iW * 2, $iH) Global $fProg = 0, $iEnd = $iW * $iH - 1 AdlibRegister("Progress", 490) Global $t = TimerInit() Global Const $hGDIBitmap = _GDIPlus_BitmapApplyFilter_Median($hImage, 4) ConsoleWrite(Round(TimerDiff($t) / 1000, 2) & " s / " & Round(TimerDiff($t) / 60000, 2) & " min" & @CRLF) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW - 1, $iH - 1) Global Const $iPic_o = GUICtrlCreatePic("", $iW, 0, $iW - 1, $iH - 1) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap)) Global Const $hGDIBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic_o, $STM_SETIMAGE, $IMAGE_BITMAP, $hGDIBitmap2)) GUISetState() AdlibUnRegister("Progress") ToolTip("") Do Until GUIGetMsg() = -3 _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hGDIBitmap) _WinAPI_DeleteObject($hGDIBitmap2) _GDIPlus_Shutdown() Exit Func Progress() ToolTip(Int($fProg / $iEnd * 100) & " % / " & Round(TimerDiff($t) / 60000, 2) & " min", MouseGetPos(0) + 30, MouseGetPos(1) + 30) EndFunc #Region Symmetric Nearest Neighbour Func _GDIPlus_BitmapApplyFilter_SymmetricNearestNeighbour($hImage, $fRadius = 2, $bGDI = True) ;no alpha channel implemented yet Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iRowOffset, $iX, $iY, $c, $k, $sumR, $sumG, $sumB, $iCount, $xx, $yy, $iR, $iG, $iB, $iR1, $iG1, $iB1, $iR2, $iG2, $iB2, $x, $y For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW For $iX = 0 To $iW - 1 $sumR = 0 $sumG = 0 $sumB = 0 $iCount = 0 $c = DllStructGetData($tPixel, 1, $iRowOffset + $iX) $iR = BitShift(BitAND(0x00FF0000, $c), 16) $iG = BitShift(BitAND(0x0000FF00, $c), 8) $iB = BitAND(0x000000FF, $c) For $yy = -$fRadius To $fRadius For $xx = -$fRadius To $fRadius $k = $iX + $xx $x = $k < 0 ? 0 : $k > $iW - 1 ? $iW - 1 : $k $k = $iY + $yy $y = $k < 0 ? 0 : $k > $iH - 1 ? $iH - 1 : $k $c = DllStructGetData($tPixel, 1, $y * $iW + $x) $iR1 = BitShift(BitAND(0x00FF0000, $c), 16) $iG1 = BitShift(BitAND(0x0000FF00, $c), 8) $iB1 = BitAND(0x000000FF, $c) $k = $iX - $xx $x = $k < 0 ? 0 : $k > $iW - 1 ? $iW - 1 : $k $k = ($iY - $yy) $y = $k < 0 ? 0 : $k > $iH - 1 ? $iH - 1 : $k $c = DllStructGetData($tPixel, 1, $y * $iW + $x) $iR2 = BitShift(BitAND(0x00FF0000, $c), 16) $iG2 = BitShift(BitAND(0x0000FF00, $c), 8) $iB2 = BitAND(0x000000FF, $c) If __DeltaE($iR, $iG, $iB, $iR1, $iG1, $iB1) < __DeltaE($iR, $iG, $iB, $iR2, $iG2, $iB2) Then $sumR += $iR1 $sumG += $iG1 $sumB += $iB1 Else $sumR += $iR2 $sumG += $iG2 $sumB += $iB2 EndIf $iCount += 1 Next Next DllStructSetData($tPixel_Dest, 1, 0xFF000000 + Int($sumR / $iCount) * 0x10000 + Int($sumG / $iCount) * 0x100 + Int($sumB / $iCount), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_SNN" & $fRadius & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc Func __DeltaE($iR1, $iG1, $iB1, $iR2, $iG2, $iB2) Return Sqrt(($iR1 - $iR2) * ($iR1 - $iR2) + ($iG1 - $iG2) * ($iG1 - $iG2) + ($iB1 - $iB2) * ($iB1 - $iB2)) EndFunc #EndRegion #Region Jitter Func _GDIPlus_BitmapApplyFilter_Jitter($hImage, $iAmount = 20, $bGDI = True) Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iX, $iY, $iRowOffset, $fNX, $fNY For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW + 1 For $iX = 0 To $iW - 1 $fNX = $iX + Int((Random() - 0.5) * $iAmount) $fNX = $fNX < 1 ? 1 : $fNX > $iW - 1 ? $iW - 1 : $fNX $fNY = ($iY + Int((Random() - 0.5) * $iAmount)) $fNY = $fNY < 1 ? 1 : $fNY > $iH - 1 ? $iH - 1 : $fNY $fNY *= $iW DllStructSetData($tPixel_Dest, 1, DllStructGetData($tPixel, 1, $fNY + $fNX), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_Jitter" & $iAmount & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc #EndRegion #Region Median Func _GDIPlus_BitmapApplyFilter_Median($hImage, $fRadius = 3, $bGDI = True) Local Const $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap_Dest = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $tBitmapData_Dest = _GDIPlus_BitmapLockBits($hBitmap_Dest, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) Local Const $iScan0_Dest = DllStructGetData($tBitmapData_Dest, "Scan0") Local Const $tPixel_Dest = DllStructCreate("int[" & $iW * $iH & "];", $iScan0_Dest) Local Const $tBitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW - 1, $iH - 1, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local Const $iScan0 = DllStructGetData($tBitmapData, "Scan0") Local Const $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0) Local $iX, $iY, $iRowOffset For $iY = 0 To $iH - 1 $iRowOffset = $iY * $iW + 1 For $iX = 0 To $iW - 1 DllStructSetData($tPixel_Dest, 1, __Median_Value($iX, $iY, $fRadius, $tPixel, $iW, $iH), $iRowOffset + $iX) $fProg += 1 Next Next _GDIPlus_BitmapUnlockBits($hImage, $tBitmapData) _GDIPlus_BitmapUnlockBits($hBitmap_Dest, $tBitmapData_Dest) _GDIPlus_ImageSaveToFile($hBitmap_Dest, @ScriptDir & "\Filter_Median" & $fRadius & "_" & @YEAR & @MON & @MDAY & @MIN & @SEC & ".png") If $bGDI Then Local $hGDIBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_Dest) _GDIPlus_BitmapDispose($hBitmap_Dest) Return $hGDIBitmap EndIf Return $hBitmap_Dest EndFunc Func __Median_Value($iPosX, $iPosY, $fRadius, $tPixel, $iW, $iH) Local $iX, $iY, $aColors[1000], $iColors = 0, $iSize = $iW * $iH - 1, $iOff, $e For $iX = $iPosX - $fRadius To $iPosX + $fRadius For $iY = $iPosY - $fRadius To $iPosY + $fRadius $iOff = 1 + $iY * $iW + $iX $aColors[$iColors] = DllStructGetData($tPixel, 1, $iOff < 1 ? 1 : $iOff > $iSize ? $iSize : $iOff) $iColors += 1 Next Next ReDim $aColors[$iColors] ;~ _ArraySort($aColors, 0) $e = $iColors - 1 __ArrayQuickSort1D($aColors, 0, $e) Local $iMid = Floor($iColors / 2), $iMedian If BitAND($iColors, 1) Then $iMedian = Int($aColors[$iMid + 1]) Else $iMedian = Int(($aColors[$iMid] + $aColors[$iMid + 1]) / 2) EndIf Return $iMedian EndFunc #EndRegion _GDIPlus_BitmapApplyFilter v0.9.8 build 2024-04-17 beta.7z
    1 point
  3. J2TeaM

    Font Icon UDF

    This is an UDF that helps you use Font Awesome in your AutoIt project. Screenshot Download Click here to download! Usage/Example #NoTrayIcon #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; Font Icon UDF by Juno_okyo #include <font-icon.au3> Opt('GUIOnEventMode', 1) #Region ### START Koda GUI section ### Global $FormMain = GUICreate('Font Icon for AutoIt by Juno_okyo', 355, 126, -1, -1) GUISetFont(20, 400, 0, 'Arial') GUISetOnEvent($GUI_EVENT_CLOSE, 'FormMainClose') GUIStartGroup() Global $Label1 = GUICtrlCreateLabel('Juno_okyo', 25, 42, 155, 36) GUICtrlSetFont(-1, 24, 400, 0, 'Arial') ; See demo.html for Icon name Global $Label2 = GUICtrlCreateLabel(Font_Icon('icon-heart'), 193, 46, 35, 36) GUICtrlSetFont(-1, 20, 400, 0, 'juno_okyo') ; Font name GUICtrlSetColor(-1, 0xa83f39) ; Heart color ;) Global $Label3 = GUICtrlCreateLabel('AutoIt', 235, 42, 90, 36) GUICtrlSetFont(-1, 24, 400, 0, 'Arial') GUIStartGroup() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func FormMainClose() Exit EndFunc Credits Author: Juno_okyo Font Awesome by Dave Gandy Source code on GitHub. Contributing are welcome!
    1 point
  4. Hello Guys! I wanted to share all my knowledge on arrays! Hope may enjoy the article , Lets start! Declaring arrays! Declaring arrays is a little different than other variables: ; Rules to follow while declaring arrays: ; ; Rule #1: You must have a declarative keyword like Dim/Global/Local before the declaration unless the array is assigned a value from a functions return (Ex: StringSplit) ; Rule #2: You must declare the number of dimensions but not necessarily the size of the dimension if you are gonna assign the values at the time of declaration. #include <Array.au3> Local $aEmptyArray[0] ; Creates an Array with 0 elements (aka an Empty Array). Local $aArrayWithData[1] = ["Data"] _ArrayDisplay($aEmptyArray) _ArrayDisplay($aArrayWithData) That's it Resizing Arrays Its easy! Just like declaring an empty array! ReDim is our friend here: #include <Array.au3> Local $aArrayWithData[1] = ["Data1"] ReDim $aArrayWithData[2] ; Change the number of elements in the array, I have added an extra element! $aArrayWithData[1] = "Data2" _ArrayDisplay($aArrayWithData) Just make sure that you don't use ReDim too often (especially don't use it in loops!), it can slow down you program. Best practice of using "Enum" You might be wondering what they might be... Do you know the Const keyword which you use after Global/Local keyword? Global/Local are declarative keywords which are used to declare variables, of course, you would know that already by now , If you check the documentation for Global/Local there is a optional parameter called Const which willl allow you to "create a constant rather than a variable"... Enum is similar to Const, it declares Integers (ONLY Integers): Global Enum $ZERO, $ONE, $TWO, $THREE, $FOUR, $FIVE, $SIX, $SEVEN, $EIGHT, $NINE ; And so on... ; $ZERO will evaluate to 0 ; $ONE will evaluate to 1 ; You get the idea :P ; Enum is very useful to declare Constants each containing a number (starting from 0) This script will demonstrate the usefulness and neatness of Enums : ; We will create an array which will contain details of the OS Global Enum $ARCH, $TYPE, $LANG, $VERSION, $BUILD, $SERVICE_PACK Global $aOS[6] = [@OSArch, @OSType, @OSLang, @OSVersion, @OSBuild, @OSServicePack] ; Now, if you want to access anything related to the OS, you would do this: ConsoleWrite(@CRLF) ConsoleWrite('+>' & "Architecture: " & $aOS[$ARCH] & @CRLF) ConsoleWrite('+>' & "Type: " & $aOS[$TYPE] & @CRLF) ConsoleWrite('+>' & "Langauge: " & $aOS[$LANG] & @CRLF) ConsoleWrite('+>' & "Version: " & $aOS[$VERSION] & @CRLF) ConsoleWrite('+>' & "Build: " & $aOS[$BUILD] & @CRLF) ConsoleWrite('+>' & "Service Pack: " & $aOS[$SERVICE_PACK] & @CRLF) ConsoleWrite(@CRLF) ; Isn't it cool? XD You can use this in your UDF(s) or Program(s), it will look very neat! Looping through an Array Looping through an array is very easy! . There are 2 ways to loop an array in AutoIt! Simple Way: ; This is a very basic way to loop through an array ; In this way we use a For...In...Next Loop! Global $aArray[2] = ["Foo", "Bar"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $vElement In $aArray ; $vElement will contain the value of the elements in the $aArray... one element at a time. ConsoleWrite($vElement & @CRLF) ; Prints the element out to the console Next ; And that's it! Advanced Way: ; This is an advanced way to loop through an array ; In this way we use a For...To...Next Loop! Global $aArray[4] = ["Foo", "Bar", "Baz", "Quack"] ; Create an array ; This loop will loop 2 times because our $aArray contains 2 elements. For $i = 0 To UBound($aArray) - 1 ; $i is automatically created and is set to zero, UBound($aArray) returns the no. of elements in the $aArray. ConsoleWrite($aArray[$i] & @CRLF) ; Prints the element out to the console. Next ; This is the advanced way, we use $i to access the elements! ; With the advanced method you can also use the Step keyword to increase the offset in each "step" of the loop: ; This will only print every 2nd element starting from 0 ConsoleWrite(@CRLF & "Every 2nd element: " & @CRLF) For $i = 0 To UBound($aArray) - 1 Step 2 ConsoleWrite($aArray[$i] & @CRLF) Next ; This will print the elements in reverse order! ConsoleWrite(@CRLF & "In reverse: " & @CRLF) For $i = UBound($aArray) - 1 To 0 Step -1 ConsoleWrite($aArray[$i] & @CRLF) Next ; And that ends this section! For some reason, many people use the advance way more than the simple way . For more examples of loops see this post by @FrancescoDiMuro! Interpreting Multi-Dimensional Arrays Yeah, its the most brain squeezing problem for newbies, Imagining an 3D Array... I will explain it in a very simple way for ya, so stop straining you brain now! . This way will work for any array regardless of its dimensions... Ok, Lets start... You can imagine an array as a (data) mine of information: ; Note that: ; Dimension = Level (except the ground level :P) ; Element in a Dimension = Path ; Level 2 ----------\ ; Level 1 -------\ | ; Level 0 ----\ | | ; v v v Local $aArray[2][2][2] ; \-----/ ; | ; v ; Ground Level ; As you can see that $aArray is the Ground Level ; All the elements start after the ground level, i.e from level 0 ; Level 0 Contains 2 different paths ; Level 1 Contains 4 different paths ; Level 2 Contains 8 different paths ; When you want too fill some data in the data mine, ; You can do that like this: $aArray[0][0][0] = 1 $aArray[0][0][1] = 2 $aArray[0][1][0] = 3 $aArray[0][1][1] = 4 $aArray[1][0][0] = 5 $aArray[1][0][1] = 6 $aArray[1][1][0] = 7 $aArray[1][1][1] = 8 ; Don't get confused with the 0s & 1s, Its just tracing the path! ; Try to trace the path of a number with the help of the image! Its super easy! :D I hope you might have understand how an array looks, Mapping your way through is the key in Multi-Dimensional arrays, You take the help of notepad if you want! Don't be shy! Frequently Asked Questions (FAQs) & Their answers Q #1. What are Arrays? A. An Array is an datatype of an variable (AutoIt has many datatypes of variables like "strings", "integers" etc. Array is one of them). An Array can store information in a orderly manner. An Array consist of elements, each element can be considered as a variable (and yes, each element has its own datatype!). AutoIt can handle 16,777,216 elements in an Array, If you have an Array with 16,777,217 elements then AutoIt crashes. Q #2. Help! I get an error while declaring an Array!? A. You tried to declare an array like this: $aArray[1] = ["Data"] That is not the right way, Array is a special datatype, since its elements can be considered as individual variables you must have an declarative keyword like Dim/Global/Local before the declaration, So this would work: Local $aArray[1] = ["Data"] Q #3. How can I calculate the no. of elements in an array? A. The UBound function is your answer, Its what exactly does! If you have an multi-dimensional Array you can calculate the total no. of elements in that dimension by specifying the dimension in the second parameter of UBound Q #4. Why is my For...Next loop throwing an error while processing an Array? A. You might have done something like this: #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) ; Concentrate here! $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Did you notice the mistake? UBound returns the no. of elements in an array with the index starting from 1! That's right, you need to remove 1 from the total no. of elements in order to process the array because the index of an array starts with 0! So append a simple - 1 to the statment: #include <MsgBoxConstants.au3> Local $aArray[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Local $iMyNumber = 0 For $i = 0 To UBound($aArray) - 1 $iMyNumber += $aArray[$i] Next MsgBox($MB_OK, "Sum of all Numbers!", $iMyNumber) Q #5. Can an Array contain an Array? How do I access an Array within an Array? A. Yes! It is possible that an Array can contain another Array! Here is an example of an Array within an Array: ; An Array can contain another Array in one of its elements ; Let me show you an example of what I mean ;) #include <Array.au3> Global $aArray[2] $aArray[0] = "Foo" Global $aChildArray[1] = ["Bar"] $aArray[1] = $aChildArray _ArrayDisplay($aArray) ; Did you see that!? The 2nd element is an {Array} :O ; But how do we access it??? ; You almost guessed it, like this: ; Just envolope the element which contains the {Array} (as shown in _ArrayDisplay) with brackets (or parentheses)! :D ConsoleWrite(($aArray[1])[0]) ; NOTE the brackets () around $aArray[1]!!! They are required or you would get an syntax error! ; So this: $aArray[1][0] wont work! More FAQs coming soon!
    1 point
  5. jchd

    StringRegExp Question

    $var = ";&amp;u=http://www.example.com/news/&amp;prev=" StringRegExp($var, '(?i)&amp;u=(http://.+?)&') Maybe that (there was a spurious / in pattern), maybe not. BTW, no need to escape slash, semi-column or ampersand in pattern.
    1 point
  6. That's what Google tells me. http://www.snb-vba.eu/VBA_Dictionary_en.html#L_3
    1 point
  7. mikell

    StringRegExp Question

    How could you get a response with so little information about the text to treat and the expected result ?!
    1 point
  8. Put quotes around the parm. $parm2 = '"Program Files"'
    1 point
  9. Melba23

    On Error Resume Next

    vicsar, I have replied to your PM. Your code snippet in indeed "complete rubbish" and deserves to be called as such. Sorry you took offence at that remark, but I am afraid that is the truth and I would be remiss if I did not point it out. I carefully pointed out why this was the case and how the code should have been structured - I do not see how this "prevents other from learning", nor how it would "intimidate" them as you suggested in your PM. You can see from JLogan3o13's response above that I am not alone in viewing my response in that light. If you post any snippets of that quality again you will no doubt get a similar response, from myself or another experienced user. Might I suggest that you post asking whether your approach is correct rather than immediately claiming that you have a solution - that way everyone will be able to learn, which is why we are all here in the first place. M23
    1 point
  10. What you mean ? DLL Version ? there is property $oQP.LibraryVersion
    1 point
  11. 1 point
  12. Here ya go! For $i = 1 To 9999 $sNumStr = StringFormat("%04i", $i) ConsoleWrite($sNumStr & @CRLF) Next
    1 point
  13. crappy, Welcome to the AutoIt forums. Not too difficult - and even easier if you use my GUIScrollbars_Ex UDF (look in my sig for the link): #include <GUIConstantsEx.au3> #include <GUIScrollBars_Ex.au3> ; Create main GUI $hGUI = GUICreate("Test", 500, 500) ; Create ListView $cLV = GUICtrlCreateListView("Column 0|Column 1", 0, 400, 500, 100) For $i = 0 To 10 GUICtrlCreateListViewItem("Item " & $i, $cLV) Next GUISetState() ; Now create the child GUI $hGUI_Child = GUICreate("Child", 500, 400, 0, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) For $i = 0 To 10 GUICtrlCreateLabel("Item " & $i, 10, 0 + ($i * 50), 480, 30) GUICtrlSetBkColor(-1, 0xFFCCCC) Next GUISetState() ; Add teh scrollbars to the child - the parametr is the bottom of the final label added _GUIScrollbars_Generate($hGUI_Child, 0, 530) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd please ask if you have any questions. M23
    1 point
×
×
  • Create New...