Sign in to follow this  
Followers 0
newtoau3

Addition of numbers in label

5 posts in this topic

#1 ·  Posted (edited)

Hi guys. I'm hoping someone would kindly help me with a little problem. In the following example, next to the label "Total:" I'm hoping to be able to add the hrs, mins, secs thus giving an "updated" amount as values are typed into the boxes. I'm looking for the individual sums of the hrs, mins and secs. Could someone point me in the right direction or kindly help me with the code.

Thanks.

#requireadmin
#include <Constants.au3>
#include <GUIConstants.au3>
#Include <Misc.au3>
#include <Date.au3>

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("MouseCoordMode", 1)
;Use Mouse Coordinates relative to:
;1-rel to screen



;master gui vars
$master_gui_width = 210
$master_gui_height = 190

; variables group
$default_group_width = 200
$x_var_group = 5
$y_var_group = 10
$var_group_width = $default_group_width
$var_group_height = $master_gui_height - 70

; = END DEFINE VARIABLES

; ===== START MASTER GUI
GUICreate(".", $master_gui_width, $master_gui_height)

WinSetOnTop(".", "", 1)


; MENU

GUICtrlCreateGroup("Times", $x_var_group, $y_var_group, $var_group_width, $var_group_height)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group

;Hrs, secs title
$widthCell = 100
GUICtrlCreateLabel("Hrs.  Mins.  Secs.", 50, 30, $widthCell)

Local Const $NumTimeFields = 3 
Local $HourFields[$NumTimeFields]
Local $MinuteFields[$NumTimeFields]
Local $SecondFields[$NumTimeFields]
Local $ProgressBar[$NumTimeFields]
Local $CoordsField[$NumTimeFields]
Local $XSpot, $YSpot

$widthCellb = 40
$diff = 22

For $I = 0 To $NumTimeFields - 1
    Local $Y = $y_var_group + $diff * ($I + 2) - 3
    Local $Label = 'Time ' & $I + 1 & '.'
    Local $Label2 = 'Total:'
    GUICtrlCreateLabel($Label, $x_var_group + 2, $Y + 3, $widthCellb)
    GUICtrlCreateLabel($Label2, 7, $master_gui_heigHT -58)
    $HourFields[$I] = GUICtrlCreateInput('', 47, $Y, 21, 17, $ES_NUMBER)
    $MinuteFields[$I] = GUICtrlCreateInput('', 76, $Y, 21, 17, $ES_NUMBER)
    $SecondFields[$I] = GUICtrlCreateInput('', 105, $Y, 21, 17, $ES_NUMBER)
    $ProgressBar[$I] = GUICtrlCreateProgress(130, $Y + 2, 70, 13,$PBS_SMOOTH)
    $CoordsField[$I] = GUICtrlCreateInput("", 213, $Y, 60, 17)
    
Next

GUISetState()

;Mouse movements/coords
While 1
    $msg = GUIGetMsg()
WEnd
Edited by newtoau3

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#requireadmin
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#Include <Misc.au3>
#include <Date.au3>

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("MouseCoordMode", 1)
;Use Mouse Coordinates relative to:
;1-rel to screen



;master gui vars
$master_gui_width = 210
$master_gui_height = 190

; variables group
$default_group_width = 200
$x_var_group = 5
$y_var_group = 10
$var_group_width = $default_group_width
$var_group_height = $master_gui_height - 70

; = END DEFINE VARIABLES

; ===== START MASTER GUI
GUICreate(".", $master_gui_width, $master_gui_height)

WinSetOnTop(".", "", 1)


; MENU

GUICtrlCreateGroup("Times", $x_var_group, $y_var_group, $var_group_width, $var_group_height)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group

;Hrs, secs title
$widthCell = 100
GUICtrlCreateLabel("Hrs.  Mins.  Secs.", 50, 30, $widthCell)

Local Const $NumTimeFields = 3
Local $HourFields[$NumTimeFields]
Local $MinuteFields[$NumTimeFields]
Local $SecondFields[$NumTimeFields]
Local $ProgressBar[$NumTimeFields]
Local $CoordsField[$NumTimeFields]
Local $XSpot, $YSpot

$widthCellb = 40
$diff = 22

For $I = 0 To $NumTimeFields - 1
    Local $Y = $y_var_group + $diff * ($I + 2) - 3
    Local $Label = 'Time ' & $I + 1 & '.'
    GUICtrlCreateLabel($Label, $x_var_group + 2, $Y + 3, $widthCellb)
    $Label2 = GUICtrlCreateLabel("", 7, $master_gui_heigHT -58, 90, 20)
    GUICtrlSetData($Label2, 'Total: ' & @HOUR & ':' & @MIN & ':' & @SEC)
    $HourFields[$I] = GUICtrlCreateInput('', 47, $Y, 21, 17, $ES_NUMBER)
    $MinuteFields[$I] = GUICtrlCreateInput('', 76, $Y, 21, 17, $ES_NUMBER)
    $SecondFields[$I] = GUICtrlCreateInput('', 105, $Y, 21, 17, $ES_NUMBER)
    $ProgressBar[$I] = GUICtrlCreateProgress(130, $Y + 2, 70, 13,$PBS_SMOOTH)
    $CoordsField[$I] = GUICtrlCreateInput("", 213, $Y, 60, 17)
    
Next
;$start = GUICtrlCreateButton("START", 160, $master_gui_height - 40, 45, 30)
;GUICtrlSetOnEvent($start, "Start")


GUISetState()

;Mouse movements/coords
While 1
    Sleep(100)
    $msg = GUIGetMsg()
    ControlSetText(".", "", $Label2, 'Total: ' & @HOUR & ':' & @MIN & ':' & @SEC)
WEnd
Exit
Edited by mikiutama

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks, but what this does is just quotes the PC's time.

I'd like the total hrs, mins, secs to update as I enter values into the boxes.

Edited by newtoau3

Share this post


Link to post
Share on other sites

Thanks, but what this does is just quotes the PC's time.

I'd like the total hrs, mins, secs to update as I enter values into the boxes.

Notice I changed the way you create your controls as well as other changes or additions.

#requireadmin
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#Include <Misc.au3>
#include <Date.au3>

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("MouseCoordMode", 1)
;Use Mouse Coordinates relative to:
;1-rel to screen


Global $Toth,$Totm,$tots
;master gui vars
$master_gui_width = 210
$master_gui_height = 190

; variables group
$default_group_width = 200
$x_var_group = 5
$y_var_group = 10
$var_group_width = $default_group_width
$var_group_height = $master_gui_height - 70

; = END DEFINE VARIABLES

; ===== START MASTER GUI
GUICreate(".", $master_gui_width, $master_gui_height)

WinSetOnTop(".", "", 1)


; MENU

GUICtrlCreateGroup("Times", $x_var_group, $y_var_group, $var_group_width, $var_group_height)
GUICtrlCreateGroup("", -99, -99, 1, 1);close group

;Hrs, secs title
$widthCell = 100
GUICtrlCreateLabel("Hrs.  Mins.  Secs.", 50, 30, $widthCell)

Local Const $NumTimeFields = 3
Local $HourFields[$NumTimeFields]
Local $MinuteFields[$NumTimeFields]
Local $SecondFields[$NumTimeFields]
Local $ProgressBar[$NumTimeFields]
Local $CoordsField[$NumTimeFields]
Local $XSpot, $YSpot

$widthCellb = 40
$diff = 22
Local $Y 
;create all the edits together
For $I = 0 To $NumTimeFields - 1
    $Y = $y_var_group + $diff * ($I + 2) - 3
    $HourFields[$I] = GUICtrlCreateInput('', 47, $Y, 21, 17, $ES_NUMBER)
    $MinuteFields[$I] = GUICtrlCreateInput('', 76, $Y, 21, 17, $ES_NUMBER)
    $SecondFields[$I] = GUICtrlCreateInput('', 105, $Y, 21, 17, $ES_NUMBER)
Next

For $I = 0 to $NumTimeFields - 1
     $Y = $y_var_group + $diff * ($I + 2) - 3
    Local $Label = 'Time ' & $I + 1 & '.'
    GUICtrlCreateLabel($Label, $x_var_group + 2, $Y + 3, $widthCellb)
    $ProgressBar[$I] = GUICtrlCreateProgress(130, $Y + 2, 70, 13,$PBS_SMOOTH)
    $CoordsField[$I] = GUICtrlCreateInput("", 213, $Y, 60, 17)
Next
;create $Label2 outside of the loop, there is only one $Label2
$Label2 = GUICtrlCreateLabel("", 7, $master_gui_heigHT -58, 190, 20)
; GUICtrlSetData($Label2, 'Total: ' & @HOUR & ':' & @MIN & ':' & @SEC)
;$start = GUICtrlCreateButton("START", 160, $master_gui_height - 40, 45, 30)
;GUICtrlSetOnEvent($start, "Start")


GUISetState()

GUIRegisterMsg($WM_COMMAND, "ED_WM_COMMAND");only used for EN_CHANGE so far
GUISetOnEvent($GUI_EVENT_CLOSE,"ex")
;Mouse movements/coords
While 1
    Sleep(100)
    $msg = GUIGetMsg()
  ; ControlSetText(".", "", $Label2, 'Total: ' & @HOUR & ':' & @MIN & ':' & @SEC)
WEnd
Exit
Func ex()
    Exit
EndFunc


Func ED_WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $setHK = False
    Local $nNotifyCode = BitShift($iwParam, 16)
    Local $nID = BitAND($iwParam, 0x0000FFFF)
    Local $hCtrl = $ilParam
    
    If $nNotifyCode = $EN_CHANGE Then
        switch $ilParam
              Case  $HourFields[0] to $SecondFields[$NumTimeFields - 1]
                $tots = 0
                For $n = 0 to $NumTimeFields - 1
                    $Tots += GUICtrlRead($SecondFields[$n])
                Next
                $TotM = INt($Tots/60)
                $TotS = Mod($TotS,60)
                For $n = 0 to $NumTimeFields - 1
                    $Totm += GUICtrlRead($MinuteFields[$n])
                Next
                $TotH = INt($Totm/60)
                $TotM = Mod($TotM,60)
                For $n = 0 to $NumTimeFields - 1
                    $TotH += GUICtrlRead($HourFields[$n])
                Next
                GUICtrlSetData($Label2,StringFormat("Total = %d H: %2dM: %2dS",$TotH,$TotM,$Tots))
                
        EndSWitch
    EndIf

    Return $GUI_RUNDEFMSG
    

EndFunc  ;==>ED_WM_COMMAND

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Martin, thanks heaps for your time and effort!! :P This is exactly what I wanted and, Mikiutama, you also answered a future question for me!! Cheers! :(:idea:

Edited by newtoau3

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