VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   If Then with Function produces error (https://forums.vandyke.com/showthread.php?t=11258)

olivebranch2006 10-31-2013 06:03 PM

If Then with Function produces error
 
Hello,

This If Then End if statement with a function in it is producing the error:
VBScript Compilation error
Error: Expected Statement
Line: 45
If mySwitchCount = 1 Then 3750x48-1

Do you know why? Code is below.

Thanks!

Code:

main

sub main()

crt.Screen.Synchronous = True



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

'Declare Strings
dim mySwPort
dim phonemac
                                                         
'count the number of switches
Dim mySwitchCount
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

myPortNum = 1

If mySwitchCount = 1 Then 3750x48-1
End If

If mySwitchCount = 2 Then 3750x48-1 and 3750x48-2
End If

If mySwitchCount = 3 _
then 3750x48-1 _
then 3750x48-2 _
then 3750x48-3 _
End If

If mySwitchCount = 4 _
then 3750x48-1 _
then 3750x48-2 _
then 3750x48-3 _
then 3750x48-4 _
End If



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


end sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Incrementing Loop for each port of a switch
function 3750x48-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
screenrow = crt.Screen.CurrentRow
phonemac = crt.Screen.Get(screenrow, 3, screenrow, 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 " & phonemac & " 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
crt.Screen.WaitForStrings "IP Phone", "#", "Ieee PD"
'Ieee PD is a Paging Zone Controller. skip these ports
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 "
phonevlan = 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 " & phonevlan & 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
end function

function 3750x48-2
end function

function 3750x48-3
end function

function 3750x48-4
end function


rtb 11-01-2013 10:32 AM

Hi olivebranch2006,

I have gone through the script code, and all of the problems you are seeing and will see are VBScript syntax errors rather than problems with SecureCRT. You may consider taking a look at the scripting manual that we have published at the following location:
http://www.vandyke.com/support/tips/...ing/index.html
In the first chapter of the scripting manual, we point to the Microsoft documentation on VBScript. You may want to familiarize yourself with VBScript before diving into the scripting manual.

The error you are seeing can mean that you are missing one part of a pair of statements or keywords, but it can also point to other issues in the script code. When a syntax error is encountered by a script engine, it is not always clear what was originally intended by the script author. The information that the script engine is able to provide can sometimes be difficult to interpret.

Here is an example that illustrates proper syntax and ways to make code more readable:
Code:

crt.Screen.Synchronous = True
crt.Screen.WaitForStrings "1","2","3","4"
Select Case crt.Screen.MatchIndex
    Case 1
        nNum = 1
    Case 2
        nNum = 2
    Case 3
        nNum = 3
    Case 4
        nNum = 4
End Select

If nNum = 1 Then F1

If nNum = 2 Then
    F1
    F2
End If

If nNum = 3 Then
    F1
    F2
    F3
End If

If nNum = 4 Then
    F1
    F2
    F3
    F4
End If

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub F1()
    MsgBox "Entered subroutine 1."
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub F2()
    MsgBox "Entered subroutine 2."
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub F3()
    MsgBox "Entered subroutine 3."
End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub F4()
    MsgBox "Entered subroutine 4."
End Sub


olivebranch2006 11-04-2013 03:18 PM

Still a problem
 
Hello,

I have read the guide but it has been a while. Now that I've added a bunch of tabs and tried placing each function in a sub, I'm still getting the same error. Can you please advise?

Here is the new version:

Code:

crt.Screen.Synchronous = True

main

sub main()

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

'Declare Global Strings
Dim mySwPort
Dim phonemac
Dim mySwitchCount
                                                         
'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

myPortNum = 1

If mySwitchCount = 1 Then 3750x48-1

If mySwitchCount = 2 Then
        3750x48-1
        3750x48-2
End If

If mySwitchCount = 3 Then
        3750x48-1
        3750x48-2
        3750x48-3
End If

If mySwitchCount = 4 Then
        3750x48-1
        3750x48-2
        3750x48-3
        3750x48-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 3750x48-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
                        screenrow = crt.Screen.CurrentRow
                        phonemac = crt.Screen.Get(screenrow, 3, screenrow, 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 " & phonemac & " 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 "
                                        phonevlan = 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 " & phonevlan & 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
End Function
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function 3750x48-2
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function 3750x48-3
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function 3750x48-4
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


rtb 11-04-2013 04:39 PM

1 Attachment(s)
Hi olivebranch2006,

The problem you are having now is still a VBScript syntax problem. I would suggest familiarizing yourself with the Microsoft VBScript scripting language documentation and more specifically the fundamentals before moving forward with your script. The problem on line 30 below is the name of your function:
If mySwitchCount = 1 Then 3750x48-1
Please see the attached screenshot of the Microsoft help.

olivebranch2006 11-04-2013 04:59 PM

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
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


olivebranch2006 11-04-2013 05:25 PM

Now Working
 
Hello Todd,

It is working now by replacing
For i to 48

with
For Each strSwitchPort In vSwitchPorts

Funny, the i to 48 has worked for me before. maybe i didn't declare a variable globally...

Here is the working script and hope you have a good day.


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
Dim vSwitchPorts(48)
vSwitchPorts(0) = "1"
vSwitchPorts(1) = "2"
vSwitchPorts(2) = "3"
vSwitchPorts(3) = "4"
vSwitchPorts(4) = "5"
vSwitchPorts(5) = "6"
vSwitchPorts(6) = "7"
vSwitchPorts(7) = "8"
vSwitchPorts(8) = "9"
vSwitchPorts(9) = "10"
vSwitchPorts(10) = "11"
vSwitchPorts(11) = "12"
vSwitchPorts(12) = "13"
vSwitchPorts(13) = "14"
vSwitchPorts(14) = "15"
vSwitchPorts(15) = "16"
vSwitchPorts(16) = "17"
vSwitchPorts(17) = "18"
vSwitchPorts(18) = "19"
vSwitchPorts(19) = "20"
vSwitchPorts(20) = "21"
vSwitchPorts(21) = "22"
vSwitchPorts(22) = "23"
vSwitchPorts(23) = "24"
vSwitchPorts(24) = "25"
vSwitchPorts(25) = "26"
vSwitchPorts(26) = "27"
vSwitchPorts(27) = "28"
vSwitchPorts(28) = "29"
vSwitchPorts(29) = "30"
vSwitchPorts(30) = "31"
vSwitchPorts(31) = "32"
vSwitchPorts(32) = "33"
vSwitchPorts(33) = "34"
vSwitchPorts(34) = "35"
vSwitchPorts(35) = "36"
vSwitchPorts(36) = "37"
vSwitchPorts(37) = "38"
vSwitchPorts(38) = "39"
vSwitchPorts(39) = "40"
vSwitchPorts(40) = "41"
vSwitchPorts(41) = "42"
vSwitchPorts(42) = "43"
vSwitchPorts(43) = "44"
vSwitchPorts(44) = "45"
vSwitchPorts(45) = "46"
vSwitchPorts(46) = "47"
vSwitchPorts(47) = "48"

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
For Each strSwitchPort In vSwitchPorts
        If strSwitchPort = "" Then Exit For
        crt.Screen.Send "terminal length 0" & vbCr
        crt.Screen.WaitForString "#"
        crt.Screen.Send "sh cdp ne int g1/0/" & strSwitchPort & 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/" & strSwitchPort & 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/" & strSwitchPort & 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/" & strSwitchPort & 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/" & strSwitchPort & 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
Next
'End Function
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-2
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-3
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'function f3750x48-4
'end function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


rtb 11-05-2013 12:13 PM

OB,

Your code was doing this:
Code:

Sub F1
    Function f3750x48-1
        ' Lots of lines of code...
        ' Lots of lines of code...
        ' Lots of lines of code...
        ' Lots of lines of code...
    End Function
End Sub

The Statements section of VBScript reference I encouraged you to explore has a "Remarks" section that explains:
You cannot define a Function procedure inside any other procedure (for example, Sub or Property Get).
In other words, you can't have any Function statements inside of a Sub ... End Sub block. Nor can you have any Sub statements inside of a Function .. End Function block.

You can call functions/subs by name from within another function/sub definition, but you cannot declare/define additional functions/subs within any function/sub definition.

In my initial example, I used Sub Procedures rather than Functions Procedures because Sub Procedures are used for situations where the code does not need to return a value. Here is an excerpt from Microsoft documentation about VBScript Procedures:
A Sub procedure is a series of VBScript statements (enclosed by Sub and End Sub statements) that perform actions but don't return a value.
The problem does not appear to be with the looping statement, but the For Each...Next option is easier to use when iterating over an array in my opinion.


All times are GMT -6. The time now is 09:20 AM.