Jump to content

Coding question around Inputbox,Focus, Combo


Recommended Posts

Here is some script I have been tinkering with while attempting to learn coding and Autoit.  Been in the help files and attempted several solutions but keep running into a brick wall. IF anyone would like to be additive to helping me resolve the below issues and learn from it, I would appreciate it.
 
Here is what DOES work:
1.Combobox(Category)
Click and make selection. Focus then moves to -
 
2. InputBox (Amount)
Enter numbers, hit enter key. But it also takes alpha (not good) Focus then moves to -
 
3. Combobox(Vendor)
Click and make selection. Listitem is added (category, amount, vendor) Focus then moves to #1 and clears #1, #2 and #3.
 
4. Delete button
Right click listitem, click delete button. Entry is deleted.
 
Here is what is screwed up:
1. Inputbox (Amount) takes alpha characters but I need it to only take numbers(currency).
I've tried multiple solutions - but nada.
 
2. UNCOMMENT  the aeReset() in Case $cEnterPressed and go through the input routine above - notice
Combobox(category) works but when you enter data into Inputbox(Amount) there is no focus to Combobox(vendor) and the Inputbox(Amount) is cleared and focus goes back to Combobox(Category) but does not clear it.
Leave the aeReset "comment", go through the above routine and when Combobox(Vendor) gets focus start typing entry and when you hit enter it adds the list item but does NOT clear the #1, #2, #3 entries because asRest is not called.
 
aeReset() is callable in two locations - seems to work for one but not the other.
 
Goal is to be able to use clicking and/or enter key where appropriate. 
 
Thanks.
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <MsgBoxConstants.au3>
 #include <GuiListView.au3>
#include <ColorConstants.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>


#Region ### START Koda GUI section ### Form=C:\Users\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Vendor  Category Selection", 680, 401, 150, 100)
$combo_b = GUICtrlCreateCombo("", 10, 26, 70, 25)
GUICtrlSetData(-1, "a|B|C|D|E|F|G")

$AEamounts = GUICtrlCreateInput("", 96, 26, 70, 21);

$hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25)
GUICtrlSetData(-1, "a|L|M|N|O|P")

$List1 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)
_GUICtrlListView_AddColumn($list1, "Vendor",290)
_GUICtrlListView_AddColumn($list1, "Category", 90)
_GUICtrlListView_AddColumn($list1, "Amount", 160)

$Button12 = GUICtrlCreateButton("Save Files", 10, 60, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Button13 = GUICtrlCreateButton("Delete Record", 10, 100, 158, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0xE3E3E3)

$Label1 = GUICtrlCreateLabel("Your Entries", 390, 53, 73, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

$Label2 = GUICtrlCreateLabel("Category", 16, 8, 54, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel(" Amount", 104, 8, 50, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Vendor", 392, 8, 44, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $fComboSelected = False

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)


Global $tInfo, $fComboActive = False
Global $fComboActive2 = False

_GUICtrlComboBox_GetComboBoxInfo($hcombo, $tInfo)
$hEdit = DllStructGetData($tInfo, "hEdit")

$cEnterPressed = GUICtrlCreateDummy()


GUISetState()

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]]
GUISetAccelerators($aAccelKeys)


Global $MMM
Global $NNN
Global $AEmoney

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP

            If $fComboActive2 Then
                 GUICtrlSetState ($AEamounts, $GUI_FOCUS)
                EndIf

            If $fComboActive Then

                 $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                 _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)
                 GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney , $List1)
                _GUICtrlComboBox_SetCurSel ( $hcombo ,  -1 )
                _GUICtrlComboBox_SetCurSel ( $combo_b ,  -1 )
                $fComboActive = False
                _GUICtrlComboBox_ShowDropDown($hcombo, False)
                _aeReset ()
                EndIf

            _blanker()

        Case $cEnterPressed

            If _WinAPI_GetFocus() = $hEdit Then

                $MMM =_GUICtrlComboBox_GetCurSel($combo_b)
                _GUICtrlComboBox_GetLBText($combo_b, $MMM, $NNN)
                GUICtrlCreateListViewItem(GUICtrlRead($hcombo)&"|"& $NNN &"|"& $AEmoney, $List1)

                _GUICtrlComboBox_ShowDropDown($hcombo, False)
                 GUICtrlSetState ($hcombo, $GUI_FOCUS)
             EndIf

                ;_aeReset ()


            _blanker()


        Case $AEamounts

            $AEmoney = GUICtrlRead ( $AEamounts )
            if _IsPressed("0D") then
            GUICtrlSetState ($hcombo, $GUI_FOCUS)
            EndIf


        Case $Button12


        Case $Button13

                Global $zzzz =_GUICtrlListView_GetSelectedIndices ( $List1 )
                DoubleClickFunc()






    EndSwitch

    If _GUICtrlComboBox_GetDroppedState($hcombo) = True Then
        $fComboActive = True
    EndIf

    If _GUICtrlComboBox_GetDroppedState($combo_b) = True Then
        $fComboActive2 = True
    EndIf


WEnd


Func _Edit_Changed($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hcombo)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $hcombo
                    _Edit_Changed($hcombo) ; <<<<<<<<<<<<<<<<<<<<<
                Case $combo_b
                    _Edit_Changed($combo_b) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND


Func _Blanker()
global $blankcount
$blankcount = _GUICtrlListView_GetItemCount ( $List1 )
for $i = (($blankcount) -1) to 0 step -1
if (_GUICtrlListView_GetItemText ( $List1, $i ))  = "" then
_GUICtrlListView_DeleteItem (  $List1, $i )
EndIf
Next
EndFunc



Func DoubleClickFunc()
    Global $DoubleClicked   = False
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    local $msgText = GUICtrlRead(GUICtrlRead($List1))
    local $msgText2 = StringTrimRight ( $msgText, 3 )
    local $msgCheck = MsgBox(4, "OK to : ", "Delete Entry:  " & $msgText2)
    If $msgCheck = 6 then
    _GUICtrlListView_DeleteItemsSelected ( $List1 )

    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $List1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

 Func _aeReset ()
                $NNN = ""
                GUICtrlSetData($AEamounts, "")
                $AEMoney =0.0
                GUICtrlSetState ($combo_b, $GUI_FOCUS)

    EndFunc

 

Link to comment
Share on other sites

For the Alpha problem you can use N as a subsequent character in the password field. (see help file)

where M would be Mandatory, N means only integer is accepted.

This info is not in the help file but on the WIKI

cya,

Bill

Link to comment
Share on other sites

I found a way to get the inputbox to accept numbers only and error message when not.

It may not be the most esoteric solution and may have holes in it that I am not aware of, but at this point it seems to work.

Here is the code for checking number entry.

 

I still have not figured out how to get the focus to move away from the combobox when using the enter key for input. The mouse function for entering input is fine.  I'm trying to learn how to anticipate usage of either mode and build it into the script.

After entry of data by way of mouse or enter key should, after adding to Listview, reset all fields to blanks.

Window messaging is part of the script that I did not do and really don't know much about but I do believe that is what is the hurdle around the enter key problem.

Initially I tried things like GUICtrlSetState ($othercontrols, $GUI_FOCUS) to move the focus or _GUICtrlListView_ClickItem ( $hWnd, $iIndex) thinking I could move the focus away from the combobox to the listview - anything to get to eventually resetting values to -0- or blanks.

$AEmoney = GUICtrlRead ( $AEamounts )
            if ($AEmoney/$AEmoney) = 1 And _IsPressed("0D") Then
                GUICtrlSetState ($hcombo, $GUI_FOCUS)
            EndIf

            if ($AEmoney/$AEmoney) <> 1 Then
                MsgBox($MB_SYSTEMMODAL, "Information", "Must Be Number ")
                _aeReset ()

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