Jump to content

Recommended Posts

Posted (edited)

Hello all autoit scripters I want to ask to have this input to work with only numbers and

when a number typed in the little inputbox then automatic execute is that possible?

If so that ok button can be removed. The numbers to use is 1 to 9 ..

Another question is if I want this input window to be in center of screen in differents resolution what I must do then whats commands to use?

All help is welcome !!

Code:

#include <GUIConstants.au3>

$GUI = GUICreate(" Test Input" , 400,170, @DesktopWidth/2-200, @DesktopHeight/2-110, -1 )

GUISetBkColor (0x00E0FFFF)

GUICtrlCreateLabel("-----------------------------------------------------------", 13, 110, 400)

GUICtrlCreateLabel("-----------------------------------------------------------", 206, 110, 400)

$val = GUICtrlCreateInput ("", 190, 107, 15, 20," M1")

$ok = GUICtrlCreateButton ("Ok", 110, 133, 80, 25)

$av = GUICtrlCreateButton ("Cancel", 205, 133, 80, 25)

; GUISetState(@SW_SHOW, $GUI)

GUISetState ()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

ExitLoop

Case $msg = $av

Exit ; close

Case $msg = $ok

ExitLoop

EndSelect

Wend

MsgBox (4096, "You pressed ok button", GUICtrlRead($ok))

Edited by Borje
Posted

Thank you Rajeshontheweb

I have lock at the snippet in your example 2 but i cant find out to insert this in my example to have that to work.

Yes i dont know that with braces to have the code more readable can you give a exaple with braces..

Posted (edited)

just add "
" to the beginning of your code and "
" to the end of the code

#include <GUIConstants.au3>

$GUI = GUICreate("Test Input" , 150 ,120, @DesktopWidth/2-200, @DesktopHeight/2-110, -1 )

GUISetBkColor (0x00E0FFFF)

$val = GUICtrlCreateInput ("Type here",25, 10, 100 ,50," M1")
$moveWin = GUICtrlCreateButton("CentreWindow",25,85,100,25)

GUISetState ()

While 1
        $msg = GUIGetMsg()
        
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    Exit
                Case $msg = $val
                    Msgbox(4096,"","You typed" & @CRLF & GUICtrlRead($val))
                    Exit
                Case $msg = $moveWin
                    _CentreWindow($GUI,"Test Input")
            EndSelect

Wend



Func _CentreWindow($win, $txt)
     $size = WinGetClientSize($win, $txt)
     Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
     Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
     Return WinMove($win, $txt, $x, $y)
EndFunc   ;==>_Middle
Edited by rajeshontheweb
Posted

Now there is only one problem with the input what to do to have this input to work with only numbers and

when a number typed in the little inputbox then automatic execute is that possible?

If so that ok button can be removed. The numbers to use is 1 to 9 ..

Posted

Now there is only one problem with the input what to do to have this input to work with only numbers and

when a number typed in the little inputbox then automatic execute is that possible?

If so that ok button can be removed. The numbers to use is 1 to 9 ..

Try this.

#include <GUIConstants.au3>
#include <String.au3>

$GUI = GUICreate(" Test Input", 400, 170, (@DesktopWidth - 400) / 2, (@DesktopHeight - 170) / 2)
GUISetBkColor(0x00E0FFFF)

GUICtrlCreateLabel(_StringRepeat("-", 58), 13, 110, 176, 20)
GUICtrlCreateLabel(_StringRepeat("-", 58), 206, 110, 4194, 20)

$val = GUICtrlCreateInput("", 190, 107, 15, 20)
$av = GUICtrlCreateButton("Cancel", 160, 133, 80, 25)

GUISetState()

While 1
    If GUICtrlRead($val) <> "" Then
        $sChr = GUICtrlRead($val)
        If StringRegExp($sChr, "[1-9]") Then
            ExitLoop
        Else
            GUICtrlSetData($val, "")
        EndIf
    EndIf

    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $av
            Exit; close
    EndSwitch

WEnd

MsgBox(4096, "A digit between 1 - 9 was entered", $sChr)
Posted (edited)

or try this

#include <GUIConstants.au3>
#include <EditConstants.au3>

$GUI = GUICreate(" Test Input", 400, 170, (@DesktopWidth - 400) / 2, (@DesktopHeight - 170) / 2)
GUISetBkColor(0x00E0FFFF)

$val = GUICtrlCreateInput("", 190, 107, 15, 20,$ES_NUMBER)
$av = GUICtrlCreateButton("Cancel", 160, 133, 80, 25)

GUISetState()

While 1
    if GUICtrlRead($val) = 0 then 
        GUICtrlSetData($val,"")
    ElseIf GUICtrlRead($val) <> "" Then
        ExitLoop
    EndIf

    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $av
            Exit; close
    EndSwitch

WEnd

MsgBox(4096, "A digit between 1 - 9 was entered", GUICtrlRead($val))
Edited by KaFu

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
×
×
  • Create New...