Jump to content

Search the Community

Showing results for tags 'adlilbregister'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. I was working on a good way to run a script after x amount of time without needing to run it as a scheduled task so that it can be run from any computer. I have used AdlibRegister() before with good success for small periods of time but never larges ones (like an hour). So I tried it out and it looks like it actually works very well. One thing that sort of annoyed me though was walking up to the computer and not knowing when it was going to run next, so I tried to plug in a little time check function and it appeared to work on my little test but in production it started to give me some crazy results. Breaking it down, I figured most of the issue had to do with two things. 1.) Bad practice to use Global Variables in a function. I never understood why, so I try not to do it. In this example I would need MyFunc() to update $vEndTime and $vStartTime globally so I believe the right way to do this would be to pass the variables to the function ByRef. But that leads to problem #2 2.) You can not pass any variables to a function called with AdlibRegister() So that leads me to create this topic so that I can learn some new best practices. Why exactly is using Global in the function a bad idea on a simple script like this? How can I pass these to/from the function using AdlibRegister() and if it can't really be done, what is the best way to do this? For now I have my script working without the "check time" feature and I could update/return multiple values from the function with Global scope but I create this thread in hopes to learn more of why/how things can and should not be done. Also maybe a good tip on how to run a function on a repeat basis with accurate time without AdlibRegister() Regards, Edit: Just realized I did not post the example code. ;Just a concept this is not my actual script where things were a bit different #Include <Date.au3> Global $iWaitTime = 60000*60 Global $vStartTime = _NowTime(4) HotKeySet("^!t", "CheckTime") AdlibRegister("MyFunc", $iWaitTime) MyFunc() While 1 Sleep(10) WEnd Func MyFunc() $vEndTime = $vStartTime $vStartTime = _NowTime(4) ;do stuff ;do stuff EndFunc Func CheckTime() MsgBox(0, "", "Current Cycle is set for " & $iWaitTime/60000 & " Minutes" & @CRLF & @CRLF & _ "There is " & ($iWaitTime/60000)-(_NowTime(4)-$vStartTime) & " Minutes Left Until Next Cycle") EndFunc The actual code was a bit different, I had to strip the colon out of the time and such.
×
×
  • Create New...