Jump to content

Time addition


Recommended Posts

  • Moderators

stefionesco,

There is no native function - but this little function should work: ;)

$sTime_1 = "0:14"
$sTime_2 = "1:24"

$sSum = _TimeAdd($sTime_1, $sTime_2)

MsgBox(0, "Sum", $sSum)

Func _TimeAdd($sTime_1, $sTime_2)

    $aTime_1 = StringSplit($sTime_1, ":")
    $aTime_2 = StringSplit($sTime_2, ":")

    $iMinutes = Mod($aTime_1[2] + $aTime_2[2], 60)
    $iHours = $aTime_1[1] + $aTime_2[1] + Int(($aTime_1[2] + $aTime_2[2]) / 60)

    Return $iHours & ":" & $iMinutes

EndFunc

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I want to do something like this

#include <GUIConstantsEx.au3>
#include <Date.au3>
Dim $msg, $calculate, $out
Global $time1, $time2, $time_result
GUICreate("Time operation", 270, 150)
GUISetState(@SW_SHOW)
$time1 = GUICtrlCreateInput("", 10, 40, 50, 20)
GUICtrlCreateLabel("+", 80, 40, 20, 20)
$time2 = GUICtrlCreateInput("",110, 40, 50, 20)
GUICtrlCreateLabel("=", 180, 40, 20, 20)
$time_result = GUICtrlCreateInput("", 200, 40, 50, 20)
$calculate = GUICtrlCreateButton("Calculate", 50, 80, 100, 25, 0)
While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
   
   Case $calculate
        $out = $time1 + $time2
        GUICtrlSetData ($time_result, $out)
  EndSelect
WEnd

But it didn't work. The result is always 8.

Can somebody explain me why?

Link to comment
Share on other sites

  • Moderators

stefionesco,

You need to use GUICtrlRead - at the moment you are just adding the ControlIDs of the 2 inputs. ;)

Take a look at this:

#include <guiconstantsex.au3>
#include <date.au3>

Global $msg, $calculate, $out  ; Do not use Dim
Global $time1, $time2, $time_result

GUICreate("Time operation", 270, 150)

$time1 = GUICtrlCreateInput("", 10, 40, 50, 20)
GUICtrlCreateLabel("+", 80, 40, 20, 20)
$time2 = GUICtrlCreateInput("", 110, 40, 50, 20)
GUICtrlCreateLabel("=", 180, 40, 20, 20)
$time_result = GUICtrlCreateInput("", 200, 40, 50, 20)
$calculate = GUICtrlCreateButton("Calculate", 50, 80, 100, 25, 0)

GUISetState(@SW_SHOW)  ; Add this after creating the controls

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $calculate ; You need the Case $msg = here 
            $out = GUICtrlRead($time1) + GUICtrlRead($time2)
            GUICtrlSetData($time_result, $out)
    EndSelect
WEnd

All clear? :)

M23

Edit: Took 2 minutes for the "New reply" alert to show up - I would not have bothered otherwise! :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

stefionesco,

I'm new and I'm learning.

Please have patience.

We all were at one time - and we will. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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