Jump to content

Script to accept range above certain number..


Thudo
 Share

Recommended Posts

Trying to put a range where the user cannot input a value higher than X. In this case, any number less than 5 is not accepted.

Local $iMinTime = 5
    
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; Read Timeout input
    $tidle = GUICtrlRead($timeidle)
    ; Check value
    If _CheckMinimumIdleTime($tidle, $iMinTime) = 0 Then
        $Error = "Timeout must be no less than 5 minutes: "
        $Error &= "Please change the time."
        MsgBox(48, "Error", $Error)
        GUICtrlSetData($timeidle, "")
        Return
    EndIf

Func _CheckMinimumIdleTime($tidle, $iMinTime)

    Local $iResult = StringRegExp($tidle, $iMinTime)
    If @error = 0 Then
        Return SetError(0, 0, ($iResult <> 0))
    Else
        Return SetError(1, 0, 0)
    EndIf

EndFunc   ;==>_CheckMinimumIdleTime
However it only is accepting the value of 5. I need it to accept values 5 and greater and obviously nothing less than 5. Yeah I know this is likely stupid-easy. I've tried to create an array and switch/case for Local $iMinTime = 5 but that hasn't worked. As an FYI.. GUICtrlRead($timeidle) is when the user inputs the value to be checked.
Link to comment
Share on other sites

You just need an edit like this?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Global $iMinTime = 5, $status

GUICreate("")
$TimeIdle = GUICtrlCreateInput("", 20, 10, 60)
$btn = GUICtrlCreateButton("SET VALUE", 10, 40, 80, 18 ,$BS_DEFPUSHBUTTON)
$message = GUICtrlCreateLabel("", 10, 70, 180, 16)
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = -3 then Exit
    If $msg = $btn Then $status = _EditTimeIdle()
    If $status Then
        MsgBox(1,"","process the good value")
        $status = 0
    EndIf
WEnd

Func _EditTimeIdle()
    Local $tidle = GUICtrlRead($TimeIdle)
    If $tidle < $iMinTime Then
        GUICtrlSetData($message, "VALUE MUST BE 5 OR GREATER")
        GUICtrlSetData($timeidle, "")
        GUICtrlSetState($timeidle, $GUI_FOCUS)
        Return
    Else
        GUICtrlSetData($message, "")
    EndIf
    Return $tidle
EndFunc
Link to comment
Share on other sites

Thanks Spiff but I only need detection code as I already have the GUI buttons already placed which link off GUICtrlRead($timeidle). You'll also notice I have prompt boxes coming up to tell the user whats invalid. Those must be maintained.

Edited by Thudo
Link to comment
Share on other sites

(Detection) code like this?

If GUICtrlRead($timeidle) < $iMinTime Then
    $Error = "Timeout must be no less than 5 minutes: "
    $Error &= "Please change the time."
    MsgBox(48, "Error", $Error)
    GUICtrlSetData($timeidle, "")
EndIf

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

;) I think I need a twinkie.. I over-complicated the original script. Gah.. Where is Jason to Chainsaw me Texan stylez.. :)

Thanks SOMD! Happy 13ths today to you.

Final script:

Local $iMinTime = 7
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    ; Read Timeout input
    $tidle = GUICtrlRead($timeidle)
    ; Check value
    If GUICtrlRead($timeidle) < $iMinTime then
        $Error = "Timeout must be no less than 7 minutes: "
        $Error &= "Please change the time."
        MsgBox(48, "Error", $Error)
        GUICtrlSetData($timeidle, "")
        Return
    EndIf
Edited by Thudo
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...