Jump to content
Sign in to follow this  
crystalburner

Input Box read/action

Recommended Posts

crystalburner

Hi

I'm struggling with a small project to make a database that a friend has in Access in AutoIT.

In access its setup so that there are several input boxes. Each input box is restricted to certain lengths and charactors, e.g.

One input box may be alphanumeric and 200 charactors long

Another input box will accept only the numbers 2, 4 and -9

I've got the gui part done no problem, but I cant see how to restrict the boxes like so, and also the bigger problem is that if say you type a 2 into inputbox 2 it should jump to input box 4 but if you put a 4 it should jump to input box 3.

I've been playing with

Case ControlGetFocus($Main) = 'Edit1'

But this only takes action when you have clicked on the box not after you have typed.

Does anyone have a script example I can look at that may point me in the right direction?

There are 60 - 120 input boxes needed so I'm not sure if something like guictrlrecvmsg will help, but this would mean 60 -120 statements in the gui loop ....

Help!

Share this post


Link to post
Share on other sites
GaryFrost

Maybe something like:

#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $EN_CHANGE = 0x300
Global Const $DebugIt = 1

$GUI = GUICreate(" My GUI", 500, 500)
$input1 = GUICtrlCreateInput("", 10, 5, 300, 20)
GUICtrlSetLimit($input1, 200)
$input2 = GUICtrlCreateInput("", 10, 35, 300, 20)
GUICtrlSetLimit($input2, 2)
$input3 = GUICtrlCreateInput("", 10, 65, 300, 20)
$input4 = GUICtrlCreateInput("", 10, 95, 300, 20)
$btn = GUICtrlCreateButton("Ok", 40, 225, 60, 20)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            ExitLoop
    EndSelect
WEnd

Func _Input1_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Input1 Changed:" & GUICtrlRead($input1))
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>_Input1_Changed

Func _Input2_Changed()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then _DebugPrint("Input2 Changed:" & GUICtrlRead($input2))
    ;----------------------------------------------------------------------------------------------
    $number = Int(GUICtrlRead($input2))
    If $number = 2 Then
        GUICtrlSetState($input4, $GUI_FOCUS)
    ElseIf $number = 4 Then
        GUICtrlSetState($input3, $GUI_FOCUS)
    ElseIf $number = -9 Then ;just a test
        GUICtrlSetState($input1, $GUI_FOCUS)
    Else
    EndIf
EndFunc   ;==>_Input2_Changed

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam

    Switch $nID
        Case $input1
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Input1_Changed()
            EndSwitch
        Case $input2
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _Input2_Changed()
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint


Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc   ;==>_LoWord

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
crystalburner

Okay, thats way beyond me, but I can see I can replace the consolewrite with statements to perform actions on certain keystrokes... cool... thanks

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  

×