Sign in to follow this  
Followers 0
Roshith

Input with only Numbers and decimal point

5 posts in this topic

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..

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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!"

Share this post


Link to post
Share on other sites

Roshith,

Welcome to the AutoIt forum. :x

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: :P

#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_COMMAND

Please ask if you have any questions. :shifty:

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

There is a great UDF doing this and more:

I always use this one becaus $ES_NUMBER is much to less.

1 person likes this

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

This is Awesome.. Thank you very much. I really appreciate the quick response. :x

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0