Jump to content

Still Can't Figure Out What's wrong with this Code


deef99
 Share

Recommended Posts

I sincerely apologize for posting this again, but I am at my wits end trying to figure out what I am doing wrong as this code works intermittently and I just don't know why...

We have several products we take calls for in our call center. We have some backup agents that do other projects unless we get backed up on calls. This app runs on each of the backup agents' PCs and needs to alert them when ANY of the product lines gets to a threshold.

For EACH PRODUCT, it should:

Splash the Text on the screen

Play a sound only once

Write the alert to a text file on the network

As the threshold clears, it should Splashoff the text for that product, and reset the sound for that skill

This process checks a text file that is updated about every 5 seconds with the current status of the product lines. That text file looks like this:

644,0,0

650,0,0

651,0,0

652,0,0

655,0,0

690,0,0

707,0,0

740,0,0

The elements for each line: skill number, time in queue, number in queue and the file will always have the same layout and same skill numbers. Only the Time in queue and number in queue may change every five seconds it is written out.

It is possible that different products will have alerts while others don't, so I assumed I would need seperate variables for Splash Messages, whether the sound if on or off for a product, etc.

It just doesn't work consistently and I can't figure out where I am wrong. So, if anyone can run the code and assist, I would greatly appreciate it!

Current Code [not all products are set up yet since I can't even get what I have stable!]

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=G:\Avaya_OS_Ticker\CallTick_NS.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <File.au3>
#include "array.au3"
#include "String.au3"
#include <Sound.au3>
#include <Constants.au3>

Opt("TrayMenuMode", 0) ; Default tray menu items (Script Paused/Exit) will not be shown.
Opt("WinTitleMatchMode", 1) ;1=start of text
HotKeySet("^z", "Terminate"); Press Ctrl z to terminate script

Global $result, $vskill, $vOCW, $pt, $pd, $rr, $tCur, $tday, $search, $logfile, $hds, $hdn, $jd1, $jd2, $iq, $newlog
Global $aLines, $line
$messagehs = ""
$messagehn = ""
$messagej1 = ""
$messagej2 = ""
$hds = 0
$jd1 = 0
$jd2 = 0
$hdn = 0

;open sound file
$sound = _SoundOpen("\\ardfiles02\common\Avaya_OS_Ticker\tadaaa.wav", "Startup")

;set the MM_YYYY for log file and create unique log file on network for each PC user
$tday = @MON & "_" & @MDAY
$newlog = Random(10, 10000, 1)
$logfile = "\\ardfiles02\common\Avaya_OS_Ticker\SkillCheck_Log" & $tday & $newlog & ".txt"
If FileExists($logfile) Then
$logfile = "\\ardfiles02\common\Avaya_OS_Ticker\SkillCheck_Log" & $tday & $newlog & @MSEC & ".txt"
EndIf

;get the current hour and min
$tCur = @MON & "/" & @MDAY & "," & @HOUR & ":" & @MIN & " - "

While 9 = 9  ;runs continuously
_FileReadToArray("\\ardfiles02\common\avaya_OS_ticker\skillcheck.txt", $aLines)

For $i = 1 To $aLines[0]
  $line = $aLines[$i]

  ;grab the skill, OCW,in queue
  $aTemp = StringSplit($line, ",")
  $vskill = Number($aTemp[1]) ;skill number
  $vOCW = Number($aTemp[2]) ;time in queue
  $iq = Number($aTemp[3]) ;Calls in Queue

  FileOpen($logfile, 1)

  ;-----start skill checking ------------------------------------------------------------------------
  If (($vOCW >= 150 Or $iq >= 1) And $vskill = 690) Then
   $vskill = "HD Supplements"

  If $hds = 0 Then
    $result = $vskill & " shows OCW " & $vOCW & " seconds -- " & $iq & " Calls in Queue"
    FileWrite($logfile, $tCur & $result & @CRLF)
    _SoundPlay($sound, 1)
    $hds = 1 ;played sound set flag to no sound
    $messagehs = $vskill & " has Calls in Queue!"
    SplashTextOn("LOG IN IMMEDIATELY!", $messagehs, 250, 40, 875, 12, -1, "Arial", 9, 500)
    ControlSetText("LOG IN IMMEDIATELY!", "", "Static1", $messagehs)
   EndIf
   Sleep(2000)
  ElseIf (($vOCW < 150 Or $iq < 1 And $hds = 1) And $vskill = 690) Then
   $hds = 0
   SplashOff()
  EndIf
  ;------------------------------------------------------------------------------------------------------
  If $vOCW >= 15 And $vskill = 740 Then
   $vskill = "HD Newsletters"
   If $hdn = 0 Then
    _SoundPlay($sound, 1)
    $result = $vskill & " shows OCW " & $vOCW & " seconds -- " & $iq & " Calls in Queue"
    FileWrite($logfile, $tCur & $result & @CRLF)
    $hdn = 1 ;played sound set flag to no sound

    $messagehn = $vskill & " has Calls in Queue!"
    SplashTextOn("LOG IN IMMEDIATELY!", $messagehn, 250, 40, 875, 15, -1, "Arial", 10, 500)
    ControlSetText("LOG IN IMMEDIATELY!", "", "Static1", $messagehn)
    $result = $vskill & " shows OCW: " & $vOCW & " seconds"
   EndIf
   Sleep(2000)
  ElseIf $vOCW < 15 And $hdn = 1 And $vskill = 740 Then
   $hdn = 0
   SplashOff()
  EndIf
  ;------------------------------------------------------------------------------------------------------
  If (($vOCW >= 150 Or $iq >= 1) And $vskill = 707) Then
   ;MsgBox(0,"",$vOCW&" "&$iq&" "&$vskill,5)
   $vskill = "John Deere CCC"
   If $jd1 = 0 Then
    _SoundPlay($sound, 1)
    $result = $vskill & " shows OCW " & $vOCW & " seconds -- " & $iq & " Calls in Queue"
    FileWrite($logfile, $tCur & $result & @CRLF)
    $jd1 = 1 ;played sound set flag to no sound
    $messagej1 = $vskill & " has Calls in Queue!"
    SplashTextOn("LOG IN IMMEDIATELY!", $messagej1, 250, 40, 875, 18, -1, "Arial", 9, 500)
    ControlSetText("LOG IN IMMEDIATELY!", "", "Static1", $messagej1)
    $result = $vskill & " shows OCW: " & $vOCW & " seconds"
    Sleep(2000)
   EndIf
  ElseIf ($vOCW < 150 Or $iq < 1) And ($jd1 = 1 And $vskill = 707) Then
   $jd1 = 0
   SplashOff()
  EndIf
  ;------------------------------------------------------------------------------------------------------
  ;------------------------------------------------------------------------------------------------------
  ;msgbox(0,"",$vOCW&" "&$iq&" "&$vskill,2)
Next
Sleep(2000)
If @HOUR >= 22 Then Exit

WEnd


Func Terminate()
FileClose($logfile)
_SoundClose($sound)
Exit 0
EndFunc   ;==>Terminate
Link to comment
Share on other sites

It just doesn't work consistently ...

is a bit vague.

As the file is updated every 5 seconds there might be a problem with the consistency of this file.

We had a similar situation many years ago and we solved it by creating a lock file. The application that updates the file ceates a lock file (e.g. lock.txt) then updates the file and if successful deletes lock.txt.

The agent scripts check for the lock.txt file. If it exists they wait a bit and recheck until the lock file is deleted. Then the agent script reads the file.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

deef99,

If the file is open for update while your routine is reading the results of the read are certain to be unpredictible. You need to ensure exclusive use of the file during update, as water said...

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

The approach I just described ensures that the agent script can always read the whole file. Imagine the file is updated and the update process has finished to rewrite 50% of the file. In this moment the agent script tries to read the file. What do you think will the agent script read?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Okay, I understand. Can you give me a quick lead on the code for this locked file coding? Do I create the lock file at the before the _FileReadtoArray and then delete it after all the elements have been read? Or, do you mean I create the lock file AND delete it in the process that generate the skillcheck.txt file?

Thank you so much for your quick responses!!!!

Link to comment
Share on other sites

deef99,

Simplest method:

whatever updates the the file creates a "lock" file. When the update is done the updating entity deletes the "lock" file. Your script checks for "lock" file precence and only reads the file if lock file does not exist.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Something like this:

; Updater script
$sLockFile = "\\ardfiles02\common\avaya_OS_ticker\skillcheck.lock"
FileWrite($sLockFile, "Lock File - Don't Delete!")
If @error Then Exit MsgBox(16, "Error", "Couldn't create the lock file")
; Update the file \\ardfiles02\common\avaya_OS_ticker\skillcheck.txt here
FileDelete($sLockFile)
If @error Then Exit MsgBox(16, "Error", "Couldn't delete the lock file")

; Agent script
$sLockFile = "\\ardfiles02\common\avaya_OS_ticker\skillcheck.lock"
While FileExists($sLockFile)
    Sleep(100) ; wait for 100 ms
WEnd

You might end the loop of the agent script after x loops and give an error message so the agent script doesnt loop forever if there is a problem with the lock file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok... I have found the the Updater script is not AUTO IT... looks like VBA.

I can get the LOCK.txt file to be created, but no matter where I put the DELETE, the file never gets deleted.

Not sure what to do from here...I don't expect you guys should help with other code that's not AUTO It. I understand that.

Oh well.... I appreciate all the insight you gave me anyway...

'LANGUAGE=ENU

'SERVERNAME=10.1.195.13

Public Sub Main()

Const wshYes = 6

Const wshNo = 7

Const wshYesNoDialog = 0

Const wshQuestionMark = 32

Set objShell = CreateObject("Wscript.Shell")

intReturn = 0

'## cvs_cmd_begin

'## ID = 2001

'## Description = "Report: Integrated: Designer: OS Skill View for Pop Up: Export Data"

'## Parameters.Add "Report: Integrated: Designer: OS Skill View for Pop Up: Export Data","_Desc"

'## Parameters.Add "Reports","_Catalog"

'## Parameters.Add "2","_Action"

'## Parameters.Add "1","_Quit"

'## Parameters.Add "IntegratedDesignerOS Skill View for Pop Up","_Report"

'## Parameters.Add "1","_ACD"

'## Parameters.Add "6345","_Top"

'## Parameters.Add "8707","_Left"

'## Parameters.Add "2460","_Width"

'## Parameters.Add "4395","_Height"

'## Parameters.Add "The report IntegratedDesignerOS Skill View for Pop Up was not found on ACD 1.","_ReportNotFound"

'## Parameters.Add "*","_BeginProperties"

'## Parameters.Add "640;641;707;651;644;643;650;642;652;655;740;690","Splits/Skills"

'## Parameters.Add "*","_EndProperties"

'## Parameters.Add "*","_BeginViews"

'## Parameters.Add "*","_EndViews"

'## Parameters.Add "ardfiles02commonAvaya_OS_Tickerskillcheck.txt","_Output"

'## Parameters.Add "44","_FldSep"

'## Parameters.Add "0","_TextDelim"

'## Parameters.Add "True","_NullToZero"

'## Parameters.Add "False","_Labels"

'## Parameters.Add "True","_DurSecs"

On Error Resume Next

cvsSrv.Reports.ACD = 1

Set Info = cvsSrv.Reports.Reports("IntegratedDesignerOS Skill View for Pop Up")

If Info Is Nothing Then

If cvsSrv.Interactive Then

MsgBox "The report IntegratedDesignerOS Skill View for Pop Up was not found on ACD 1.", vbCritical Or vbOKOnly, "Avaya CMS Supervisor"

Else

Set Log = CreateObject("ACSERR.cvsLog")

Log.AutoLogWrite "The report IntegratedDesignerOS Skill View for Pop Up was not found on ACD 1."

Set Log = Nothing

End If

Else

Do While intReturn <> 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile("ardfiles02commonAvaya_OS_TickerLock.txt")

b = cvsSrv.Reports.CreateReport(Info,Rep)

If b Then

Rep.SetProperty "Splits/Skills","707;690;740;651;644;650;652"

b = Rep.ExportData("ardfiles02commonAvaya_OS_Tickerskillcheck.txt", 44, 0, True, False, True)

Rep.Quit

If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID

Set Rep = Nothing

End If

intReturn = objShell.Popup("Click OK to Exit CMS Script!", _

15, "Running Skill Report", wshYesNoDialog + wshQuestionMark)

LOOP

End If

Set Info = Nothing

'## cvs_cmd_end

End Sub

Link to comment
Share on other sites

objFSO.Deletefile("\\ardfiles02\common\Avaya_OS_Ticker\Lock.txt")
according to http://www.vbforums.com/showthread.php?t=349991?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Or you create an AutoIt script to create the lock file, call the VB script and delete the lock file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Still working with this as mgmt is really not happy with me at this point...

What if I did this: had the AUTO IT program read the file to array at :15 and :45 in the hour.... have the vb script write the file out at :05 and :35 in the hour.... this way they won't clash.

If I can figure that angle out... :D

Link to comment
Share on other sites

First you wanted to check every 5 seconds now a 30 minutes interval seems to be ok :D

Did you try my latest suggestion? A lock file lets you choose a much smaller interval.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm sorry...I'm getting frantic. I meant SECONDS... If the file is written out at 10 seconds into a minute...then read at 15 seconds, they shouldn't collide. And then all PCs are reading the file at the same time.

My problem is...I can create the LOCK file with the VBA script that I have posted...but I can't Delete the file within the VBA script no matter where I put the deletefile command.

Link to comment
Share on other sites

But can you call an Autoit script on the "server" which creates the lock file, calls the VBA script and then deletes the lock file?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I think how to change this VBA script is a question best to be asked on an Avaya Users Group.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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