faustf Posted March 17, 2016 Posted March 17, 2016 hi guy i saw the oprtion of inputbox have es_number work correctly but only with integer nuber , if i have a double like 12.23 or 12,23 exist an specific option?? thankz
jguinch Posted March 17, 2016 Posted March 17, 2016 Are you talking about an InputBox (with the InputBox function) or an edit control ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
faustf Posted March 17, 2016 Author Posted March 17, 2016 $Input1 = GUICtrlCreateInput("Input1", 184, 64, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER)) GUISetState(@SW_SHOW) like this but if number have decimal , not go
faustf Posted March 17, 2016 Author Posted March 17, 2016 i answer me i create this solution is not so much pretty style Func _control_numb($stringa) Local $string_correct = StringReplace($stringa, ',', '.') Local $de = StringIsDigit($string_correct) If $de = 1 Then MsgBox(0, '', 'è un numero') Else Local $de2 = StringIsFloat($string_correct) If $de2 = 1 Then MsgBox(0, '', 'è un numero2') Else MsgBox(0, '', 'non è un numero !!!') EndIf EndIf EndFunc ;==>_control_numb
jguinch Posted March 17, 2016 Posted March 17, 2016 (edited) You can also use something like this : expandcollapse popup#Include <EditConstants.au3> #Include <GuiConstantsEx.au3> #include <GuiEdit.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate("gui") $edit = GUICtrlCreateInput("", 10, 10, 200, 25) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _CheckInput() Local Static $sPreviousValue Local $sVal = GUICtrlRead($edit), $aSel If StringRegExp($sVal, "^\d+\.?\d*$") Then $sPreviousValue = $sVal Else $aSel = _GUICtrlEdit_GetSel ( $edit ) GUICtrlSetData($edit, $sPreviousValue) _GUICtrlEdit_SetSel ( $edit, $aSel[0] - 1, $aSel[1] - 1 ) EndIf EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = _WinAPI_LoWord($wParam) Local $iCode = _WinAPI_HiWord($wParam) Switch $iIDFrom Case $edit Switch $iCode Case $EN_UPDATE _CheckInput() EndSwitch EndSwitch EndFunc Edited March 17, 2016 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
mikell Posted March 17, 2016 Posted March 17, 2016 A little simpler #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> $gui = GUICreate("test", 300, 200) $input = GUICtrlCreateInput("", 50, 50, 200, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUISetState() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $IdFrom, $iCode, $read $IdFrom = BitAnd($wParam, 0x0000FFFF) $iCode = BitShift($wParam, 16) Switch $IdFrom Case $input Switch $iCode Case $EN_UPDATE $read = GUICtrlRead($input) If not StringRegExp($read, "^\d+\.?\d*$") Then GUICtrlSetData($input, StringTrimRight($read, 1)) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc mLipok 1
jguinch Posted March 17, 2016 Posted March 17, 2016 @mikell, if the user wants to add a character in the middle... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
alien4u Posted March 18, 2016 Posted March 18, 2016 14 hours ago, jguinch said: You can also use something like this : expandcollapse popup#Include <EditConstants.au3> #Include <GuiConstantsEx.au3> #include <GuiEdit.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> GUICreate("gui") $edit = GUICtrlCreateInput("", 10, 10, 200, 25) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _CheckInput() Local Static $sPreviousValue Local $sVal = GUICtrlRead($edit), $aSel If StringRegExp($sVal, "^\d+\.?\d*$") Then $sPreviousValue = $sVal Else $aSel = _GUICtrlEdit_GetSel ( $edit ) GUICtrlSetData($edit, $sPreviousValue) _GUICtrlEdit_SetSel ( $edit, $aSel[0] - 1, $aSel[1] - 1 ) EndIf EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = _WinAPI_LoWord($wParam) Local $iCode = _WinAPI_HiWord($wParam) Switch $iIDFrom Case $edit Switch $iCode Case $EN_UPDATE _CheckInput() EndSwitch EndSwitch EndFunc You can't delete the edit content, not the first character, maybe this line: _GUICtrlEdit_SetSel ( $edit, $aSel[0] - 1, $aSel[1] - 1 ) Work around? Check if Backspace key or DEL key is pressed? Kind Regards Alien.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now