Jump to content
myspacee

GUICtrlCreateInput to accept only formattted numbers

Recommended Posts

myspacee

Hello,

to facilitate my users to input money digits in my GUICtrlCreateInput i want to format like this :

1234,00 = 1.234,00

9999888,77 = 9.999.888,77

 

How set GUICtrlCreateInput to accept numbers, comma and dot chars like above examples ?

 

Thank you for any info,

m.

Share this post


Link to post
Share on other sites
Starstar

Local $isnum = 445

If IsNumber($isnum) Then
    MsgBox(0,"Error","This is a digits")
Else
    MsgBox(0,"Error","This is not a digits")
    EndIf

Try this one.


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
myspacee

HEllo,

thank you for reply but i ask for a separator style like this :

image037.jpg

 

m.

 

Share this post


Link to post
Share on other sites
BrewManNH

I believe you'll have to process that yourself. There's no setting for an input control that will do it automatically. Maybe this thread might give you some ideas.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Starstar

$guiInfo = GUICreate("Data",250,150)
$guicombo = GUICtrlCreateCombo("",140,10,80,30)
$guicombolbl = GUICtrlCreateLabel("Select Formate",10,10,80,30)
$guicombo1 = GUICtrlCreateCombo("",140,50,80,30)
$guicombolbl = GUICtrlCreateLabel("Data Entry",10,50,80,30)
GUICtrlSetData($guicombo, "Number|Text|", "Number")
GUISetState(@SW_SHOW)

while 2
    $reding = GUICtrlRead($guicombo)
    Select
        Case $reding = "Number"
            Local $gnmdata
        $nmdata = "1|2|3|4|5|6|7|8|9|10"
        If $nmdata <> $gnmdata Then
            GUICtrlSetData($guicombo1,"")
            GUICtrlSetData($guicombo1, "1|2|3|4|5|6|7|8|9|10", "1")
            $gnmdata = $nmdata
            $gtxdata = ""
            EndIf
        Case Else
            Local $gtxdata
            $txdata = "A|B|C|D|E|F|G|H|I|J"
            If $txdata <> $gtxdata Then
            GUICtrlSetData($guicombo1,"")
            GUICtrlSetData($guicombo1, "A|B|C|D|E|F|G|H|I|J", "A")
            $gtxdata = $txdata
            $gnmdata = ""
            EndIf
    EndSelect
    $gMsg = GUIGetMsg()
    Switch $gMsg
        Case -3
        Exit
        EndSwitch
WEnd

Do you want something like this?


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
UEZ

Try this:

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

AutoItSetOption("GUIOnEventMode", 1)

Global Const $sSep = ".", $sDec = ","
Global Const $hGUI = GUICreate("Currency Decimal Separator", 232, 90)
Global Const $Label = GUICtrlCreateLabel("Enter some numbers", 22, 8, 163, 17)
Global Const $input = GUICtrlCreateInput("", 22, 30, 165, 24)
GUICtrlSetLimit(-1, 19)
GUICtrlSetFont(-1, 12)
Global Const $iCurrency = GUICtrlCreateLabel("€", 22 + 165 + 4, 32, 10, 17)
GUICtrlSetFont(-1, 12)
GUISetState()

GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND')
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While Sleep(1000)
WEnd

Func _Exit()
    GUIDelete()
    Exit
EndFunc

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0x0000FFFF) = $input Then
        GUICtrlSetData($input, CurrencySeperator(StringRegExpReplace(GUICtrlRead($input), "[^0-9" & $sDec & "]", "")))
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func CurrencySeperator($iNumber, $iDecPlace = 2)
    $iNumber = StringReplace($iNumber, $sSep, "")
    StringReplace($iNumber, $sDec, $sDec)
    Switch @extended
        Case 0
            If StringLen($iNumber) > 3 Then
                $iNumber = StringReverse(StringRegExpReplace(StringReverse($iNumber), ".{3}", "$0" & $sSep))
                If StringLeft($iNumber, 1) = $sSep Then $iNumber = StringTrimLeft($iNumber, 1)
            EndIf
            Return $iNumber
        Case 1
            Local Const $f = StringLeft(StringRegExpReplace($iNumber, ".+\" & $sDec & "(\d*)", "$1"), $iDecPlace)
            $iNumber = StringRegExpReplace($iNumber, "(\d+)\" & $sDec & ".*", "$1")
            $iNumber = StringReverse(StringRegExpReplace(StringReverse($iNumber), ".{3}", "$0" & $sSep))
            If StringLeft($iNumber, 1) = $sSep Then $iNumber = StringTrimLeft($iNumber, 1)
            Return $iNumber & $sDec & $f
        Case Else
            Return StringTrimRight($iNumber, 1)
    EndSwitch
EndFunc

Not implemented yet: -,+

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
mikell

UEZ,

Nice :)
The CurrencySeperator func could be compacted a bit though

Func CurrencySeperator($iNumber, $iDecPlace = 2)
  Local $s = StringSplit(StringReplace($iNumber, $sSep, ""), $sDec)
  Return StringRegExpReplace($s[1], '(?<=\d)(?=(\d{3})+$)', $sSep) & (($s[0] = 1) ? "" : "," & StringLeft($s[2], $iDecPlace))
EndFunc

Edit
And this allows typing a comma as first char

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0x0000FFFF) = $input Then
        Local $iNumber = StringRegExpReplace(GUICtrlRead($input), '^' & $sDec, "0" & $sDec)
        GUICtrlSetData($input, CurrencySeperator(StringRegExpReplace($iNumber, "[^0-9" & $sDec & "]", "")))
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

:D

Edited by mikell
  • Like 1

Share this post


Link to post
Share on other sites
UEZ

Absolutely cool how you shorten the CurrencySeperator function. :thumbsup:

 

Thanks.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
myspacee

Thank you!

m.

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

×