Sign in to follow this  
Followers 0
stefionesco

Time addition

9 posts in this topic

There is some way to make

A + B = C

when A, B, and C is in time format?

I mean...

0:14 + 1:24 = 1:38

Something like that...

Excel can do this but I can't figure out who to do it in Autoit.

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Yes...

Something like that.

I'll try now to put it where I need.

Respect

Stef Ionesco

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks a lot.

I'm new and I'm learning.

Please have patience.

Thanks again for all the tips.

Respect

Stef Ionesco

Share this post


Link to post
Share on other sites

stefionesco,

I'm new and I'm learning.

Please have patience.

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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