Jump to content

Current Time and Function Call


Recommended Posts

This is a simple script that displays the current time and has a button named "Run Function" to call a function where it sleeps for 5 seconds. How can I call the function, but still have the current time continuing to update on the main GUI? As expected in its current state, when I run the function, the time on the main GUI stops for 5 seconds and then resumes once the function is complete.

I will be adding a progress bar routine that runs within the function later on that will go in place of the "sleep for 5 seconds" place holder, but I was needing to get this little detail figured out first. I don't think I could put the time update loop in the same loop that will be in the function, because it will perform a number of tasks before it ever returns to the top of the loop to update the time. Thanks in advance!

CODE
#include <GUIConstantsEx.au3>

#include <Date.au3>

Opt ("GUIOnEventMode", 1)

$GUI=GuiCreate("Title",200,100,-1,-1)

$Button1 = GUICtrlCreateButton("Run Function", 20, 60)

GUICtrlSetOnEvent($BUTTON1, "RunFunction")

$CurrentTime = _DateTimeFormat( _NowCalc(),3)

$label=GUICtrlCreateLabel($CurrentTime,20,20,140,20)

GUICtrlSetFont (-1,10, 800)

GUISetOnEvent($GUI_EVENT_CLOSE,"CloseGUI")

GUISetState(@SW_SHOW)

While 1

If $CurrentTime <> _DateTimeFormat( _NowCalc(),3) Then

$CurrentTime = _DateTimeFormat( _NowCalc(),3)

GUICtrlSetData($label, $CurrentTime)

EndIf

WEnd

Func RunFunction()

Sleep(5000)

EndFunc

Func CloseGUI()

Exit

EndFunc

Link to comment
Share on other sites

I have seen some people embed another script that hides in the background that receives and sends information to and from hidden controls on the main form to address these types of concerns. Haven't played with it much myself though.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • Moderators

TheCrimsonCrusader,

Look at Adlib in the Help file. It lets you call a specific function at defined intervals, pausing your main script while that function runs, but then resuming it once it has terminated.

Sounds like just the thing for your timer update.

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

  • Developers

Well, the problem is that AutoIt is not multithreaded and while your script is sleeping 5 seconds it's suspended so no code get executed at this time interval.

AdlibEnable() works fine during Sleep() :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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