Jump to content

Get current date/time each time a variable is called


Recommended Posts

Hello,

This is my first time posting in the AutoIT forums, however I have been using this, the help section as well as Google for a while now to learn and understand AutoIT.

I hope I've put in everything that's required within the post below, I apologise if I have missed anything out.

If I need to rename the title to something more appropriate, please let me know.

Description of issue:

I sort of understand where I'm going wrong, by storing the current date and time within the defined variable ($logComputerDateTime) and always using that variable. However I'm unsure how to tackle the problem.

The reason for asking is that from the actual script I've written, I have a loop of 50 attempts to run an external utility with defined parameters. Unfortunately, that utility doesn't provide any output or logging once it has been successfully run, so once I've run that external utility, I'm querying a SQL database to view a specific record to verify if the record has been updated with a new value. Only once it has, I end the loop. (It's also an issue where the utility needs to be "spammed" for lack of a better word, in order to obtain the desired results).

I cannot include the original script as there's sensitive information within it, but I've pieced together two example bits of code, one where I'm having the issue and another to demonstrate what I'm trying to achieve.

I've tried to Google what and search the AutoIT forums for what I believe the issue to be however can't seem to find a way around this.

Again, I apologise if I've completely overlooked something, but any help or step in the right direction would be greatly appreciated.

Example code (with issue):

Local $sleepValue = 1000
Local $logComputerDateTime = @ComputerName & " | " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & " | "

ConsoleWrite($logComputerDateTime & "Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)
ConsoleWrite($logComputerDateTime & "Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)
ConsoleWrite($logComputerDateTime & "Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)

Example code (with a workaround):

#include <Date.au3>

Local $sleepValue = 1000

ConsoleWrite(@ComputerName & " | " & _NowCalc() & " | Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)
ConsoleWrite(@ComputerName & " | " & _NowCalc() & " | Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)
ConsoleWrite(@ComputerName & " | " & _NowCalc() & " | Line number: " & @ScriptLineNumber & "." & @CRLF)
Sleep($sleepValue)

 

Link to comment
Share on other sites

It's plain that a variable can't change by white magic when it's read, unless shared among processes or threads and changed outside your own control.  Your workaround is the only correct solution: invoke a function.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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