Jump to content

How to allow only ranging numbers in input box?


Recommended Posts

What I want is to make the Chance input to only allow between 0.01-98 and the Payout input to allow only 1.01202 to 9900 How do I make it to only allow those ranging numbers?

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

$Form1 = GUICreate("Form1", 364, 153, 192, 124)

$label1 = GUICtrlCreateLabel("Chance", 80, 32, 59, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$label2 = GUICtrlCreateLabel("Payout", 228, 31, 53, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("49.50", 144, 104, 97, 41)
$Chance = GUICtrlCreateInput("49.50", 56, 63, 121, 21)
$Payout = GUICtrlCreateInput("2", 208, 63, 121, 21)

GUISetState(@SW_SHOW)

Global $WhichFunc = 0
Global $aFuncs[2]
$aFuncs[0] = _Func_1
$aFuncs[1] = _Func_2
Global $RW = 1


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Chance
            Chance()
        Case $Payout
            Payout()
        Case $Button1
                 $aFuncs[$WhichFunc] ()
            $WhichFunc = Not $WhichFunc
    EndSwitch
WEnd


Func Chance()
    $Read1 = GUICtrlRead($Chance)
    $data = 99 / $Read1
    GUICtrlSetData($Payout, $data)
    $data = 99 / $data
    If $RW = 1 Then
    GUICtrlSetData($Button1, $data)
    Else
    _Func_1()
    EndIf
    EndFunc
    Func Payout()
    $Read2 = GUICtrlRead($Payout)
    $data1 = 99 / $Read2
    $data1 = Round($data1, 5)
    GUICtrlSetData($Chance, $data1)
    If $RW = 1 Then
        GUICtrlSetData($Button1, $data1)
    Else
        _Func_1()
    EndIf
EndFunc

 Func _Func_2()
$Read1 = GUICtrlRead($Chance)
GUICtrlSetData($Button1, $Read1)
$RW = 1
 EndFunc

 Func _Func_1()
$Read2 = GUICtrlRead($Chance)
$Read2 = 99.99 - $Read2
GUICtrlSetData($Button1, $Read2)
$RW = 2
 EndFunc

 

Link to comment
Share on other sites

6 minutes ago, Subz said:

Wouldn't you just use Random:

Round(Random(.01, .98), 2) ;~ 0.01-98
Random(1.01202, 9900) ;~ 1.01202 - 9900

 

It is something users will enter, and so if a user enters for example 99 in chance input it should revert to 98 and inform must be between "  0.01-98 " same goes for Payout input.

Link to comment
Share on other sites

Sorry was confused so maybe something like this?

Case $Chance
            If Number(GUICtrlRead($Chance)) < 0.01 Then GUICtrlSetData($Chance, 0.01)
            If Number(GUICtrlRead($Chance)) > 98 Then GUICtrlSetData($Chance, 98)
            Chance()
        Case $Payout
            If Number(GUICtrlRead($Payout)) < 1.01202 Then GUICtrlSetData($Payout, 1.01202)
            If Number(GUICtrlRead($Payout)) > 9900 Then GUICtrlSetData($Payout, 9900)
            Payout()

 

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