Jump to content

Weird Problem


Recommended Posts

I am not sure why but if I click on one of the input boxes enter data and hit TAB to got to the next one it doesn't calculate like it should. If I click on one of the other input boxes it calculates just fine. Here is the weird part it only happens the first time you hit TAB if you hit it a second time it calculates properly (for that input only). It is as if it doesn't recognize the first data entry. It happens with every input but only the first time!

CODE
#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=

$frmMove_1 = GUICreate("New Equipment Move", 370, 307, 272, 155)

$Label1 = GUICtrlCreateLabel("In Town Move?", 0, 12, 111, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$cmbInTown = GUICtrlCreateCombo("Yes", 232, 10, 60, 28)

GUICtrlSetData(-1, "No")

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Submit = GUICtrlCreateButton("Submit", 272, 272, 89, 25, 0)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

GUICtrlSetBkColor(-1, 0xA6CAF0)

$lblInTown = GUICtrlCreateLabel("195.00", 304, 12, 53, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Label2 = GUICtrlCreateLabel("Milage", 0, 47, 50, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$txtMilage = GUICtrlCreateInput("", 232, 45, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$lblMilage = GUICtrlCreateLabel("", 304, 45, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Label3 = GUICtrlCreateLabel("How Many Machines?", 0, 82, 159, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$txtMachines = GUICtrlCreateInput("", 232, 80, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$lblMachines = GUICtrlCreateLabel("", 304, 80, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Label4 = GUICtrlCreateLabel("How Many Drivers?", 0, 118, 140, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$txtDrivers = GUICtrlCreateInput("", 232, 116, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$lblDrivers = GUICtrlCreateLabel("", 304, 116, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Label6 = GUICtrlCreateLabel("Any Special Circumstances?", 0, 153, 205, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$cmbSpecial = GUICtrlCreateCombo("No", 232, 151, 60, 28)

GUICtrlSetData(-1, "Yes")

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$lblSpecial = GUICtrlCreateLabel("", 304, 151, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$Label8 = GUICtrlCreateLabel("Additional Costs?", 0, 188, 132, 24)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$txtCost = GUICtrlCreateInput("", 232, 186, 60, 28)

GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")

$lblTotal = GUICtrlCreateLabel("195.00", 296, 232, 72, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$Label9 = GUICtrlCreateLabel("Total", 232, 232, 60, 28)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$btnClear = GUICtrlCreateButton("Clear", 8, 272, 89, 25, 0)

GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlSetBkColor(-1, 0x800000)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$InTown = GUICtrlRead($lblInTown)

$Milage = GUICtrlRead($lblMilage)

$Machines = GUICtrlRead($lblMachines)

$Drivers = GUICtrlRead($lblDrivers)

$Special = GUICtrlRead($lblSpecial)

$Cost = GUICtrlRead($txtCost)

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $cmbInTown

If GUICtrlRead($cmbInTown) = ("Yes") Then

GUICtrlSetData($lblInTown,"195.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblInTown)+ $Milage + $Machines + $Drivers + $Special + $Cost & ".00"))

Else

GUICtrlSetData($lblInTown,"250.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblInTown)+ $Milage + $Machines + $Drivers + $Special + $Cost & ".00"))

EndIf

Case $txtMilage

If (GUICtrlRead($txtMilage) >10) Then

GUICtrlSetData($lblMilage,(GUICtrlRead($txtMilage) * 2 - 20 & ".00"))

GUICtrlSetData($lblTotal, (GUICtrlRead($lblMilage)+ $InTown + $Machines + $Drivers + $Special + $Cost & ".00"))

Else

GUICtrlSetData($lblMilage,"0.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblMilage)+ $InTown + $Machines + $Drivers + $Special + $Cost & ".00"))

EndIf

Case $txtMachines

If (GUICtrlRead($txtMachines) >1) then

GUICtrlSetData($lblMachines,(GUICtrlRead($txtMachines) * 25 - 25 & ".00"))

GUICtrlSetData($lblTotal, (GUICtrlRead($lblMachines)+ $InTown + $Milage + $Drivers + $Special + $Cost & ".00"))

Else

GUICtrlSetData($lblMachines,"0.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblMachines)+ $InTown + $Milage + $Drivers + $Special + $Cost & ".00"))

EndIf

Case $txtDrivers

If (GUICtrlRead($txtDrivers) >1) then

GUICtrlSetData($lblDrivers,(GUICtrlRead($txtDrivers) * 95 - 95 & ".00"))

GUICtrlSetData($lblTotal, (GUICtrlRead($lblDrivers)+ $InTown + $Milage + $Machines + $Special + $Cost & ".00"))

Else

GUICtrlSetData($lblDrivers,"0.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblDrivers)+ $InTown + $Milage + $Machines + $Special + $Cost & ".00"))

EndIf

Case $cmbSpecial

If GUICtrlRead($cmbSpecial) = ("Yes") Then

GUICtrlSetData($lblSpecial,"50.00")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblSpecial)+ $InTown + $Milage + $Machines + $Drivers + $Cost & ".00"))

Else

GUICtrlSetData($lblSpecial,"")

GUICtrlSetData($lblTotal, (GUICtrlRead($lblSpecial)+ $InTown + $Milage + $Machines + $Drivers + $Cost & ".00"))

EndIf

Case $txtCost

GUICtrlSetData($lblTotal, (GUICtrlRead($txtCost)+ $InTown + $Milage + $Machines + $Drivers + $Special & ".00"))

Case $btnClear

Reset()

EndSwitch

If $nMsg = $Submit Then Submit()

WEnd

Func Submit()

GUISetCursor(15)

Opt("SendKeyDelay", 150)

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

$Total = GUICtrlRead($lblTotal)

$Drivers = GUICtrlRead($lblDrivers)

$Tab = "{TAB}"

$Space = "{SPACE}"

ShellExecute("New Equipment Move.pdf")

WinWaitActive("New Equipment Move.pdf", 5)

If WinActive("New Equipment Move.pdf") Then

; Disable mouse and keyboard

BlockInput(1)

; Sends text

Sleep(200)

Send("{TAB}")

Send("1")

Send("{TAB}")

Send("1")

Send("{TAB}")

Send(@MON & "/" & @MDAY & "/" & @YEAR)

Sleep(100)

Send("{TAB 21}")

If $Drivers <2 then

Send($Space)

Else

Send($Tab)

EndIf

Sleep(100)

If $Drivers >1 then

Send($Space)

Else

Send($Tab)

EndIf

Send("{TAB 5}")

Send($Total)

; Enable mouse and keyboard

BlockInput(0)

GUISetCursor(2)

EndIf

EndFunc

Func Reset()

GUICtrlSetData($lblInTown,"195.00")

GUICtrlSetData($lblMachines,"")

GUICtrlSetData($lblMilage,"")

GUICtrlSetData($lblDrivers,"")

GUICtrlSetData($lblSpecial,"")

GUICtrlSetData($lblTotal,"195.00")

GUICtrlSetData($txtCost,"")

GUICtrlSetData($txtDrivers,"")

GUICtrlSetData($txtMachines,"")

GUICtrlSetData($txtMilage,"")

GUICtrlSetData($cmbInTown,"Yes")

GUICtrlSetData($cmbSpecial,"No")

EndFunc

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Link to comment
Share on other sites

If I click in an input box, enter a number and press TAB then it calculates OK for me, so I don't get the problem you describe.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I don't see any particular problem with your script but it would help if you created the controls in the same order that you want to tab between them. The first tab takes me to Submit because that's the control that's created after the Combo. Just thought .. is that what you're talking about?

WBD

Link to comment
Share on other sites

It only happens the first time you run it and only the very first time.

For me it works first time. WHich input boxe are you trying for the first time and what do you enter in it before you press TAB?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

For me it works first time. WHich input boxe are you trying for the first time and what do you enter in it before you press TAB?

For me it does it with any of them and If I enter 1 or 1000 when I hit tab it doesn't calculate at all.

But the next box will after I hit TAB.

[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!
Link to comment
Share on other sites

For me it does it with any of them and If I enter 1 or 1000 when I hit tab it doesn't calculate at all.

But the next box will after I hit TAB.

Try this and see if it overcomes your problem.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$frmMove_1 = GUICreate("New Equipment Move", 370, 307, 272, 155)
$Label1 = GUICtrlCreateLabel("In Town Move?", 0, 12, 111, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$cmbInTown = GUICtrlCreateCombo("Yes", 232, 10, 60, 28)
GUICtrlSetData(-1, "No")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Submit = GUICtrlCreateButton("Submit", 272, 272, 89, 25, 0)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xA6CAF0)
$lblInTown = GUICtrlCreateLabel("195.00", 304, 12, 53, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Milage", 0, 47, 50, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$txtMilage = GUICtrlCreateInput("", 232, 45, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$lblMilage = GUICtrlCreateLabel("", 304, 45, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("How Many Machines?", 0, 82, 159, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$txtMachines = GUICtrlCreateInput("", 232, 80, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$lblMachines = GUICtrlCreateLabel("", 304, 80, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("How Many Drivers?", 0, 118, 140, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$txtDrivers = GUICtrlCreateInput("", 232, 116, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$lblDrivers = GUICtrlCreateLabel("", 304, 116, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Any Special Circumstances?", 0, 153, 205, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$cmbSpecial = GUICtrlCreateCombo("No", 232, 151, 60, 28)
GUICtrlSetData(-1, "Yes")
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$lblSpecial = GUICtrlCreateLabel("", 304, 151, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label8 = GUICtrlCreateLabel("Additional Costs?", 0, 188, 132, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$txtCost = GUICtrlCreateInput("", 232, 186, 60, 28)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$lblTotal = GUICtrlCreateLabel("195.00", 296, 232, 72, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label9 = GUICtrlCreateLabel("Total", 232, 232, 60, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$btnClear = GUICtrlCreateButton("Clear", 8, 272, 89, 25, 0)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x800000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
ControlFocus($frmMove_1, "", $cmbInTown)
$lastIP = $cmbInTown
While 1

    $InTown = GUICtrlRead($lblInTown)
    $Milage = GUICtrlRead($lblMilage)
    $Machines = GUICtrlRead($lblMachines)
    $Drivers = GUICtrlRead($lblDrivers)
    $Special = GUICtrlRead($lblSpecial)
    $Cost = GUICtrlRead($txtCost)

    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $btnClear
            Reset()
        Case $Submit
            Submit()
    EndSwitch

    $thisFocus = ControlGetFocus($frmMove_1)
    If $thisFocus <> "" And $thisFocus <> $lastIP Then
        
        Switch $lastIP
            Case $cmbInTown, "Edit1", "ComboBox1"
                ConsoleWrite("intown" & @CRLF)
                If GUICtrlRead($cmbInTown) = ("Yes") Then
                    GUICtrlSetData($lblInTown, "195.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblInTown) + $Milage + $Machines + $Drivers + $Special + $Cost & ".00"))
                Else
                    GUICtrlSetData($lblInTown, "250.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblInTown) + $Milage + $Machines + $Drivers + $Special + $Cost & ".00"))
                EndIf
            Case $txtMilage, "Edit2"
                ConsoleWrite("mileage" & @CRLF)
                If (GUICtrlRead($txtMilage) > 10) Then
                    GUICtrlSetData($lblMilage, (GUICtrlRead($txtMilage) * 2 - 20 & ".00"))
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblMilage) + $InTown + $Machines + $Drivers + $Special + $Cost & ".00"))
                Else
                    GUICtrlSetData($lblMilage, "0.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblMilage) + $InTown + $Machines + $Drivers + $Special + $Cost & ".00"))
                EndIf
            Case $txtMachines, "Edit3"
                ConsoleWrite("machine" & @CRLF)
                If (GUICtrlRead($txtMachines) > 1) Then
                    GUICtrlSetData($lblMachines, (GUICtrlRead($txtMachines) * 25 - 25 & ".00"))
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblMachines) + $InTown + $Milage + $Drivers + $Special + $Cost & ".00"))
                Else
                    GUICtrlSetData($lblMachines, "0.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblMachines) + $InTown + $Milage + $Drivers + $Special + $Cost & ".00"))
                EndIf
            Case $txtDrivers, "Edit4"
                ConsoleWrite("drivers" & @CRLF)
                If (GUICtrlRead($txtDrivers) > 1) Then
                    GUICtrlSetData($lblDrivers, (GUICtrlRead($txtDrivers) * 95 - 95 & ".00"))
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblDrivers) + $InTown + $Milage + $Machines + $Special + $Cost & ".00"))
                Else
                    GUICtrlSetData($lblDrivers, "0.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblDrivers) + $InTown + $Milage + $Machines + $Special + $Cost & ".00"))
                EndIf
            Case $cmbSpecial, "Edit5", "ComboBox2"
                ConsoleWrite("special" & @CRLF)
                If GUICtrlRead($cmbSpecial) = ("Yes") Then
                    GUICtrlSetData($lblSpecial, "50.00")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblSpecial) + $InTown + $Milage + $Machines + $Drivers + $Cost & ".00"))
                Else
                    GUICtrlSetData($lblSpecial, "")
                    GUICtrlSetData($lblTotal, (GUICtrlRead($lblSpecial) + $InTown + $Milage + $Machines + $Drivers + $Cost & ".00"))
                EndIf
            Case $txtCost, "Edit6"
                ConsoleWrite("cost" & @CRLF)
                GUICtrlSetData($lblTotal, (GUICtrlRead($txtCost) + $InTown + $Milage + $Machines + $Drivers + $Special & ".00"))

        EndSwitch
        $lastIP = $thisFocus
    EndIf





WEnd


Func Submit()
    GUISetCursor(15)
    Opt("SendKeyDelay", 150)
    Opt("WinTitleMatchMode", 2);1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

    $Total = GUICtrlRead($lblTotal)
    $Drivers = GUICtrlRead($lblDrivers)

    $Tab = "{TAB}"
    $Space = "{SPACE}"
    ShellExecute("New Equipment Move.pdf")

    WinWaitActive("New Equipment Move.pdf", 5)

    If WinActive("New Equipment Move.pdf") Then

       ; Disable mouse and keyboard
        BlockInput(1)

       ; Sends text
        Sleep(200)
        Send("{TAB}")
        Send("1")
        Send("{TAB}")
        Send("1")
        Send("{TAB}")
        Send(@MON & "/" & @MDAY & "/" & @YEAR)
        Sleep(100)
        Send("{TAB 21}")
        If $Drivers < 2 Then
            Send($Space)
        Else
            Send($Tab)
        EndIf
        Sleep(100)
        If $Drivers > 1 Then
            Send($Space)
        Else
            Send($Tab)
        EndIf
        Send("{TAB 5}")
        Send($Total)

       ; Enable mouse and keyboard
        BlockInput(0)
        GUISetCursor(2)
    EndIf
EndFunc  ;==>Submit

Func Reset()

    GUICtrlSetData($lblInTown, "195.00")
    GUICtrlSetData($lblMachines, "")
    GUICtrlSetData($lblMilage, "")
    GUICtrlSetData($lblDrivers, "")
    GUICtrlSetData($lblSpecial, "")
    GUICtrlSetData($lblTotal, "195.00")
    GUICtrlSetData($txtCost, "")
    GUICtrlSetData($txtDrivers, "")
    GUICtrlSetData($txtMachines, "")
    GUICtrlSetData($txtMilage, "")
    GUICtrlSetData($cmbInTown, "Yes")
    GUICtrlSetData($cmbSpecial, "No")

EndFunc  ;==>Reset
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

YES! That did fix my problem. Thank you!

Have you seen this before?

No, but I couldn't reproduce the problem so I thought the best thing to do was to detect when the focus moved away from an edit.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...