Jump to content

UDF: Basics and Time extensions


Recommended Posts

Hey all,

This UDF is basically a compilation of functions I've written to address needs I've had in a workplace testing atmosphere. Most of these I wrote to overcome some problem or to address a particular issue. As such, the UDF itself is a little hodgepodge, but I used most of them on a very regular basis. I'll give a brief description of each function listed. Probably the most valuable ones for you all are the ticks/time extensions. I've been wanting to post a UDF for a while now, and I finally feel as if my coding practices can allow for lean, efficient, well coded functions - in most cases. :unsure: Included with each function in the headers is the function's call tip entry if you'd like to use it.

Current Functions:
















_Array2DClearBlanks - This function removes ALL blanks lines from a given 2D array. This is useful if pulling in large amounts of information which may include useless blank lines. Eventually, I coded in the functionality for a 1D array as well. The $2DSize pertains to the size of the second dimension of the array. For example $aVar[3][4] the 2DSize would be 4. If 0 is entered, the array is treated as a 1D array.

_ClickMenu - I wrote this function specifically for software I test for that does not have any other means of control besides mouse coordinate based control. It is somewhat specialized but will work with most programs containing a standard enough menu system. By "spacers" in the function header, I mean the lines that separate various sections of a menu.

_CreateBuild - This function, when placed at the head of your script below the includes will ask to produce a new build each time the script is run from SciTE. It also creates an archive with all previous builds and a log file. I coded this because I needed a custom way to know exactly what lines changed through all of my builds. The function can be left in the script after compiling, as it only runs on non-compiled scripts.

_ForceInsigZero - This function forces a given number of insignificant zeroes to the right of a decimal. This was primarily written for testing needs, but some others could find it useful. It will also dictate exactly how many decimal places to return; BUT DOES NOT ROUND.

_GetDate - This function returns the date in this format: Tuesday, May 3, 2011 I wrote this quick function because I was sick of using the macros all the time. I write a TON of timestamps in my testing work, so this worked nicely.

_MilitaryToStandard - Quick and easy, converts a military time to standard time. All of my time functions use the same format for entry strings, HH, HH:MM, HH:MM:SS

_PauseScript - Pauses the currently running script and asks the user if they would like to return or not. If not, closes the script. This is to be used as a hotkey script. Probably most of you have some version of this already, but this is the one I use.

_RandomColor - Outputs a hexadecimal representation of a random color in AutoIt hex form, I.E. 0x000000. Also has the option to output the random color along with its RGB values in an array.

_TCPListen - Custom written TCP function that listens over a given port until a message is received and sends an acknowledgement. Written to allow two testing scripts to talk to each other on separate computers over an internal network.

_TCPSend - Sends a message over a given port and waits for an acknowledgement. Written to allow two testing scripts to talk to each other on separate computers over an internal network.

The next 4 are the ones I use most and am most proud of. I wrote the following 4 functions due to the limits of the Ticks/Time functions

_TicksToTimeEx - Takes a given tick amount and converts it to time in a chosen format. Can return the time with the seconds, or without. Can output the time in military, standard time, or a numerical representation. (I.E. 17:30, 5:30 PM, or 17.5) And can include the milliseconds in the final value or not.

_TimeAddition - Adds two time stamps together to get the total time. Mostly used for testing. The two timestamps can be entered as military or standard times. HH, HH:MM, HH:MM:SS, HH AM/PM, HH:MM AM/PM, HH:MM:SS AM/PM This function can also output in milliseconds for high precision.

_TimeDifference - Same as above, except finds the difference between two times. Very useful for finding the duration of things given two timestamps. Same timestamp entries apply as above. This function can also output in milliseconds for high precision.

_TimeToTicksEx - Probably my favorite function. This function converts ANY time measurement into ticks: military, standard, or numeric. It only needs the time stamp, not the cumbersome entering of each hour, minute, and second. Also, is more precise, as it also uses milliseconds if they are given. Ex:

; Parameters ....: $Time - The time to convert to ticks. Format can be any of the following:
;                           (Military)      (Standard)                                                      (If Numeric = 1)
;                           - HH            - HH A          - HH AM         - HH P          - HH PM         - N
;                           - HH:MM         - HH:MM A       - HH:MM AM      - HH:MM P       - HH:MM PM      - N.N
;                           - HH:MM:SS      - HH:MM:SS A    - HH:MM:SS AM   - HH:MM:SS P    - HH:MM:SS PM   - etc.
;                           - HH:MM:SS.MS   - HH:MM:SS.MS A - HH:MM:SS.MS AM- HH:MM:SS.MS P - HH:MM:SS.MS PM

_ToolTipTimer - This small function is really useful for when pausing a script for a given duration and notifying the user of the time left. It basically acts as Sleep() but also creates a Tool Tip on the mouse that can display a message (or not) and displays the time left for the duration of the sleep.

So, some of these you probably won't use very often, but some I think are incredibly useful, especially the extended time functions. Let me know what you think and if you'll use any of these! If you have any questions, or would like me to post any examples, let me know. Thanks a lot for looking!

- Fett (Kris)


P.S. As I add more to my UDF, I'll place them here. Thanks again!

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...