Jump to content

Enter instead of Button Press on GUICtrlCreateInput


Recommended Posts

I'm struggling how to use an accelerator here to get the Enter key to sub for the button control.

This GUI is reused which is they the IF/Else/Endif around it.

 

IF $GUI1HNDL = "" Then
        $GUI1HNDL = GUICreate("Watson Automator", 270, 90, -1, -1, -1, $WS_EX_TOPMOST)
        GUICtrlCreateLabel("Please Enter HPE Req ID to Quote", 0, 10, 270, 20,$SS_CENTER)
        GUICtrlCreateLabel("HPE Req ID: ", 23, 30, 75, 20, $SS_RIGHT)
        $idHPEReq = GUICtrlCreateInput("", 105, 30, 135, 20)
        GUICtrlSetLimit(-1, 12)
        GUISetState(@SW_SHOW,$GUI1HNDL)
        $idGO= GUICtrlCreateButton("Automate", 85, 60, 100)
        $idMsg = 0
    Else
        GUICtrlSetData ($idHPEReq, "")
        GUISetState(@SW_SHOW, $GUI1HNDL)
        $idMsg = 0
    EndIf

    BlockInput($BI_ENABLE)
    While 1
        $idMsg = GUIGetMsg ()
        Select
            Case $idMsg = $idGO
            ExitLoop
        EndSelect
    WEnd
    $HPEReqID = GUICtrlRead($idHPEReq)

 

Edited by dchaosw360
Link to comment
Share on other sites

hi

first of all your code don't work like this and actually it's not that easy to see what's the problem pls post the rest...

second i don't even know what you want pls explain...

maybe it's my bad english but :D 

greetings

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

Sorry it isn't the full code. It's over 1000 lines so I think it would detract to post it all.

The application works fines as it is right now. I'm having trouble figuring out how to use GUISetAccelerators to get the Enter key to act like a button press on the GUICtrlCreateInput control.

Link to comment
Share on other sites

@dchaosw360
Having a script 1000 lines long is not an excuse to not post a valid reproducer script of your question, since you are asking for help about GUISetAccelerators, and in your script there is no such function, so, for the next time, just keep in mind it.
A slightly modified version of the example provided in the Help file about GUICtrlSetAccelerators():

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("Custom MsgBox", 225, 80)

    GUICtrlCreateLabel("Please select a button.", 10, 10)
    Local $idInput = GUICtrlCreateInput("Exit", 80, 50, 65, 25)

    ; Set GUIAccelerators for the Input control
    Local $aAccelKeys[1][2] = [["{ENTER}", $idInput]]
    GUISetAccelerators($aAccelKeys)

    GUISetState(@SW_SHOW) ; Display the GUI.

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idInput
                MsgBox($MB_SYSTEMMODAL, "", GUICtrlRead($idInput))

        EndSwitch
    WEnd
    GUIDelete() ; Delete the GUI.
EndFunc   ;==>Example

:)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Sorry. I've tried all the examples I found under the functions. Bottom line is I'm just not getting it. So I know it's my fault. Thanks for the response.

I'll take a closer look and see if I can figure it out. I left the code clean as opposed to post my attempts that didn't work, because I thought it would be more helpful.

Appreciate the assistance, and I'll see if I can understand what you posted.

 

 

Link to comment
Share on other sites

#Region Includes
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ColorConstants.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <EditConstants.au3>
#include <Excel.au3>
#include <ProgressConstants.au3>
#include <ListBoxConstants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <Date.au3>
#EndRegion Includes

#Region Variable Delarations
Local $UCIDOverride
Local $EUOverride
Local $Today
Local $idMore
Local $idDone
Local $a1
Local $a2
Local $aRET
Local $BCNPOS1
Local $BCNPOS2
Local $ChromeTXT
Local $ContactEmail
Local $ContactName
Local $Cost
Local $CRMHNDL
Local $CRMWin
Local $CTCNPOS1
Local $CTCNPOS2
Local $CTEMPOS1
Local $CTEMPOS2
Local $CTPOS1
Local $CTPOS2
Local $Discount
Local $DocTitle
Local $Domain
Local $DTPOS1
Local $DTPOS2
Local $EndUser
Local $EUPOS1
Local $EUPOS2
Local $Geninfo
Local $GeninfoHNDL
Local $GTPOS1
Local $GTPOS2
Local $HPEReqID
Local $HRIDPOS1
Local $HRIDPOS2
Local $idCheckbox
Local $idCustomBCN
Local $idCustomEU
Local $idCustomSP
Local $idGO
Local $idHPEReq
Local $idMsg
Local $idPriceAD
Local $idPriceExperis
Local $idPriceStd
Local $LineItems
Local $ListPrice
Local $LoopBreak
Local $LPPOS1
Local $LPPOS2
Local $LPVAL
Local $OCAUCID
Local $RANPOS1
Local $RANPOS2
Local $RealAccount
Local $RealBCN
Local $rows
Local $Shipping
Local $ShipVAL
Local $SHPOS1
Local $SHPOS2
Local $SpecialPricing
Local $SPPOS1
Local $SPPOS2
Local $Steps
Local $STPOS1
Local $STPOS2
Local $SubTotal
Local $SubVAL
Local $Template
Local $Total
Local $TotalVAL
Local $ValidUCID
Local $WatsonHNDL
Local $WatsonID
Local $WatsonWin
Local $idContact
Local $idCustomOCA
Local $idEmail
Local $idOCA
Local $LPCheck
Local $oExcel
Local $oWorkbook
Local $PriceCheck
Local $ShipCheck
Local $SubCheck
Local $sWorkbook
Local $ValidDomain
Local $idContact
Local $idCustomOCA
Local $idEmail
Local $idOCA
Local $LPCheck
Local $oExcel
Local $oWorkbook
Local $PriceCheck
Local $ShipCheck
Local $SubCheck
Local $sWorkbook
Local $cols
Local $aArray1D [4]
Local $Decision
Local $GUI1HNDL
Local $GUI2HNDL
Local $GUI3HNDL
#EndRegion Variable Declarations End

#Region Main

#RequireAdmin

HotKeySet("{ESC}", "Terminate")

BlockInput($BI_DISABLE)

;Main Loop
While 1
    IF $GUI1HNDL = "" Then
        $GUI1HNDL = GUICreate("Watson Automator", 270, 90, -1, -1, -1, $WS_EX_TOPMOST)
        GUICtrlCreateLabel("Please Enter HPE Req ID to Quote", 0, 10, 270, 20,$SS_CENTER)
        GUICtrlCreateLabel("HPE Req ID: ", 23, 30, 75, 20, $SS_RIGHT)
        $idHPEReq = GUICtrlCreateInput("", 105, 30, 135, 20)
        GUICtrlSetLimit(-1, 12)
        GUISetState(@SW_SHOW,$GUI1HNDL)
        $idGO= GUICtrlCreateButton("Automate", 85, 60, 100)
        $idMsg = 0
    Else
        GUICtrlSetData ($idHPEReq, "")
        GUISetState(@SW_SHOW, $GUI1HNDL)
        $idMsg = 0
    EndIf

    BlockInput($BI_ENABLE)
    While 1
        $idMsg = GUIGetMsg ()
        Select
            Case $idMsg = $idGO
            ExitLoop
        EndSelect
    WEnd
    $HPEReqID = GUICtrlRead($idHPEReq)

    BlockInput($BI_DISABLE)

    GUISetState(@SW_HIDE)

    ;Get Chrome
    GetChrome ()
    ;Check For Valid Domain
    If $ValidDomain = False Then
        BlockInput($BI_ENABLE)
        MsgBox (262144,"Invalid Customer", "Contact is from Ingram, Promark, or HPE. Hit OK when contact is correct.")
        BlockInput($BI_DISABLE)
        Sleep(250)
        GetChrome()
    EndIf


    ;Inner Loop Start
    While 1

        ;Get Watson
        GetWatson ()

        ;Validate
        ValidateQuote ()

        ;Fill Template
        FillTemplate ()

        ClipPut ($WatsonID & " - " & $HPEReqID)

        ;Do More ? Restart Loop
        If $GUI3HNDL = "" Then
            $GUI3HNDL = GUICreate("Watson Automator", 270, 110, -1, -1, -1, $WS_EX_TOPMOST)
            GUICtrlCreateLabel("More to price on this HPE Request?", 0, 10, 270, 20,$SS_CENTER)
            GUICtrlCreateLabel("Press Do Another when quote is ready", 0, 30, 270, 20,$SS_CENTER)
            GUICtrlCreateLabel("Press Done when this HPE Request is complete", 0, 50, 270, 20,$SS_CENTER)
            $idMore= GUICtrlCreateButton("Do Another", 10, 75, 100)
            $idDone= GUICtrlCreateButton("Done", 160, 75, 100)
            $idMsg = 0
            GUISetState(@SW_SHOW, $GUI3HNDL)
        Else
            $idMsg = 0
            GUISetState(@SW_SHOW, $GUI3HNDL)
        EndIf

        BlockInput($BI_ENABLE)
        $Decision = ""
        While 1
            Switch  GUIGetMsg ()
                Case $idMore
                    $Decision = "More"
                    ExitLoop
                Case $IdDone
                    $Decision = "Done"
                    ExitLoop
            EndSwitch
        WEnd

        BlockInput($BI_DISABLE)

        GUISetState(@SW_HIDE, $GUI3HNDL)

        If $Decision = "More" then ContinueLoop
        If $Decision = "Done" Then ExitLoop

    Wend ; Inner Loop End

WEnd

#EndRegion Main End

#Region Function
Func Terminate()
    Exit
EndFunc   ;==>Terminate

Func GetWatson()
    AutoItSetOption ( "WinTitleMatchMode" ,1 )

    $WatsonWin = WinList("Watson Quoter -")
    $WatsonHNDL = $WatsonWin [1] [1]
    WinActivate ($WatsonHNDL)
    WinWaitActive ($WatsonHNDL)
    Sleep (50)
    WinSetState ($WatsonHNDL,"",@SW_MAXIMIZE)
    Sleep (250)

    ;Watson ID
    ControlFocus ($WatsonHNDL,"","[NAME:txtDocNum]")
    Sleep (250)
    $WatsonID = ControlGetText($WatsonHNDL,"","[NAME:txtDocNum]")
    Sleep (250)

    If $WatsonID = "To be assigned" Or StringRight($WatsonID,3) = "rev" Then
        BlockInput($BI_ENABLE)
        MsgBox (262144,"Quote Not Saved", "Quote isn't saved. Press OK when quote has been saved.")
        BlockInput($BI_DISABLE)
        Sleep(250)
        ControlFocus ($WatsonHNDL,"","[NAME:txtDocNum]")
        Sleep (250)
        $WatsonID = ControlGetText($WatsonHNDL,"","[NAME:txtDocNum]")
        Sleep (250)
    EndIf

    ;Line Items Control
    ;ControlFocus ($WatsonHNDL,"","[CLASS:WindowsForms10.SCROLLBAR.app.0.378734a; INSTANCE:1]")
    ;Sleep (250)
    ;For $Steps = 1 to 50
    ;   ControlClick ($WatsonHNDL,"","[CLASS:WindowsForms10.SCROLLBAR.app.0.378734a; INSTANCE:1]", "LEFT" ,1, 30, 8)
    ;   Sleep (50)
    ;Next
    ;Sleep (250)

    ;Check for Valid Template
    ControlFocus ($WatsonHNDL,"","[NAME:dgQuoteLineItems]")
    Sleep (250)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^{HOME}")
    Sleep (1500)
    ControlClick ($WatsonHNDL,"","[NAME:dgQuoteLineItems]", "Left" ,1, 114, 26)
    Sleep (100)
    ControlClick ($WatsonHNDL,"","[NAME:dgQuoteLineItems]", "Left" ,1, 114, 26)
    Sleep (100)
    ControlClick ($WatsonHNDL,"","[NAME:dgQuoteLineItems]", "Left" ,1, 114, 26)
    Sleep (100)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^C")
    Sleep (100)

    $LineItems = ClipGet()
    $LineItems = StringStripCR ($LineItems)
    $LineItems = StringStripWS ($LineItems, 8)
    $LineItems = StringLeft ($LineItems,4)

    If $LineItems = "0100" Then
        BlockInput($BI_ENABLE)
        MsgBox (262144,"Wrong View", "Wrong Quote View. Press OK when view is correct.")
        BlockInput($BI_DISABLE)
        Sleep(250)
    EndIf

    ;Get Line item data
    ControlFocus ($WatsonHNDL,"","[NAME:dgQuoteLineItems]")
    Sleep (250)
    ControlClick ($WatsonHNDL,"","[NAME:dgQuoteLineItems]", "Left" ,1,103,60)
    Sleep (250)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^{HOME}")
    Sleep (250)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^{HOME}")
    Sleep (250)
    ControlClick ($WatsonHNDL,"","[NAME:dgQuoteLineItems]", "Left" ,1,103,60)
    Sleep (250)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^+{END}")
    Sleep (2000)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^C")
    Sleep (250)
    ControlSend ($WatsonHNDL, "", "[NAME:dgQuoteLineItems]", "^{HOME}")

    $LineItems = ClipGet()
    $a1 = StringRegExp($LineItems, '[^\r\n]+', 3)
    $rows = UBound($a1)
    $cols = 0

    ; determine max number of columns
    For $i = 0 To UBound($a1) - 1
        StringReplace($a1[$i], @TAB, '')
        $cols = (@extended > $cols ? @extended : $cols)
    Next

    ; define and populate array
    Global $aRET[$rows][$cols + 1]
    For $i = 0 To UBound($a1) - 1
        $a2 = StringSplit($a1[$i], @TAB, 3)
        For $j = 0 To UBound($a2) - 1
            $aRET[$i][$j] = $a2[$j]
        Next
    Next

    ;Grab OCA UCID and Document Title for other option then validate it
    ControlFocus ($WatsonHNDL,"","[NAME:toolStrip1]")
    Sleep (250)
    ControlClick ($WatsonHNDL,"","[NAME:toolStrip1]", "Left" ,1,267,12)
    Sleep (250)
    WinWait ("General Quote Info")
    $Geninfo = WinList("General Quote Info")
    Sleep (400)
    $GeninfoHNDL = $Geninfo [1] [1]
    Sleep (400)
    ControlFocus ($GeninfoHNDL,"","[NAME:txtDocName]")
    Sleep (400)
    $DocTitle = ControlGetText($GeninfoHNDL,"","[NAME:txtDocName]")
    Sleep (400)
    ControlFocus ($GeninfoHNDL,"","[NAME:txtRefDocID]")
    Sleep (400)
    $OCAUCID = ControlGetText($GeninfoHNDL,"","[NAME:txtRefDocID]")
    Sleep (400)
    ControlClick ($GeninfoHNDL,"","[NAME:btnCancel]", "Left",1,52,6)
    WinWaitClose ("General Quote Info")

    $ValidUCID = True
    If StringLen ($OCAUCID) <> 13 Then $OCAUCID = StringRight($DocTitle,13)
    If StringMid ($OCAUCID,11,1) <> "-" Then
        $ValidUCID = False
        $OCAUCID = ""
    EndIf
    If StringIsDigit (StringLeft ($OCAUCID,10)) <> 1 Then
        $ValidUCID = False
        $OCAUCID = ""
    EndIf
    If StringIsDigit (StringRight ($OCAUCID,2)) <> 1 Then
        $ValidUCID = False
        $OCAUCID = ""
    EndIf

    ;Grab Watson Totals
    ControlFocus ($WatsonHNDL,"","[NAME:dgvQuoteTotals]")
    Sleep (400)
    ControlSend ($WatsonHNDL, "", "[NAME:dgvQuoteTotals]", "^a")
    Sleep (400)
    ControlSend ($WatsonHNDL, "", "[NAME:dgvQuoteTotals]", "^c")
    Sleep (400)
    ControlSend ($WatsonHNDL, "", "[NAME:dgvQuoteTotals]", "^+{HOME}")
    $QuoteTotals = ClipGet()
    $QuoteTotals = StringStripCR($QuoteTotals)
    $QuoteTotals = StringStripWS($QuoteTotals,7)

    ;Get MSRP
    $LPPOS1 = StringInStr ($QuoteTotals, "Gross Price")
    $LPPOS2 = StringInStr ($QuoteTotals, "Global Discount",0,1,$LPPOS1)
    $ListPrice = StringMid ($QuoteTotals,$LPPOS1 + 12,$LPPOS2 - $LPPOS1 - 13)
    $LPVAL = StringReplace ($ListPrice,"$","")
    $LPVAL = StringReplace ($LPVAL,",","")

    ;Get Total Discounts for MSRP Validation
    $DTPOS1 = StringInStr ($QuoteTotals, "Discount Total",0,1,$LPPOS2)
    $DTPOS2 = StringInStr ($QuoteTotals, "Regulatory Fee",0,1,$DTPOS1)
    $Discount = StringMid ($QuoteTotals,$DTPOS1 + 15 ,$DTPOS2 - $DTPOS1 - 16)
    ;Strip ( and ) if they are there
    $Discount = StringReplace ($Discount,"(","")
    $Discount = StringReplace ($Discount,")","")

    ;Get Subtotal
    $STPOS1 = StringInStr ($QuoteTotals, "Subtotal",0,1,$DTPOS2)
    $STPOS2 = StringInStr ($QuoteTotals, "Cost Subtotal",0,1,$STPOS1)
    $SubTotal = StringMid ($QuoteTotals,$STPOS1 + 9 ,$STPOS2 - $STPOS1 - 10)
    $SubVAL = StringReplace ($SubTotal,"$","")
    $SubVAL = StringReplace ($SubVAL,",","")

    ;Get Shipping Cost
    $SHPOS1 = StringInStr ($QuoteTotals, "Shipping",0,1,$STPOS2)
    $SHPOS2 = StringInStr ($QuoteTotals, "Cost Grand",0,1,$SHPOS1)
    $Shipping = StringMid ($QuoteTotals,$SHPOS1 + 22 ,$SHPOS2 - $SHPOS1 - 23)
    If $SHPOS2 = $SHPOS1 + 22 then $Shipping = "$0.00"
    $ShipVAL = StringReplace ($Shipping,"$","")
    $ShipVAL = StringReplace ($ShipVAL,",","")

    ;Get Grand Total for customer = Shipping + Subtotal
    $GTPOS1 = StringInStr ($QuoteTotals, "Grand Total",0,2,$SHPOS2)
    $GTPOS2 = StringInStr ($QuoteTotals, "Cost",0,1,$GTPOS1)
    $Total = StringMid ($QuoteTotals,$GTPOS1 + 12 ,$GTPOS2 - $GTPOS1 - 13)
    $TotalVAL = StringReplace ($Total,"$","")
    $TotalVAL = StringReplace ($TotalVAL,",","")

    ;Get Ingram Cost for MSRP Validation = MSRP - Total Discounts + Shipping Cost
    $CTPOS1 = StringInStr ($QuoteTotals, "Cost Grand Total",0,1,$GTPOS2)
    $CTPOS2 = StringLen($QuoteTotals)+1
    $Cost = StringMid ($QuoteTotals,$CTPOS1 + 17 ,$CTPOS2 - $CTPOS1 - 17)
EndFunc

Func FillTemplate ()
    If $Template = "Standard" Then
        ; Create application object
        $oExcel = _Excel_Open()
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        Sleep (1000)
        ; Open an existing workbook and return its object identifier.
        $sWorkbook = @ScriptDir & "\2019 Watson Quote Template.xlsx"
        $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        ;Maximize Excel
        Sleep (1000)
        Global $xlMaximized = -4137
        $oExcel.Application.Activewindow.WindowState = $xlMaximized
        Sleep (1000)

        ;Populate Quote
        Sleep (250)
        $Today = _DateTimeFormat(_NowCalc(), 2)
        Global $aArray1D [5] = [$WatsonID, $RealAccount, $OCAUCID, $EndUser, $Today]
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "C1")

        Sleep (250)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Shipping, "F5")

        Sleep (250)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aRET, "A15")

        Sleep (1000)
        $LPCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F3")

        Sleep (250)
        $SubCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F4")

        Sleep (250)
        $ShipCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F5")

        Sleep (250)
        $PriceCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F6")

        If $LPCheck <> $LPVAL Then
            MsgBox(262144,"", "List Price Mismatch!",20)
        ElseIf $ShipCheck <> $ShipVAL Then
            MsgBox(262144,"", "Shipping Price Mismatch!",20)
        ElseIf $SubCheck <> $SubVAL Then
            MsgBox(262144,"", "Subtotal Price Mismatch!",20)
        Elseif $PriceCheck <> $TotalVAL Then
            MsgBox(262144,"", "Total Price Mismatch!",20)
        EndIf

    ElseIf $Template = "AD" Then

        ; Create application object
        $oExcel = _Excel_Open()
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        Sleep (1000)
        ; Open an existing workbook and return its object identifier.
        $sWorkbook = @ScriptDir & "\AD Template.xlsm"
        $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        ;Maximize Excel
        Sleep (1000)
        Global $xlMaximized = -4137
        $oExcel.Application.Activewindow.WindowState = $xlMaximized

        ;Populate Quote
        Sleep (250)
        $Today = _DateTimeFormat(_NowCalc(), 2)
        Global $aArray1D[5] = [$WatsonID, $RealAccount, $OCAUCID, $EndUser, $Today]
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "D1")

        Sleep (250)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Shipping, "G5")

        Sleep (250)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aRET, "B15")

        Sleep (1000)
        $LPCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "G3")

        Sleep (250)
        $SubCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "G4")

        Sleep (250)
        $ShipCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "G5")

        Sleep (250)
        $PriceCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "G6")

        If $LPCheck <> $LPVAL Then
            MsgBox(262144,"", "List Price Mismatch!",20)
        ElseIf $ShipCheck <> $ShipVAL Then
            MsgBox(262144,"", "Shipping Price Mismatch!",20)
        ElseIf $SubCheck <> $SubVAL Then
            MsgBox(262144,"", "Subtotal Price Mismatch!",20)
        Elseif $PriceCheck <> $TotalVAL Then
            MsgBox(262144,"", "Total Price Mismatch!",20)
        EndIf

    Else

        ; Create application object
        $oExcel = _Excel_Open()
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        Sleep (1000)
        ; Open an existing workbook and return its object identifier.
        $sWorkbook = @ScriptDir & "\Experis Quote Template.xlsx"
        $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

        ;Maximize Excel
        Sleep (1000)
        Global $xlMaximized = -4137
        $oExcel.Application.Activewindow.WindowState = $xlMaximized

        ;Populate Quote
        Sleep (250)
        $Today = _DateTimeFormat(_NowCalc(), 2)
        Global $aArray1D[5] = [$WatsonID, $RealAccount, $OCAUCID, $EndUser, $Today]
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "C1")

        Sleep (250)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $Shipping, "F5")

        Sleep (1000)
        _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aRET, "A15")

        Sleep (250)
        $LPCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F3")

        Sleep (250)
        $ShipCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F5")

        Sleep (250)
        $PriceCheck = _Excel_RangeRead($oWorkbook, $oWorkbook.Activesheet, "F7")

        $SubCheck = $PriceCheck - $ShipCheck

        If $LPCheck <> $LPVAL Then
            MsgBox(262144,"", "List Price Mismatch!",20)
        ElseIf $ShipCheck <> $ShipVAL Then
            MsgBox(262144,"", "Shipping Price Mismatch!",20)
        Elseif $PriceCheck <> $TotalVAL Then
            MsgBox(262144,"", "Total Price Mismatch!",20)
        EndIf

    EndIf
EndFunc

Func GetChrome ()

    AutoItSetOption ( "WinTitleMatchMode" ,2 )
    $CRMWin = WinList("- Google Chrome")
    $CRMHNDL = $CRMWin [1] [1]
    WinActivate ($CRMHNDL)
    WinWaitActive($CRMHNDL)
    WinSetState ($CRMHNDL,"",@SW_MAXIMIZE)

    $LoopBreak = 0
    While WinGetTitle ($CRMHNDL) <> "HPE Request: " & $HPEReqID & " - Google Chrome"
        Send ("^{TAB}")
        Sleep (500)
        $LoopBreak = $LoopBreak + 1
        If $LoopBreak > 20 Then Exit
    Wend

    Sleep(500)

    Send ("^a")
    Sleep(500)
    Send ("^c")
    Sleep(500)
    Send ("^+{HOME}")
    Sleep (500)
    $ChromeTXT= ClipGet ()

    Sleep(250)

    $ChromeTXT = StringStripCR($ChromeTXT)
    $ChromeTXT = StringStripWS($ChromeTXT,7)

    Sleep (250)

    $HRIDPOS1 = StringInStr ($ChromeTXT, "HPE Request ID Required")
    $HRIDPOS2 = StringInStr ($ChromeTXT, "Locked control",0,1,$HRIDPOS1)
    $HPEReqID = StringMid ($ChromeTXT,$HRIDPOS1+23,$HRIDPOS2 - $HRIDPOS1 - 24)

    $RANPOS1 = StringInStr ($ChromeTXT, "Recommended",0,1,$HRIDPOS2)
    $RANPOS2 = StringInStr ($ChromeTXT, "BCN",0,1,$RANPOS1)
    $RealAccount = StringMid ($ChromeTXT,$RANPOS1+19,$RANPOS2 - $RANPOS1-20)

    $BCNPOS1 = StringInStr ($ChromeTXT, "BCN",0,1,$RANPOS2+3)
    $BCNPOS2 = StringInStr ($ChromeTXT, "Country",0,1,$BCNPOS1)
    $RealBCN = StringMid ($ChromeTXT,$BCNPOS1+3,$BCNPOS2 - $BCNPOS1-4)

    $CTCNPOS1 = StringInStr ($ChromeTXT, "Contact",0,1,$BCNPOS2+3)
    $CTCNPOS2 = StringInStr ($ChromeTXT, "E-Mail",0,1,$CTCNPOS1)
    $ContactName = StringMid ($ChromeTXT,$CTCNPOS1+24,$CTCNPOS2 - $CTCNPOS1-25)

    $CTEMPOS1 = StringInStr ($ChromeTXT, "E-Mail",0,1,$CTCNPOS2)
    $CTEMPOS2 = StringInStr ($ChromeTXT, "Business",0,1,$CTEMPOS1)
    $ContactEmail = StringMid ($ChromeTXT,$CTEMPOS1+25,$CTEMPOS2 - $CTEMPOS1-26)
    $Domain = StringMid($ContactEmail,StringInStr($ContactEmail,"@",0,1,1)+1,StringLen($ContactEmail))
    If $Domain = "ingrammicro.com" Then
        $ValidDomain = False
    ElseIf $Domain = "promarktech.com" Then
        $ValidDomain = False
    ElseIf $Domain ="hpe.com" Then
        $ValidDomain = False
    Else
        $ValidDomain = True
    EndIf

    $SPPOS1 = StringInStr ($ChromeTXT, "Special Pricing",0,1,$CTEMPOS2)
    $SPPOS2 = StringInStr ($ChromeTXT, "End User",0,1,$SPPOS1)
    $SpecialPricing = StringMid ($ChromeTXT,$SPPOS1+31,$SPPOS2 - $SPPOS1-32)

    $EUPOS1 = StringInStr ($ChromeTXT, "End User",0,1,$SPPOS2)
    $EUPOS2 = StringInStr ($ChromeTXT, "Inside",0,1,$EUPOS1)
    $EndUser = StringMid ($ChromeTXT,$EUPOS1+17,$EUPOS2 - $EUPOS1-18)

    Sleep (500)

EndFunc

Func ValidateQuote()
    $UCIDOverride = ""
    $EUOverride = ""
    $idCustomEU = ""
    $idCustomOCA = ""
    ; Create GUI
    GUICreate("Watson Automator", 600, 380, -1, -1, -1, $WS_EX_TOPMOST)
    GUICtrlCreateLabel("HPE Req ID: ", 8, 40, 75, 20, $SS_RIGHT)
    GUICtrlCreateLabel($HPEReqID , 90, 40, 300, 20)
    GUICtrlCreateLabel("Reseller: ", 8, 60, 75, 20, $SS_RIGHT)
    GUICtrlCreateLabel($RealAccount, 90, 60, 300, 20)
    GUICtrlCreateLabel("BCN: ", 8, 80, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($RealBCN, 90, 80, 300, 20)
    ;$idCustomBCN = GUICtrlCreateInput("", 240, 80, 320, 20, $ES_NUMBER)
    ;GUICtrlSetLimit(-1, 8)
    If $ValidDomain = True Then
        GUICtrlCreateLabel("Contact: ", 8, 100, 75, 20,$SS_RIGHT)
        GUICtrlCreateLabel($ContactName, 90, 100, 300, 20)
        GUICtrlCreateLabel("Email: ", 8, 120, 74, 20,$SS_RIGHT)
        GUICtrlCreateLabel($ContactEmail, 90, 120, 300, 20)
    Else
        GUICtrlCreateLabel("Contact: ", 8, 100, 75, 20,$SS_RIGHT)
        $idContact =GUICtrlCreateLabel($ContactName, 90, 100, 320, 20)
        GUICtrlSetColor($idContact, $COLOR_RED)
        GUICtrlCreateLabel("Email: ", 8, 120, 74, 20,$SS_RIGHT)
        $idEmail = GUICtrlCreateLabel($ContactEmail, 90, 120, 320, 20)
        GUICtrlSetColor($idEmail, $COLOR_RED)
    EndIf
    GUICtrlCreateLabel("End User: ", 8, 140, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($EndUser, 90, 140, 250, 20)
    $idCustomEU = GUICtrlCreateInput("", 350, 140, 210, 20)
    GUICtrlCreateLabel("Special Pricing: ", 8, 160, 75, 20, $SS_RIGHT)
    GUICtrlCreateLabel($SpecialPricing, 90, 160, 300, 20)
    ;$idCustomSP = GUICtrlCreateInput("", 240, 160, 320, 20)
    GUICtrlCreateLabel("Watson ID: ", 8, 180, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($WatsonID, 90, 180, 300, 20)
    If $ValidUCID = True Then
        GUICtrlCreateLabel("OCA UCID: ", 8, 200, 75, 20,$SS_RIGHT)
        GUICtrlCreateLabel($OCAUCID, 90, 200, 300, 20)
    Else
        GUICtrlCreateLabel("OCA UCID: ", 8, 200, 75, 20,$SS_RIGHT)
        $idOCA = GUICtrlCreateLabel("Invalid OCA Number", 90, 200, 250, 20)
        GUICtrlSetColor($idOCA, $COLOR_RED)
        $idCustomOCA = GUICtrlCreateInput("", 350, 200, 210, 20)
        GUICtrlSetLimit(-1, 13)
    EndIf
    GUICtrlCreateLabel("Total List: ", 8, 220, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($ListPrice, 90, 220, 300, 20)
    GUICtrlCreateLabel("SubTotal: ", 8, 240, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($SubTotal, 90, 240, 300, 20)
    GUICtrlCreateLabel("Shipping: ", 8, 260, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($Shipping, 90, 260, 300, 20)
    GUICtrlCreateLabel("Grand Total: ", 10, 280, 75, 20,$SS_RIGHT)
    GUICtrlCreateLabel($Total, 90, 280, 300, 20)

    $idCheckbox = GUICtrlCreateCheckbox("Data Validated", 10, 310, 185, 25)

    GUISetState(@SW_SHOW)
    BlockInput($BI_ENABLE)

    ; Wait for price validation checkbox to be selected
    While 1
        Switch GUIGetMsg()
            Case $idCheckbox
                If GUICtrlRead($idCheckbox) = $GUI_CHECKED Then
                    ExitLoop
                EndIf
        EndSwitch
    WEnd

    ; Display price quote button on GUI
    $idPriceStd = GUICtrlCreateButton("Price Standard", 10, 340, 100)
    $idPriceAD = GUICtrlCreateButton("Price AD", 150, 340, 100)
    $idPriceExperis = GUICtrlCreateButton("Price Experis", 290, 340, 100)

    $Template = ""
    ; Wait for Price Quote Button on GUI to be pressed
    $idMsg = 0
    While 1
        $idMsg = GUIGetMsg ()
        Select
            Case $idMsg = $idPriceStd
                $Template = "Standard"
                ExitLoop
            Case $idMsg = $idPriceAD
                $Template = "AD"
                ExitLoop
            Case $idMsg = $idPriceExperis
                $Template = "Experis"
                ExitLoop
            Case $idMsg = $GUI_EVENT_CLOSE
            ExitLoop
        EndSelect
    WEnd
    BlockInput($BI_DISABLE)
    $UCIDOverride = GUICtrlRead ($idCustomOCA)
    If $UCIDOverride <> "" Then $OCAUCID = $UCIDOverride
    $EUOverride = GUICtrlRead ($idCustomEU)
    If $EUOverride <> "" Then $EndUser = $EUOverride

    GUIDelete()
EndFunc

#Region Function End

And here is the complete code

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