Solved

VBScript Compilation Error

Posted on 2013-06-22
8
284 Views
Last Modified: 2014-04-11
Hello Experts,

Can someone please help figure out why I'm getting the error shown in the attachment?


# $language = "VBScript"
# $interface = "1.0"

' ASSUMPTION: file being 'tailed' contains information
'             similar to:
'   Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
'   Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
'   Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down


Sub Main()

	
    ' Make sure that we are running in Synchronous mode so
    ' that when WaitForStrings() finds something, we can
    ' capture the current line without risk of it already
    ' having flown by on the screen.  This slows things down
    ' a bit, but provides insurance against errors due to
    ' SecureCRT and the script running asynchronously.
    crt.Screen.Synchronous = true

    ' Start tailing a file...
    crt.Screen.Send "tail tailfile.txt" & vbcr

  ' Example #1: Uses WaitForString to look for just the text
  '             we care about.  Once the text is found, the
  '             line on which the text was located is captured
  '             and a piece of information is parsed using the
  '             Split() builtin VBScript method.
    CaptureJustTheLinesWeCareAbout

  ' Example #2: Uses WaitForString to detect when every new line
  '             arrives from the remote.  Each line of text is
  '             captured, and the Instr() builtin VBScript
  '             function is used to detect the presence of the
  '             specific text we care about.  Iff it is present,
  '             the Split() builtin VBScript method is used to
  '             parse out the relevant piece of information.
  '
  '             The benefit of this method over
  '             CaptureJustTheLinesWeCareAbout is that we
  '             can retrieve information from the line if
  '             the text we care about comes prior to the
  '             relevant piece of information that we would
  '             like to display as part of our notification.
  '
  '             To enable this example, comment out the statement
  '             on line 29 and uncomment the line below:
  '  CaptureAllLinesAndSearchForTextWeCareAbout

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
  MsgBox "Capturing just the lines we care about"
  do
    ' Look for specific output
  

    crt.Screen.WaitForString "changed state to down"

    ' Once specific output is found, capture the line
    ' of text on which the "changed to state down" string
    ' was located.
    szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
                                   0, _
                                   crt.Screen.CurrentRow, _
                                   crt.Screen.Columns)

    ' Trim off any leading or training spaces
    szCurrentLine = Trim(szCurrentLine)

    ' Use the Split() method (builtin VBScript method)
    ' to get at the component we care about (deviceID)
    vElements = Split(szCurrentLine, " ")

for each x in vElements 
    'document.write(x & "<br />")
next

    MsgBox "Device """ & vElements(3) & """ just went down."

' Modify the "$" or the "->" in the array below to reflect the actual shell
    ' prompt you expect to find when authentication is successful to your remote
    ' machine.
    PossibleShellPrompts = Array(_
        "changed state to down:")

    Do
           
              Select Case objNewTab.Screen.MatchIndex
                
            Case 1 ' "changed state to down:"
                ' Send the username
                objNewTab.Screen.Send strUser & vbcr & "show ip int brief"
                
            Case Else
                DisplayMessage "Ooops! Looks like you forgot to add code " & _
                    "to handle this index: " & objNewTab.Screen.MatchIndex & _
                    vbcrlf & _
                    vbcrlf & _
                    "Modify your script code's ""Select Case"" block " & _
                    "to have 'Case' statements for all of the strings you " & _
                    "are passing to the ""WaitForStrings"" method."
                
                objNewTab.Session.Disconnect
                ' Only attempt to close the tab if it's not *the* script tab
                If crt.GetScriptTab().Index <> objNewTab.Index Then
                    objNewTab.Close
                End If
                
                Exit Sub
        End Select
    Loop

   'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."

'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
  Loop



End Sub

Open in new window

scripterror3.png
0
Comment
Question by:cpatte7372
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
8 Comments
 

Author Comment

by:cpatte7372
ID: 39267711
Hello Experts,

I have updated the question with new question see above
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39268145
I'm not familiar with SecureCRT, but on line 91 you are referencing an object named "objNewTab" that you never created in a prior Set statement.  That looks like the cause of the error.

~bp
0
 

Author Comment

by:cpatte7372
ID: 39268319
Billprew,

Thanks for responding. I'm extremely new to scripting. Can you tell me where I need to create the 'Set' statement?

Cheers
0
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

Author Comment

by:cpatte7372
ID: 39268399
Hello Experts,

I changed the script to add the 'Set' statement as originally created. However, I'm now getting the error message shown in the attachment.

# $language = "VBScript"
# $interface = "1.0"

' ASSUMPTION: file being 'tailed' contains information
'             similar to:
'   Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
'   Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
'   Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down


Sub Main()

	
    ' Make sure that we are running in Synchronous mode so
    ' that when WaitForStrings() finds something, we can
    ' capture the current line without risk of it already
    ' having flown by on the screen.  This slows things down
    ' a bit, but provides insurance against errors due to
    ' SecureCRT and the script running asynchronously.
    crt.Screen.Synchronous = true

    ' Start tailing a file...
    crt.Screen.Send "tail tailfile.txt" & vbcr

  ' Example #1: Uses WaitForString to look for just the text
  '             we care about.  Once the text is found, the
  '             line on which the text was located is captured
  '             and a piece of information is parsed using the
  '             Split() builtin VBScript method.
    CaptureJustTheLinesWeCareAbout

  ' Example #2: Uses WaitForString to detect when every new line
  '             arrives from the remote.  Each line of text is
  '             captured, and the Instr() builtin VBScript
  '             function is used to detect the presence of the
  '             specific text we care about.  Iff it is present,
  '             the Split() builtin VBScript method is used to
  '             parse out the relevant piece of information.
  '
  '             The benefit of this method over
  '             CaptureJustTheLinesWeCareAbout is that we
  '             can retrieve information from the line if
  '             the text we care about comes prior to the
  '             relevant piece of information that we would
  '             like to display as part of our notification.
  '
  '             To enable this example, comment out the statement
  '             on line 29 and uncomment the line below:
  '  CaptureAllLinesAndSearchForTextWeCareAbout

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
  MsgBox "Capturing just the lines we care about"
  do
    ' Look for specific output
  

    crt.Screen.WaitForString "changed state to down"

    ' Once specific output is found, capture the line
    ' of text on which the "changed to state down" string
    ' was located.
    szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
                                   0, _
                                   crt.Screen.CurrentRow, _
                                   crt.Screen.Columns)

    ' Trim off any leading or training spaces
    szCurrentLine = Trim(szCurrentLine)

    ' Use the Split() method (builtin VBScript method)
    ' to get at the component we care about (deviceID)
    vElements = Split(szCurrentLine, " ")

for each x in vElements 
    'document.write(x & "<br />")
next

    MsgBox "Device """ & vElements(3) & """ just went down."

Set objNewTab = crt.Session.ConnectInTab( _
        "/SSH2 " & strHost, _
        bWaitForAuthToCompleteBeforeReturning, _
        bLetCallerDetectAndHandleConnectionErrors)
        


Set objConfig = objNewTab.Session.Config
objNewTab.Screen.Synchronous = True

' Modify the "$" or the "->" in the array below to reflect the actual shell
    ' prompt you expect to find when authentication is successful to your remote
    ' machine.
    PossibleShellPrompts = Array(_
        "changed state to down:")

    Do
           objNewTab.Screen.WaitForStrings
           Select Case objNewTab.Screen.MatchIndex
                
            Case 1 ' "changed state to down:"
                ' Send the username
                objNewTab.Screen.Send strUser & vbcr & "show ip int brief"
                
            Case Else
                DisplayMessage "Ooops! Looks like you forgot to add code " & _
                    "to handle this index: " & objNewTab.Screen.MatchIndex & _
                    vbcrlf & _
                    vbcrlf & _
                    "Modify your script code's ""Select Case"" block " & _
                    "to have 'Case' statements for all of the strings you " & _
                    "are passing to the ""WaitForStrings"" method."
                
                objNewTab.Session.Disconnect
                ' Only attempt to close the tab if it's not *the* script tab
                If crt.GetScriptTab().Index <> objNewTab.Index Then
                    objNewTab.Close
                End If
                
                Exit Sub
        End Select
    Loop

   'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."

'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
  Loop



End Sub

Open in new window

scripterror4.png
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39268419
I would look in your manual for this. Your error suggests something is wrong with the object you are creating.  Chapter 3 is what you want http://www.vandyke.com/support/tips/scripting/scripting_essentials.pdf
0
 

Author Comment

by:cpatte7372
ID: 39268469
Hi Padas

I will read into the manual for guidance.

In the meantime, would be able to assist with the question at:

http://www.experts-exchange.com/Hardware/Networking_Hardware/Routers/Q_28162093.html#a39268269

Cheers
0
 

Author Comment

by:cpatte7372
ID: 39993982
I've requested that this question be closed as follows:

Accepted answer: 0 points for cpatte7372's comment #a39268399

for the following reason:

cheers
0
 

Author Closing Comment

by:cpatte7372
ID: 39993983
cheers
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to fix error "424" object required. 6 63
Management of Huawei B315 2 68
Split on ASP 8 50
script to read text file 34 27
Problem Description:   Couple of months ago we upgraded the ADSL line at our branch office from Home to Business line. The purpose of transforming the service to have static public IP’s. We were in need for public IP’s to publish our web resour…
How to set-up an On Demand, IPSec, Site to SIte, VPN from a Draytek Vigor Router to a Cyberoam UTM Appliance. A concise guide to the settings required on both devices
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question