Script Control Granularity

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Script Control Granularity

Post by Tourless » Sat May 06, 2023 11:13 pm

Hi Folks.

I have a nice script that runs every hour from 6am to 10pm taking readings from two networked XML files, does some math, writes the values to a SQL table and reports the data in an MS Teams Chat. The data is related to production and accounts for the productivity of two specific pieces of machinery. If one of the machines is offline due to maintenance of a failure, that is reported back in Teams and the data for the machine that is still online is reported on. If both machines are offline (production finished early or doesn't work as late on a Saturday or Sunday), my script reports that as well.

So my questions is how granular can I get with controlling the script? I'm thinking that if the script reports twice that both machines are offline, I'd like to reset until the following scheduled day at 6am. As of now it will just report no machines online every hour until 10pm.

I'd love to hear how others may have solved this problem and what options exist. -Thanks.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Script Control Granularity

Post by Dorian (MJT support) » Sun May 07, 2023 8:04 am

The first idea that comes to mind is using the ini file functions to track the results.

Also making sure to reset the ini file on the first run of the day.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Script Control Granularity

Post by Grovkillen » Mon May 08, 2023 3:35 am

If you use an external scheduler which triggers the script I would use Dorian's suggestion using a ini file. If you use a loop and keep the script running at all time (internal scheduler) you could keep a variable for keeping track of what to do. I have used both approaches and non is superior, only different ways of doing it.
Let>ME=%Script%

Running: 15.0.27
version history

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: Script Control Granularity

Post by Tourless » Mon May 08, 2023 12:42 pm

That seems like a pretty good first thought... but alas I have questions.
Assuming we are talking about the runstats.ini file, can I edit that to include additional 'fields' for each section? So instead of this...

Code: Select all

[C:\Users\Mentor\Documents\Macro Scheduler 15\NYTunnelTransfers.scp]
LastElapsedTime=00:00:18
LastRun=5/8/2023 8:01:19 AM
ElapsedTotal=09:38:49
NumRuns=415
NumLines=426
LinesLastExecuted=193
AverageExecutionTimePerLine=93
NumErrors=0
Can I add edit it to include more information like this...

Code: Select all

[C:\Users\Mentor\Documents\Macro Scheduler 15\NYTunnelTransfers.scp]
LastElapsedTime=00:00:18
LastRun=5/8/2023 8:01:19 AM
ElapsedTotal=09:38:49
NumRuns=415
NumLines=426
LinesLastExecuted=193
AverageExecutionTimePerLine=93
NumErrors=0
NumRunsToday=0
T1Offline=0
T2Offline=0

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Script Control Granularity

Post by Dorian (MJT support) » Mon May 08, 2023 1:49 pm

No, not that one. I'm referring to creating an ini file for the specific data you wish to track.

You can put whatever you like in your ini file. I suggest playing with EditiniFile and ReadiniFile using the examples shown.

Create the ini file first using notepad (or writeln if you wish).

So something like this :

Code: Select all

Let>MyInifile=d:\mynewini.ini

IfNotFileExists>MyInifile
  writeln>MyInifile,,
endif

Let>NumRunsToday=0
Let>T1Offline=0
Let>T2Offline=0

EditIniFile>MyInifile,tracking,RunsToday,NumRunsToday
EditIniFile>MyInifile,tracking,T1off,T1Offline
EditIniFile>MyInifile,tracking,T2off,T2Offline
So you can keep track and add one to the appropriate values, or zero them out, as needed. You just need to integrate it into the appropriate places within your script.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts