Jump to content
Sign in to follow this  
trescon

Input with Number et point decimal

Recommended Posts

trescon

Hi, I utilizzatio to the following command interface.

GUICtrlCreateInput("0000", 350, 300, 60, 27, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT, $ES_NUMBER))

Which, however, makes me write only the numbers but not the decimal point, so I can not enter the numemro 12:45 but only 12.

There is one possible to make mous that I can type only numbers and the decimal point?

thanks


Thank You

Alberto

---------------------------------------------------

I am translate with Google.

Share this post


Link to post
Share on other sites
FireFox

Hi,

There are some examples from to the end of the page.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
PhoenixXL

Example

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>


;In the Following Example the numbers and the Colon(:) can be entered into the Edit control only.


Global $Chars, $hInput

GUICreate('Test', 220, 180)
GUICtrlCreateInput('', 10, 10, 200, 20)

;Check StringRegExp function in the Helpfile to learn about Meta-characters what is here "\d" stands for digit
_SetAllowedChars(GUICtrlGetHandle(-1),'\d:')

;Register WM_COMMAND
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

GUISetState()


While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)
If $ilParam <> $hInput Then Return $GUI_RUNDEFMSG

Static $spText = ''
$nNotifyCode = _WinAPI_HiWord($iwParam)

Switch $nNotifyCode
Case $EN_CHANGE
$nID = _WinAPI_LoWord($iwParam) ;Control ID
$sText = GUICtrlRead($nID) ; THe Text in the Control

If StringRegExp($sText, '^[' & $Chars & ']*$') = 0 Then ; IF the Text is not Valid
GUICtrlSetData($nID, $spText) ;Erase the Text
Else
$spText = $sText
EndIf
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _SetAllowedChars($hEdit, $sChars)
;Check if the Chars input is valid
StringRegExp("", '^[' & $sChars & ']$')
If @error = 2 Then Return SetError(1, @error, @extended)

$Chars = $sChars
$hInput = $hEdit

EndFunc   ;==>_SetAllowedChars
Thumbs up if it helped

Regards :)

  • Like 1

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
chun914

how to make it works for more than 1 input...

$input1

$input2

$input3

I'm not sure how can i set the parameter, thanks

Share this post


Link to post
Share on other sites
chun914

one more question is it possible to show the tip text when user entered a not allowed char ?

Share this post


Link to post
Share on other sites
PhoenixXL

Here is the way

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <Array.au3>

Global $Chars[1], $hInput[1], $s_Tip[1], $Index

GUICreate('Test', 220, 180)
GUICtrlCreateInput('', 10, 10, 200, 20)

;Check StringRegExp function in the Helpfile to learn about Meta-characters what is here "\d" stands for digit
;In the Following edit the numbers and the Colon(:) can be entered into the Edit control only.
_SetAllowedChars(GUICtrlGetHandle(-1), '\d:', "Only digits and colon can be entered")
If @error Then Exit -1

;In the Following edit alphanum can be entered into the Edit control only.
GUICtrlCreateInput('', 10, 50, 200, 20)
_SetAllowedChars(GUICtrlGetHandle(-1), '[:alnum:]', "Alphabets and Numbers only allowed")
If @error Then Exit -2

;Register WM_COMMAND
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

GUISetState()


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $imsg, $iwParam, $ilParam)

    Static $s_Text = ''

    $i_Found = _ArraySearch($hInput, $ilParam)
    If @error Then Return $GUI_RUNDEFMSG

    Local $nNotifyCode = _WinAPI_HiWord($iwParam), _
            $nID = _WinAPI_LoWord($iwParam), _ ;Control ID
            $sText = GUICtrlRead($nID) ; THe Text in the Control


    If $i_Found >= 0 And $i_Found <> $Index Then
        $Index = $i_Found
        $s_Text = ""
    EndIf

    Switch $nNotifyCode
        Case $EN_CHANGE

            If StringRegExp($sText, '^[' & $Chars[$Index] & ']*$') = 0 Then ; IF the Text is not Valid

                GUICtrlSetData($nID, $s_Text) ;Erase the Text

                ;Show the balloon tip
                _GUICtrlEdit_ShowBalloonTip($hInput[$Index], "Invalid Char", $s_Tip[$Index], $TTI_WARNING)
                AdlibRegister("HideBalloonTip", 2500) ;set the balloon tip to hide in 2.5secs.

            Else
                $s_Text = $sText

            EndIf
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _SetAllowedChars($hEdit, $sChars, $s_ErrorTip)
    ;Check if the Chars input is valid
    StringRegExp("", '^[' & $sChars & ']$')
    If @error = 2 Then Return SetError(1, @error, @extended)

    _ArrayAdd($Chars, $sChars)
    _ArrayAdd($hInput, $hEdit)
    _ArrayAdd($s_Tip, $s_ErrorTip)

EndFunc   ;==>_SetAllowedChars

Func HideBalloonTip()
    _GUICtrlEdit_HideBalloonTip($hInput[$Index])
EndFunc   ;==>HideBalloonTip
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
chun914

thanks so much the tiptext is excellent..

I'm now working to set allowed char for multiple input box.....

still playing with the code to get it done...

 

And i'm get lost on the stringregexp function....... i want to set the input only allow 0-9 and a decimal point "." which only 2 decimal place is allowed

found one which is very close but i don't need negative "-" at start and "," to seperate the numbers.

If Not StringRegExp($sText, '^(-)?(\d*\.\d{0,' & $iMaxDecimalCount & '}|(\d{1,3}|^)(?:,\d{0,3})+(?:(?<=\d{3})\.\d{0,' & $iMaxDecimalCount & '})?|\d*)$') Then

Share this post


Link to post
Share on other sites
PhoenixXL

I edited the post to support multiple edit box.

What you are asking is for the support of a full pattern and not chars.

Its better not to steal the OP's subject.

I will soon create a Topic, since it has been asked many a times.

  • Like 1

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
funkey

I always use 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
PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.