Roshith Posted December 10, 2010 Share Posted December 10, 2010 Hi, I want a GUI input to hold only numbers and decimal point. I created the Input with the style $ES_NUMBER (0x2000). But it does not accept decimal point. Could someone help Thanks in advance.. Link to comment Share on other sites More sharing options...
GEOSoft Posted December 10, 2010 Share Posted December 10, 2010 (edited) A wee bit of your code would have made this a touch simpler. I'll proceed on the assumption that you are using a message loop. In your GUI messgage loop While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch If StringRegExp(GUICtrlRead($my_input), "[^\d\.]" Then GUICtrlSetData($my_input, StringRegExpReplace(GuiCtrlRead($my_input), "[^\d\.]", "")) WEnd Edit: Forgot to add that you have to remove the $ES_NUMBER style Edited December 10, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 11, 2010 Moderators Share Posted December 11, 2010 Roshith,Welcome to the AutoIt forum. Something I developed a while ago - it allows only digits, a decimal point and a leading minus. Set $iDecimal to the number of decimal places required: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Global $iDecimal = 3 GUICreate("Input Filter", 300, 30, -1, -1) Global $inTest = GUICtrlCreateInput("", 5, 5, 290) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord Local $iCode = BitShift($wParam, 16) ;HiWord If $iIDFrom = $inTest And $iCode = $EN_CHANGE Then $Read_Input = GUICtrlRead($inTest) If StringRegExp($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]') Then $Read_Input = StringRegExpReplace($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]', '\1') $Point1 = StringInStr($Read_Input, ".", 0) $Point2 = StringInStr($Read_Input, ".", 0, 2) If $Point2 <> 0 Then $Read_Input = StringLeft($Read_Input, $Point2 - 1) If $Point1 <> 0 Then $Read_Input = StringLeft($Read_Input, $Point1 + $iDecimal) GUICtrlSetData($inTest, $Read_Input) EndIf EndFunc;==>_WM_COMMANDPlease ask if you have any questions. M23 Xandy 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
funkey Posted December 11, 2010 Share Posted December 11, 2010 There is a great UDF doing this and more:I always use this one becaus $ES_NUMBER is much to less. Xandy 1 Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Roshith Posted December 11, 2010 Author Share Posted December 11, 2010 This is Awesome.. Thank you very much. I really appreciate the quick response. Link to comment Share on other sites More sharing options...
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