faustf

inputbox only number double ?

10 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You can also use something like this :

#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 by jguinch

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

Right. Simpler is not always better  :)

Share this post


Link to post
Share on other sites

:) thankz  so much Bro 

Share this post


Link to post
Share on other sites
14 hours ago, jguinch said:

You can also use something like this :

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

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