Jump to content

'Enter' & 'Tab' functioning differently


randym
 Share

Recommended Posts

  • I used Koda to design a form, I set it up so that all but the first field is disabled. I click in the first field to get focus, and enter data. No problem. If I then hit 'Enter' - my code runs that enables the other fields and sets defaults and the like. However, if I hit 'Tab' instead, then all that happens is the data in the field is high-lited and the code associated with the field is never run. Is this as it should be, or have I done something wrong.

Weird thing is, once the other fields are enabled, it looks like 'Tab' works, but 'Enter' does not ....  - I am confused.

Randy

#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $arr = [] ; NOTE this creates an array of size 1 with an empty string
Global $Start, $End

#Region ### START Koda GUI section ###
Global $CharmROG_Form = GUICreate("Charm City ROG Automation", 566, 302, -1, -1)
Global $Label1 = GUICtrlCreateLabel("Receipt No", 8, 16, 58, 17)
Global $Label2 = GUICtrlCreateLabel("PO No", 208, 16, 36, 17)
Global $Label3 = GUICtrlCreateLabel("Inv No", 384, 16, 36, 17)
Global $ML_ReceiptNo = GUICtrlCreateInput("Receipt Number", 72, 16, 121, 21)
Global $ML_PONo = GUICtrlCreateInput("Purchase Order", 256, 16, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $ML_InvNo = GUICtrlCreateInput("Invoice Number", 424, 16, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Label4 = GUICtrlCreateLabel("Start Line", 8, 48, 49, 17)
Global $Label5 = GUICtrlCreateLabel("End Line", 200, 48, 46, 17)
Global $ML_StartLine = GUICtrlCreateInput("Starting Detail Dist Line", 72, 48, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $ML_EndLine = GUICtrlCreateInput("Ending Detail Dist Line", 256, 48, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Checkbox1 = GUICtrlCreateCheckbox("Existing ROG", 384, 48, 161, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON))
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Input1 = GUICtrlCreateInput("Lot Date", 72, 80, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $List1 = GUICtrlCreateList("", 201, 80, 183, 175)
GUICtrlSetData(-1, "Lot Dates")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Label6 = GUICtrlCreateLabel("Lot Date", 12, 80, 49, 17)
Global $Button1 = GUICtrlCreateButton("Process", 456, 264, 89, 25)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $ML_ReceiptNo
            GUICtrlSetData($ML_PONo, GUICtrlRead($ML_ReceiptNo))
            GUICtrlSetData($ML_InvNo, GUICtrlRead($ML_ReceiptNo))
            EnableForm()
            GUICtrlSetState($ML_EndLine, $GUI_FOCUS)
            GUISetState(@SW_SHOW)

        Case $ML_StartLine
            Validate_StartEnd ()

        Case $ML_EndLine
            Validate_StartEnd()

    EndSwitch
WEnd

Func EnableForm()
    GUICtrlSetState($ML_PONo, $GUI_ENABLE)
    GUICtrlSetState($ML_InvNo, $GUI_ENABLE)
    GUICtrlSetData($ML_StartLine, 1)
    GUICtrlSetState($ML_StartLine, $GUI_ENABLE)
    GUICtrlSetData($ML_EndLine, 1)
    GUICtrlSetState($ML_EndLine, $GUI_ENABLE)
    GUICtrlSetState($Checkbox1, $GUI_ENABLE)
    GUICtrlSetState($Input1, $GUI_ENABLE)
    ;GUICtrlSetState($List1, $GUI_ENABLE)
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUISetState(@SW_SHOW)
EndFunc   ;==>EnableForm

Func Validate_StartEnd()
    Get_StartEnd()
    If $End < $Start Then
        GUICtrlSetData($ML_EndLine, $Start)
        GUISetState(@SW_SHOW)
    EndIf
EndFunc   ;==>Validate_StartEnd
Func Get_StartEnd()
    $Start = GUICtrlRead($ML_StartLine)
    $End = GUICtrlRead($ML_EndLine)
EndFunc   ;==>Get_StartEnd

 

Edited by randym
Further research shed new info

And the sign said 'Long Hairded Creepy People Need Not Apply' ... So I stuffed my hair up under my hat and I went in to ask him why?

Link to comment
Share on other sites

Looks like the event firing from the control (I assuming the event is CHANGED) doesn't fire when you Tab off the control.  You might have to write your own handler to fire your code upon changed or lost focus events.  You'll also want to put in some logic to verify the validity of the Receipt #.  Just my two cents.

Google "autoit $WM_COMMAND GUIRegisterMsg" to see some examples.

Link to comment
Share on other sites

Here is a way :

#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $arr = [] ; NOTE this creates an array of size 1 with an empty string
Global $Start, $End

#Region ### START Koda GUI section ###
Global $CharmROG_Form = GUICreate("Charm City ROG Automation", 566, 302, -1, -1)
Global $Label1 = GUICtrlCreateLabel("Receipt No", 8, 16, 58, 17)
Global $Label2 = GUICtrlCreateLabel("PO No", 208, 16, 36, 17)
Global $Label3 = GUICtrlCreateLabel("Inv No", 384, 16, 36, 17)
Global $ML_ReceiptNo = GUICtrlCreateInput("Receipt Number", 72, 16, 121, 21)
Global $ML_PONo = GUICtrlCreateInput("Purchase Order", 256, 16, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $ML_InvNo = GUICtrlCreateInput("Invoice Number", 424, 16, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Label4 = GUICtrlCreateLabel("Start Line", 8, 48, 49, 17)
Global $Label5 = GUICtrlCreateLabel("End Line", 200, 48, 46, 17)
Global $ML_StartLine = GUICtrlCreateInput("Starting Detail Dist Line", 72, 48, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $ML_EndLine = GUICtrlCreateInput("Ending Detail Dist Line", 256, 48, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Checkbox1 = GUICtrlCreateCheckbox("Existing ROG", 384, 48, 161, 25, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON))
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Input1 = GUICtrlCreateInput("Lot Date", 72, 80, 121, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $List1 = GUICtrlCreateList("", 201, 80, 183, 175)
GUICtrlSetData(-1, "Lot Dates")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $Label6 = GUICtrlCreateLabel("Lot Date", 12, 80, 49, 17)
Global $Button1 = GUICtrlCreateButton("Process", 456, 264, 89, 25)
GUICtrlSetState(-1, $GUI_DISABLE)

$dummy = GUICtrlCreateDummy()

Local $aAccelKeys[1][2] = [ ["{TAB}", $dummy] ]
GUISetAccelerators($aAccelKeys)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            Case $ML_StartLine
            Validate_StartEnd ()

        Case $ML_EndLine
            Validate_StartEnd()
        Case $dummy
            If ControlGetHandle($CharmROG_Form, "", ControlGetFocus($CharmROG_Form) ) = GUICtrlGetHandle($ML_ReceiptNo) Then
                GUISetAccelerators("")
                GUICtrlSetData($ML_PONo, GUICtrlRead($ML_ReceiptNo))
                GUICtrlSetData($ML_InvNo, GUICtrlRead($ML_ReceiptNo))
                EnableForm()
                GUICtrlSetState($ML_EndLine, $GUI_FOCUS)
                GUISetState(@SW_SHOW)
            EndIf

    EndSwitch
WEnd

Func EnableForm()
    GUICtrlSetState($ML_PONo, $GUI_ENABLE)
    GUICtrlSetState($ML_InvNo, $GUI_ENABLE)
    GUICtrlSetData($ML_StartLine, 1)
    GUICtrlSetState($ML_StartLine, $GUI_ENABLE)
    GUICtrlSetData($ML_EndLine, 1)
    GUICtrlSetState($ML_EndLine, $GUI_ENABLE)
    GUICtrlSetState($Checkbox1, $GUI_ENABLE)
    GUICtrlSetState($Input1, $GUI_ENABLE)
    ;GUICtrlSetState($List1, $GUI_ENABLE)
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUISetState(@SW_SHOW)
EndFunc   ;==>EnableForm

Func Validate_StartEnd()
    Get_StartEnd()
    If $End < $Start Then
        GUICtrlSetData($ML_EndLine, $Start)
        GUISetState(@SW_SHOW)
    EndIf
EndFunc   ;==>Validate_StartEnd
Func Get_StartEnd()
    $Start = GUICtrlRead($ML_StartLine)
    $End = GUICtrlRead($ML_EndLine)
EndFunc   ;==>Get_StartEnd

 

Link to comment
Share on other sites

Thanks jguinch - it is a clever work around... I saw in the documentation I was reading about doing something like this, but you turning my gui into a working example really brought it home.  

And the sign said 'Long Hairded Creepy People Need Not Apply' ... So I stuffed my hair up under my hat and I went in to ask him why?

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