0

I have the below script that keeps receiving

Compilation Error Line 16 - Expected Sub

I'm not seeing what's causing this.

This script is run by acscript for an Avaya phone system. It's probable the ## cvs_cmd_begin and ## cvs_cmd_end are replaced with something else by the engine.

'SERVERNAME=123.45.67.89
Public Sub Main()
'## cvs_cmd_begin
' =========================================================
'  ERROR ERROR ERROR
'  If you're having trouble running a script make sure it's Encoding = UTF-8 (use Notepad++)
' =========================================================
'   On Error Resume Next

    SaveFolder = "K:\Telephony\ACD Automation\AutoReport.AgentInterval\Daily 20200124\"
    SaveFile = "Agent.Interval_20200124_12345.txt"

   cvsSrv.Reports.ACD = 1
   Set Info = cvsSrv.Reports.Reports("Historical\Designer\A.Agent Interval")

    If Info Is Nothing Then
        Exit
    Else
        b = cvsSrv.Reports.CreateReport(Info,Rep)

        If b Then
            Rep.TimeZone = "default"    
            Rep.SetProperty "Agent", "12345"
            Rep.SetProperty "Date", "1/24/2020"
            Rep.SetProperty "Times", "07:00-20:45"

            b = Rep.ExportData(SaveFolder & SaveFile, 9, 0, False, True, True)
                Rep.Quit
                Set Rep = Nothing
        End If
    End If

    Set Info = Nothing
'## cvs_cmd_end
End Sub
Ryan.James
  • 47
  • 5
  • Well I just commented out the outer If block and the Set Info = at the end and it works. Not really a problem for me if the script fails as it just means the report returned no data so... – Ryan.James Jan 25 '20 at 18:08
  • 1
    `Exit` what on line 16? `Exit` is always followed by what it is you are exiting. –  Jan 25 '20 at 18:49
  • @Mark yep, [answered that 30 minutes earlier](https://stackoverflow.com/posts/59911699/timeline). – user692942 Jan 25 '20 at 20:15
  • But you didn't make the point of actually looking at line 16. –  Jan 25 '20 at 20:20
  • @Mark Really? Didn’t realise the `Exit` statement appears more than once in the code, oh yeah, it doesn’t. – user692942 Jan 25 '20 at 20:44
  • The person who posted should have READ the error message. It is quite explicit as to what and where. –  Jan 26 '20 at 03:11
  • @mark agree, the error is pretty self explanatory if you realise that `Exit` is not a valid statement in VBScript. It tells you the line where it expects `Sub` so not a big ask to work out. – user692942 Jan 26 '20 at 12:16

1 Answers1

0

The issue is the use of the Exit statement without the accompanying keyword. There are five flavours of the Exit statement that depend on the context.

  1. Exit Do
  2. Exit For
  3. Exit Function
  4. Exit Sub
  5. Exit Property

In this instance the code is trying to exit the Sub Procedure if the Info object variable is not set. The fix is to change line 16 from

Exit

to

Exit Sub
user692942
  • 16,398
  • 7
  • 76
  • 175