Sign in to follow this  
Followers 0
eri

Only numeric..???

7 posts in this topic

Please correct my script..

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\Form1.kxf
$Form1 = GUICreate("Kalkulasi", 219, 186, 378, 178)
GUISetBkColor(0x00FFFF)
$Input1 = GUICtrlCreateInput("0", 90, 37, 122, 21)
$Input2 = GUICtrlCreateInput("0", 89, 66, 122, 21)
$Input3 = GUICtrlCreateInput("0", 89, 95, 122, 21)
$Label1 = GUICtrlCreateLabel("Diameter", 8, 39, 60, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Thickness", 8, 67, 65, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label3 = GUICtrlCreateLabel("Length", 8, 95, 46, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput("", 8, 150, 204, 21)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label4 = GUICtrlCreateLabel("", 98, 140, 4, 4)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Radio1 = GUICtrlCreateRadio(" x..", 8, 8, 49, 17)
$Radio2 = GUICtrlCreateRadio(" +..", 64, 8, 73, 17)
GUICtrlSetState($radio1, $GUI_CHECKED)
$Label5 = GUICtrlCreateLabel("Volume mm", 8, 130, 64, 20)
GUICtrlSetFont(-1, 8, 800, 2, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
        Select
        Case BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
            $x = GUICtrlRead ($Input1)
            $y = GUICtrlRead ($Input2)
            $z = GUICtrlRead ($Input3)
            $c = $x * $y * $z
            If StringRegExp(StringLeft([$x-$y], 2)) Then ;<==== How to set $x-$y Only number not for word then show message in input 4
                GUICtrlSetData($Input4, $c)
            Else
                GUICtrlSetData($Input4," Only Number Not Word") ; <======
            EndIf
        Case BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
            $x = GUICtrlRead ($Input1)
            $y = GUICtrlRead ($Input2)
            $z = GUICtrlRead ($Input3)
            $cz = $x + $y + $z
            GUICtrlSetData($Input4, $cz)
        EndSelect
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites



You want only numbers inside your GUICtrlRead?

Start by setting a $ES_NUMBER style on your inputs. (Using #include <EditConstants.au3>)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\Form1.kxf
$Form1 = GUICreate("Kalkulasi", 219, 186, 378, 178)
GUISetBkColor(0x00FFFF)
$Input1 = GUICtrlCreateInput("0", 90, 37, 122, 21)
$Input2 = GUICtrlCreateInput("0", 89, 66, 122, 21)
$Input3 = GUICtrlCreateInput("0", 89, 95, 122, 21)
$Label1 = GUICtrlCreateLabel("Diameter", 8, 39, 60, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Thickness", 8, 67, 65, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label3 = GUICtrlCreateLabel("Length", 8, 95, 46, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput("", 8, 150, 204, 21)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label4 = GUICtrlCreateLabel("", 98, 140, 4, 4)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Radio1 = GUICtrlCreateRadio(" x..", 8, 8, 49, 17)
$Radio2 = GUICtrlCreateRadio(" +..", 64, 8, 73, 17)
GUICtrlSetState($radio1, $GUI_CHECKED)
$Label5 = GUICtrlCreateLabel("Volume mm", 8, 130, 64, 20)
GUICtrlSetFont(-1, 8, 800, 2, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $Msg = GUIGetMsg()
    Select
    Case BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $c = $x * $y * $z
;~  If StringRegExp(StringLeft([$x-$y], 2)) Then ;<==== How to set $x-$y Only number not for word then show message in input 4
;~  GUICtrlSetData($Input4, $c)
;~  Else
;~  GUICtrlSetData($Input4," Only Number Not Word") ; <======
;~  EndIf
    Case BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $cz = $x + $y + $z
    GUICtrlSetData($Input4, $cz)
    EndSelect
    Switch $Msg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $inp, $integer

    $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $Input1
            $inp = GUICtrlRead($Input1)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input1, $integer)
        Case $Input2
            $inp = GUICtrlRead($Input2)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input2, $integer)
        Case $Input3
            $inp = GUICtrlRead($Input3)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input3, $integer)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Br,

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

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\Form1.kxf
$Form1 = GUICreate("Kalkulasi", 219, 186, 378, 178)
GUISetBkColor(0x00FFFF)
$Input1 = GUICtrlCreateInput("0", 90, 37, 122, 21)
$Input2 = GUICtrlCreateInput("0", 89, 66, 122, 21)
$Input3 = GUICtrlCreateInput("0", 89, 95, 122, 21)
$Label1 = GUICtrlCreateLabel("Diameter", 8, 39, 60, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Thickness", 8, 67, 65, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label3 = GUICtrlCreateLabel("Length", 8, 95, 46, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput("", 8, 150, 204, 21)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label4 = GUICtrlCreateLabel("", 98, 140, 4, 4)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Radio1 = GUICtrlCreateRadio(" x..", 8, 8, 49, 17)
$Radio2 = GUICtrlCreateRadio(" +..", 64, 8, 73, 17)
GUICtrlSetState($radio1, $GUI_CHECKED)
$Label5 = GUICtrlCreateLabel("Volume mm", 8, 130, 64, 20)
GUICtrlSetFont(-1, 8, 800, 2, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $Msg = GUIGetMsg()
    Select
    Case BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $c = $x * $y * $z
;~  If StringRegExp(StringLeft([$x-$y], 2)) Then ;<==== How to set $x-$y Only number not for word then show message in input 4
;~  GUICtrlSetData($Input4, $c)
;~  Else
;~  GUICtrlSetData($Input4," Only Number Not Word") ; <======
;~  EndIf
    Case BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $cz = $x + $y + $z
    GUICtrlSetData($Input4, $cz)
    EndSelect
    Switch $Msg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
WEnd

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $inp, $integer

    $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $Input1
            $inp = GUICtrlRead($Input1)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input1, $integer)
        Case $Input2
            $inp = GUICtrlRead($Input2)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input2, $integer)
        Case $Input3
            $inp = GUICtrlRead($Input3)
            $integer = StringRegExpReplace($inp, "[^0-9]", "")
            GUICtrlSetData($Input3, $integer)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Br,

UEZ

Thank's UEZ... ;)

Share this post


Link to post
Share on other sites

Indeed, even shorter with suggestion from AlmarM ($ES_NUMBER):

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\Form1.kxf
$Form1 = GUICreate("Kalkulasi", 219, 186, 378, 178)
GUISetBkColor(0x00FFFF)
$Input1 = GUICtrlCreateInput("0", 90, 37, 122, 21, $ES_NUMBER)
$Input2 = GUICtrlCreateInput("0", 89, 66, 122, 21, $ES_NUMBER)
$Input3 = GUICtrlCreateInput("0", 89, 95, 122, 21, $ES_NUMBER)
$Label1 = GUICtrlCreateLabel("Diameter", 8, 39, 60, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Thickness", 8, 67, 65, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label3 = GUICtrlCreateLabel("Length", 8, 95, 46, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput("", 8, 150, 204, 21)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label4 = GUICtrlCreateLabel("", 98, 140, 4, 4)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Radio1 = GUICtrlCreateRadio(" x..", 8, 8, 49, 17)
$Radio2 = GUICtrlCreateRadio(" +..", 64, 8, 73, 17)
GUICtrlSetState($radio1, $GUI_CHECKED)
$Label5 = GUICtrlCreateLabel("Volume mm", 8, 130, 64, 20)
GUICtrlSetFont(-1, 8, 800, 2, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $Msg = GUIGetMsg()
    Select
    Case BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $c = $x * $y * $z
    Case BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
    $x = GUICtrlRead ($Input1)
    $y = GUICtrlRead ($Input2)
    $z = GUICtrlRead ($Input3)
    $cz = $x + $y + $z
    GUICtrlSetData($Input4, $cz)
    EndSelect
    Switch $Msg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
WEnd

Br,

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

#7 ·  Posted (edited)

Is there a way to allow decimal points in the above?

Edit:

Don't wory IsNumber(4.2) does it for me - Tx

Even better:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=G:\Form1.kxf
$Form1 = GUICreate("Kalkulasi", 219, 186, 378, 178)
GUISetBkColor(0x00FFFF)
$Input1 = GUICtrlCreateInput("0", 90, 37, 122, 21)
$Input2 = GUICtrlCreateInput("0", 89, 66, 122, 21)
$Input3 = GUICtrlCreateInput("0", 89, 95, 122, 21)
$Label1 = GUICtrlCreateLabel("Diameter", 8, 39, 60, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Thickness", 8, 67, 65, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Label3 = GUICtrlCreateLabel("Length", 8, 95, 46, 23)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput("", 8, 150, 204, 21)
GUICtrlSetBkColor(-1, 0xE3E3E3)
$Label4 = GUICtrlCreateLabel("", 98, 140, 4, 4)
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
$Radio1 = GUICtrlCreateRadio(" x..", 8, 8, 49, 17)
$Radio2 = GUICtrlCreateRadio(" +..", 64, 8, 73, 17)
GUICtrlSetState($radio1, $GUI_CHECKED)
$Label5 = GUICtrlCreateLabel("Volume mm", 8, 130, 64, 20)
GUICtrlSetFont(-1, 8, 800, 2, "Comic Sans MS")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
        Select
        Case BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
            $x = Number(GUICtrlRead ($Input1))
            $y = Number(GUICtrlRead ($Input2))
            $z = Number(GUICtrlRead ($Input3))
            $c = $x * $y * $z
            If $c >0 Then ;<==== How to set $x-$y Only number not for word then show message in input 4
                GUICtrlSetData($Input4, $c)
            Else
                GUICtrlSetData($Input4," Only Numbers Bigger than Zero") ; <======
            EndIf
        Case BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
            $x = Number(GUICtrlRead ($Input1))
            $y = Number(GUICtrlRead ($Input2))
            $z = Number(GUICtrlRead ($Input3))
            $c = $x + $y + $z
            If $c >0 Then ;<==== How to set $x-$y Only number not for word then show message in input 4
                GUICtrlSetData($Input4, $c)
            Else
                GUICtrlSetData($Input4," Only Numbers Bigger than Zero") ; <======
            EndIf
        EndSelect
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by JoHanatCent

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