Sign in to follow this  
Followers 0
Rogue5099

Clean up code and add "Per Hour?"

6 posts in this topic

#1 ·  Posted (edited)

So I work from 10pm - 6am and would like the script to calculate the parts I'm running per hour. Basically at 1am do TotalParts/3 = Parts Per hour.

Also is there a cleaner way to do the Buttons like useing $LayerTotal[$i]? or $LayerPlus[$i]?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Stegg Production 704394 Rev. 01", 393, 409, 415, 166)
GUICtrlCreateGroup("Layer 1", 8, 8, 193, 65)
$LayerPlus1 = GUICtrlCreateButton("+", 24, 32, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerMinus1 = GUICtrlCreateButton("-", 80, 32, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerTotal1 = GUICtrlCreateLabel("0", 144, 24, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Layer 2", 8, 88, 193, 65)
$LayerPlus2 = GUICtrlCreateButton("+", 24, 112, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerMinus2 = GUICtrlCreateButton("-", 80, 112, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerTotal2 = GUICtrlCreateLabel("0", 144, 104, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Layer 3", 8, 168, 193, 65)
$LayerPlus3 = GUICtrlCreateButton("+", 24, 192, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerMinus3 = GUICtrlCreateButton("-", 80, 192, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerTotal3 = GUICtrlCreateLabel("0", 144, 184, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Layer 4", 8, 240, 193, 65)
$LayerPlus4 = GUICtrlCreateButton("+", 24, 264, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerMinus4 = GUICtrlCreateButton("-", 80, 264, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerTotal4 = GUICtrlCreateLabel("0", 144, 256, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Layer 5", 8, 312, 193, 65)
$LayerPlus5 = GUICtrlCreateButton("+", 24, 336, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerMinus5 = GUICtrlCreateButton("-", 80, 336, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$LayerTotal5 = GUICtrlCreateLabel("0", 144, 328, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Total", 224, 16, 145, 137)
$OverallTotal = GUICtrlCreateLabel("Total", 256, 72, 76, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Scrap", 224, 176, 145, 97)
$ScrapPlus = GUICtrlCreateButton("+", 232, 216, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$ScrapMinus = GUICtrlCreateButton("-", 272, 216, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$ScrapTotal = GUICtrlCreateLabel("0", 320, 208, 38, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Parts Per Hour", 224, 296, 145, 81)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LayerPlus1
            $Total1 = GUICtrlRead($LayerTotal1) + 1
            $Total2 = GUICtrlRead($OverallTotal) + 1 
            GUICtrlSetData($LayerTotal1, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerMinus1
            $Total1 = GUICtrlRead($LayerTotal1) - 1
            $Total2 = GUICtrlRead($OverallTotal) - 1 
            GUICtrlSetData($LayerTotal1, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerPlus2
            $Total1 = GUICtrlRead($LayerTotal2) + 1
            $Total2 = GUICtrlRead($OverallTotal) + 1 
            GUICtrlSetData($LayerTotal2, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerMinus2
            $Total1 = GUICtrlRead($LayerTotal2) - 1
            $Total2 = GUICtrlRead($OverallTotal) - 1 
            GUICtrlSetData($LayerTotal2, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerPlus3
            $Total1 = GUICtrlRead($LayerTotal3) + 1
            $Total2 = GUICtrlRead($OverallTotal) + 1 
            GUICtrlSetData($LayerTotal3, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerMinus3
            $Total1 = GUICtrlRead($LayerTotal3) - 1
            $Total2 = GUICtrlRead($OverallTotal) - 1 
            GUICtrlSetData($LayerTotal3, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerPlus4
            $Total1 = GUICtrlRead($LayerTotal4) + 1
            $Total2 = GUICtrlRead($OverallTotal) + 1 
            GUICtrlSetData($LayerTotal4, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerMinus4
            $Total1 = GUICtrlRead($LayerTotal4) - 1
            $Total2 = GUICtrlRead($OverallTotal) - 1 
            GUICtrlSetData($LayerTotal4, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerPlus5
            $Total1 = GUICtrlRead($LayerTotal5) + 1
            $Total2 = GUICtrlRead($OverallTotal) + 1 
            GUICtrlSetData($LayerTotal5, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $LayerMinus5
            $Total1 = GUICtrlRead($LayerTotal5) - 1
            $Total2 = GUICtrlRead($OverallTotal) - 1 
            GUICtrlSetData($LayerTotal5, $Total1)
            GUICtrlSetData($OverallTotal, $Total2)
        Case $ScrapPlus
            $Total1 = GUICtrlRead($ScrapTotal) + 1
            GUICtrlSetData($ScrapTotal, $Total1)
        Case $ScrapMinus
            $Total1 = GUICtrlRead($ScrapTotal) - 1
            GUICtrlSetData($ScrapTotal, $Total1)
    EndSwitch
WEnd
Edited by rogue5099

Share this post


Link to post
Share on other sites



Added this fuction to include Total per hour and total + scrap per hour, just put the func after each Case $Button:

Func PerHour()
    If @HOUR > 21 Then
        $PerHour = GUICtrlRead($OverallTotal) / (@HOUR - 22 + (@MIN/60))
        GUICtrlSetData($PartsPerHour, $PerHour)
        $PerHour2 = (GUICtrlRead($OverallTotal) + GUICtrlRead($ScrapTotal)) / (@HOUR - 22 + (@MIN/60))
        GUICtrlSetData($PartsPerHour2, $PerHour2)
    Else
        $PerHour = GUICtrlRead($OverallTotal) / (2 + @HOUR + (@MIN/60))
        GUICtrlSetData($PartsPerHour, $PerHour)
        $PerHour2 = (GUICtrlRead($OverallTotal) + GUICtrlRead($ScrapTotal)) / (2 + @HOUR + (@MIN/60))
        GUICtrlSetData($PartsPerHour2, $PerHour2)
    EndIf
EndFunc

Still would like to clean up those Buttons.....

Share this post


Link to post
Share on other sites

Try this one:

#Tidy_Parameters=/tc 0 /kv 0 /reel
#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -d

#include <GUIConstantsEx.au3>

GUICreate("Stegg Production 704394 Rev. 01", 393, 409, 415, 166)

GUICtrlCreateGroup("Layer 1", 8, 8, 193, 65)
Global Const $Layer1Plus = GUICtrlCreateButton("+", 24, 32, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $Layer1Minus = GUICtrlCreateButton("-", 80, 32, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerTotal1 = GUICtrlCreateLabel("0", 144, 24, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Layer 2", 8, 88, 193, 65)
Global Const $LayerPlus2 = GUICtrlCreateButton("+", 24, 112, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerMinus2 = GUICtrlCreateButton("-", 80, 112, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerTotal2 = GUICtrlCreateLabel("0", 144, 104, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Layer 3", 8, 168, 193, 65)
Global Const $LayerPlus3 = GUICtrlCreateButton("+", 24, 192, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerMinus3 = GUICtrlCreateButton("-", 80, 192, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerTotal3 = GUICtrlCreateLabel("0", 144, 184, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Layer 4", 8, 240, 193, 65)
Global Const $LayerPlus4 = GUICtrlCreateButton("+", 24, 264, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerMinus4 = GUICtrlCreateButton("-", 80, 264, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerTotal4 = GUICtrlCreateLabel("0", 144, 256, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Layer 5", 8, 312, 193, 65)
Global Const $LayerPlus5 = GUICtrlCreateButton("+", 24, 336, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerMinus5 = GUICtrlCreateButton("-", 80, 336, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $LayerTotal5 = GUICtrlCreateLabel("0", 144, 328, 46, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Total", 224, 16, 145, 137)
Global Const $OverallTotal = GUICtrlCreateLabel("0", 256, 72, 76, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Scrap", 224, 176, 145, 97)
Global Const $ScrapPlus = GUICtrlCreateButton("+", 232, 216, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $ScrapMinus = GUICtrlCreateButton("-", 272, 216, 41, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
Global Const $ScrapTotal = GUICtrlCreateLabel("0", 320, 208, 38, 41)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUICtrlCreateGroup("Parts Per Hour", 224, 296, 145, 81)
Global Const $label_hourly_average = GUICtrlCreateLabel('', 276, 330, 38, 41)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

AdlibRegister("hourly_average", 3600000)

Global $total_layer1
Global $total_layer2
Global $total_layer3
Global $total_layer4
Global $total_layer5
Global $total_overall
Global $total_scrap

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Layer1Plus
            $total_layer1 += 1
            GUICtrlSetData($LayerTotal1, $total_layer1)
            increment_overall_total()
        Case $Layer1Minus
            $total_layer1 -= 1
            GUICtrlSetData($LayerTotal1, $total_layer1)
            decrement_overall_total()
        Case $LayerPlus2
            $total_layer2 += 1
            GUICtrlSetData($LayerTotal2, $total_layer2)
            increment_overall_total()
        Case $LayerMinus2
            $total_layer2 -= 1
            GUICtrlSetData($LayerTotal2, $total_layer2)
            decrement_overall_total()
        Case $LayerPlus3
            $total_layer3 += 1
            GUICtrlSetData($LayerTotal3, $total_layer3)
            increment_overall_total()
        Case $LayerMinus3
            $total_layer3 -= 1
            GUICtrlSetData($LayerTotal3, $total_layer3)
            decrement_overall_total()
        Case $LayerPlus4
            $total_layer4 += 1
            GUICtrlSetData($LayerTotal4, $total_layer4)
            increment_overall_total()
        Case $LayerMinus4
            $total_layer4 -= 1
            GUICtrlSetData($LayerTotal4, $total_layer4)
            decrement_overall_total()
        Case $LayerPlus5
            $total_layer5 += 1
            GUICtrlSetData($LayerTotal5, $total_layer5)
            increment_overall_total()
        Case $LayerMinus5
            $total_layer5 -= 1
            GUICtrlSetData($LayerTotal5, $total_layer5)
            decrement_overall_total()
        Case $ScrapPlus
            $total_scrap += 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
        Case $ScrapMinus
            $total_scrap -= 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
    EndSwitch
WEnd

Func hourly_average()
    Local Static $hours_worked = 1
    Local Const $pph = $total_overall / $hours_worked
    $hours_worked += 1
    GUICtrlSetData($label_hourly_average, $pph)
EndFunc   ;==>hourly_average

Func increment_overall_total()
    $total_overall += 1
    GUICtrlSetData($OverallTotal, $total_overall)
EndFunc   ;==>increment_overall_total

Func decrement_overall_total()
    $total_overall -= 1
    GUICtrlSetData($OverallTotal, $total_overall)
EndFunc   ;==>decrement_overall_total

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Also is there a cleaner way to do the Buttons like useing $LayerTotal[$i]? or $LayerPlus[$i]?

Using subscripts/indexes/arrays almost always saves a ton of code.

Here's Jaberwocky's example with subscripts:

#Tidy_Parameters=/tc 0 /kv 0 /reel
#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -d

#include <GUIConstantsEx.au3>

Global $msg, $LayerPlus[5], $LayerMinus[5], $LayerTotal[5]
Global $total_layer[5], $total_scrap, $total_overall

GUICreate("Stegg Production 704394 Rev. 01", 393, 409, 415, 166)

For $x = 0 to 4
    GUISetFont(9, 600, 0, "MS Sans Serif")
    GUICtrlCreateGroup("LAYER " & $x + 1, 8, 8 + $x * 80, 193, 65)
    $LayerPlus[$x] = GUICtrlCreateButton("+", 24, 32 + $x * 80, 41, 25)
    $LayerMinus[$x] = GUICtrlCreateButton("-", 80, 32 + $x * 80, 41, 25)
    GUISetFont(20, 400, 0, "MS Sans Serif")
    $LayerTotal[$x] = GUICtrlCreateLabel("0", 144, 29 + $x * 80, 46, 41)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
Next
Global Const $ctrl_offset = $LayerPlus[1] - $LayerPlus[0] ; get CTRLID difference between similar buttons/labels

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("TOTAL", 224, 16, 155, 137)
GUISetFont(20, 600, 0, "MS Sans Serif")
$OverallTotal = GUICtrlCreateLabel("0", 256, 72, 76, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("SCRAP", 224, 176, 155, 97)
$ScrapPlus = GUICtrlCreateButton("+", 232, 216, 41, 25)
$ScrapMinus = GUICtrlCreateButton("-", 272, 216, 41, 25)
GUISetFont(20, 400, 0, "MS Sans Serif")
$ScrapTotal = GUICtrlCreateLabel("0", 325, 214, 38, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("PARTS PER HOUR", 224, 296, 155, 81)
$label_hourly_average = GUICtrlCreateLabel('', 276, 330, 38, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

AdlibRegister("hourly_average", 3600000)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LayerPlus[0], $LayerPlus[1], $LayerPlus[2], $LayerPlus[3], $LayerPlus[4]
            $x = Abs(($msg - $LayerPlus[0]) / $ctrl_offset) ; identify which plus button was clicked
            Update_total($x, 1)
        Case $LayerMinus[0], $LayerMinus[1], $LayerMinus[2], $LayerMinus[3], $LayerMinus[4]
            $x = Abs(($msg - $LayerMinus[0]) / $ctrl_offset) ; identify which minus button was clicked
            Update_total($x, -1)
        Case $ScrapPlus
            $total_scrap += 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
        Case $ScrapMinus
            $total_scrap -= 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
    EndSwitch
WEnd

Func hourly_average()
    Local Static $hours_worked = 1
    Local Const $pph = $total_overall / $hours_worked
    $hours_worked += 1
    GUICtrlSetData($label_hourly_average, $pph)
EndFunc   ;==>hourly_average

Func Update_total($x, $y)
    $total_layer[$x] += $y
    GUICtrlSetData($LayerTotal[$x], $total_layer[$x])
    $total_overall += $y
    GUICtrlSetData($OverallTotal, $total_overall)
EndFunc

There are a dozen ways one could have gone about it... this one pretty much cuts the script in half.

Edited by Spiff59

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Using subscripts/indexes/arrays almost always saves a ton of code.

Here's Jaberwocky's example with subscripts:

#Tidy_Parameters=/tc 0 /kv 0 /reel
#AutoIt3Wrapper_Au3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -d

#include <GUIConstantsEx.au3>

Global $msg, $LayerPlus[5], $LayerMinus[5], $LayerTotal[5]
Global $total_layer[5], $total_scrap, $total_overall

GUICreate("Stegg Production 704394 Rev. 01", 393, 409, 415, 166)

For $x = 0 to 4
    GUISetFont(9, 600, 0, "MS Sans Serif")
    GUICtrlCreateGroup("LAYER " & $x + 1, 8, 8 + $x * 80, 193, 65)
    $LayerPlus[$x] = GUICtrlCreateButton("+", 24, 32 + $x * 80, 41, 25)
    $LayerMinus[$x] = GUICtrlCreateButton("-", 80, 32 + $x * 80, 41, 25)
    GUISetFont(20, 400, 0, "MS Sans Serif")
    $LayerTotal[$x] = GUICtrlCreateLabel("0", 144, 29 + $x * 80, 46, 41)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
Next
Global Const $ctrl_offset = $LayerPlus[1] - $LayerPlus[0] ; get CTRLID difference between similar buttons/labels

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("TOTAL", 224, 16, 155, 137)
GUISetFont(20, 600, 0, "MS Sans Serif")
$OverallTotal = GUICtrlCreateLabel("0", 256, 72, 76, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("SCRAP", 224, 176, 155, 97)
$ScrapPlus = GUICtrlCreateButton("+", 232, 216, 41, 25)
$ScrapMinus = GUICtrlCreateButton("-", 272, 216, 41, 25)
GUISetFont(20, 400, 0, "MS Sans Serif")
$ScrapTotal = GUICtrlCreateLabel("0", 325, 214, 38, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetFont(10, 600, 0, "MS Sans Serif")
GUICtrlCreateGroup("PARTS PER HOUR", 224, 296, 155, 81)
$label_hourly_average = GUICtrlCreateLabel('', 276, 330, 38, 41)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

AdlibRegister("hourly_average", 3600000)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $LayerPlus[0], $LayerPlus[1], $LayerPlus[2], $LayerPlus[3], $LayerPlus[4]
            $x = Abs(($msg - $LayerPlus[0]) / $ctrl_offset) ; identify which plus button was clicked
            Update_total($x, 1)
        Case $LayerMinus[0], $LayerMinus[1], $LayerMinus[2], $LayerMinus[3], $LayerMinus[4]
            $x = Abs(($msg - $LayerMinus[0]) / $ctrl_offset) ; identify which minus button was clicked
            Update_total($x, -1)
        Case $ScrapPlus
            $total_scrap += 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
        Case $ScrapMinus
            $total_scrap -= 1
            GUICtrlSetData($ScrapTotal, $total_scrap)
    EndSwitch
WEnd

Func hourly_average()
    Local Static $hours_worked = 1
    Local Const $pph = $total_overall / $hours_worked
    $hours_worked += 1
    GUICtrlSetData($label_hourly_average, $pph)
EndFunc   ;==>hourly_average

Func Update_total($x, $y)
    $total_layer[$x] += $y
    GUICtrlSetData($LayerTotal[$x], $total_layer[$x])
    $total_overall += $y
    GUICtrlSetData($OverallTotal, $total_overall)
EndFunc

There are a dozen ways one could have gone about it... this one pretty much cuts the script in half.

This works great for cleaning up GUI code but the hourly function only refreshes hourly due to:

AdlibRegister("hourly_average", 3600000)

I need it to refresh after every part is added (everytime user clicks "+" button) to have an acurate "realtime" rate. Also this only refreshes every hour only due to:

$hours_worked += 1

My code in 2nd post only works for 10pm start time. I can't be sure they start the program "On-Time"... Maybe add an input of time started???

Formula needed needs to be somthing like:

GUICtrlRead($OverallTotal) / ((@HOUR - Timestarted) + (@MIN/60))

Having problems with 3rd shift going past Midnight....

Edited by rogue5099

Share this post


Link to post
Share on other sites

Something like this should take care of the shifts that go past midnight.

Opt ('TrayIconDebug',1)
Opt("MustDeclareVars", 1)
Local $iStartHour = 22 ;; 10PM
Local $iEndHour = 06 ;; 6 AM
Local $iHoursWorked = _HoursTotal($iStartHour, $iEndHour)
If NOT @Error Then MsgBox(0, "Time", $iHoursWorked)

Func _HoursTotal($i_Start, $i_End)
    If $i_End < $i_Start Then
        Return ((24 - $i_Start) + $i_End)
    Else
        Return ($i_End - $i_Start)
    EndIf
    Return SetError(1, 1, 0)
EndFunc

You could also have the function return a value in minutes then add any conversion of the minute started and the minute ended. Converting it all back to hours and rounding the total to 2 decimal places is probably best.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  
Followers 0