View Single Post
  #5  
Old 11-04-2013, 03:59 PM
olivebranch2006 olivebranch2006 is offline
Registered User
 
Join Date: Apr 2010
Posts: 35
Function issue

Hello Todd,

I skimmed the syntax of functions and subs in the microsoft documentation, thank you. I'm still getting this error even though I'm following sub and function syntax correctly:

vbscript compilation error: Syntax error
line 83
Function f3750x48-1

Any ideas?
here is the latest script:



Code:
Language="VBScript"
Interface="1.0"

crt.Screen.Synchronous = True

Dim shell
Set shell = CreateObject("WSCript.Shell")

'Declare Global Strings
Dim mySwPort
Dim myphonemac
Dim mySwitchCount
Dim myscreenrow
Dim myPortNum
myPortNum = 1
Dim myphonevlan

Sub Main()
							  
'count the number of switches
crt.Screen.Send "sh int status" & vbCr
crt.Screen.WaitForStrings "4/0/48","3/0/48","2/0/48","1/0/48"
Select Case crt.Screen.MatchIndex
	Case 1
		mySwitchCount = 4
	Case 2
		mySwitchCount = 3
	Case 3
		mySwitchCount = 2
	Case 4
		mySwitchCount = 1
End select

If mySwitchCount = 1 Then 
F1 'f3750x48-1
End If

If mySwitchCount = 2 Then 
	F2
'	f3750x48-1
'	f3750x48-2
End If

If mySwitchCount = 3 Then
	F3
'	f3750x48-1
'	f3750x48-2
'	f3750x48-3
End If

If mySwitchCount = 4 Then
	F4
'	f3750x48-1
'	f3750x48-2
'	f3750x48-3
'	f3750x48-4
End If

If crt.Session.Connected Then
crt.Session.Disconnect
msgbox "Finished Programming"
End If


End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Incrementing Loop for each port of a switch

Sub F1
Function f3750x48-1
For i to 48
	crt.Screen.Send "terminal length 0" & vbCr
	crt.Screen.WaitForString "#"
	crt.Screen.Send "sh cdp ne int g1/0/" & myPortNum & vbCr
	crt.Screen.WaitForStrings "IP Phone", "VG224", "DMP", "Ieee PD", "AIR-CAP", "#"
	Select Case crt.Screen.MatchIndex
		Case 1
			'Found a phone, secure it
			myscreenrow = crt.Screen.CurrentRow
			myphonemac = crt.Screen.Get(myscreenrow, 3, myscreenrow, 15)
			crt.Screen.Send "config t" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "int g1/0/" & myPortNum & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security max 1 vlan voice" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security violation shutdown vlan" & vbCr
			crt.Screen.WaitForString "#"
			crt.Screen.Send "switchport port-security mac-address " & myphonemac & " vlan voice" & vbCr
			crt.Screen.WaitForString "#"
			crt.screen.send "end" & vbcr
		Case 2
			'Found a VG224, ignore the port
		Case 3
			'Found a DMP, ignore the port
		Case 4
			'don't remember what this means LOOK INTO THIS can be paging zone controller
		Case 5
			'Found an LWAP, ignore the port
		Case 6
			crt.Screen.Send "sh power inline int g1/0/" & myPortNum & vbCr
			'Ieee PD is a Paging Zone Controller. skip these ports
			crt.Screen.WaitForStrings "IP Phone", "#", "Ieee PD"
			Select Case crt.Screen.MatchIndex
				Case 1
					'Phone already programmed, skip
				Case 2
					'No Phone, lock the port by removing voice vlan.  first identify the voice vlan
					crt.screen.send "sh run int g1/0/" & myPortNum & vbcr
					crt.screen.waitforstring "switchport voice vlan "
					myphonevlan = Trim(crt.Screen.ReadString(vbcr))
					crt.screen.send "config t" & vbcr
					crt.screen.waitforstring "#"
					crt.Screen.Send "int g1/0/" & myPortNum & vbCr
					crt.screen.waitforstring "#"
					crt.screen.send "no switchport voice vlan " & myphonevlan & vbcr
					crt.screen.waitforstring "#"
					crt.screen.send "end " & vbcr
					crt.screen.waitforstring "#"
				Case 3
					'Paging Zone Controller, skip the port
			end select
	end select
myPortNum = myPortNum + 1
Next
End Function
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-2
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-3
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-4
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Last edited by rtb; 11-05-2013 at 07:58 AM.
Reply With Quote