Jump to content

Input with Number et point decimal


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...