Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array Error - For Loop Exits Early

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,55900
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array Error - For Loop Exits Early
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Array Error - For Loop Exits Early - 1/23/2008 10:00:57 AM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline
Hi

This is my first post and i am a complete novice when it comes to VB scripting. I just require a little help.
I've written the following script. I read a simple text file to create an Array and then use the array to carry out a whole list of functions against each machine in the list. My loop is taken care of using For\Next but i'm finding that the script gets all the way through to 'Successful', then the next machine in the array isnt picked up
there are no quit's in any of the functions.
I've not listed the entire script below or any functions, i'm having a problem with the For loop

As i've said, i'm a completely self taught novice using bits of code that i can understand, can anyone easily spot any errors or any ways to do this better?
Thankyou very much in advance

' Main Part of the Script
arrComputer = Split(GetPCNameFromTxt(sInputFile),",")
If sEnvironment = "HeadOffice" Then 'HeadOffice Machine Start
 For intI = 0 To UBound(arrComputer) 
  sTarget = UCase(arrComputer(intI))
  If PingWorkstation(sTarget) = True Then
  sLocalUSDServer = GetLocalUSDServer(sTarget)'check to see if machine exists in USD
   If sLocalUSDServer <> "" Then
   DeletefromUSD sTarget,sLocalUSDServer
   End If
  sLocalUSDServer = GetLocalUSDServer(sTarget)'re-check to see if duplicate exists in USD
   If sLocalUSDServer <> "" Then
   DeletefromUSD sTarget,sLocalUSDServer
   End If
  sLocalUAMServer = GetUAMServer(sTarget)
   If sLocalUAMServer <> "" Then
   DeletefromUAM sTarget,sLocalUAMServer
   End If
    sLocationline = LocationCheck(sTarget)
    If Len(sLocationLine) <> 0 Then
     If BuildCheck(sTarget) = True Then
      sFoundAssetTag = AssetCheck(sTarget)
      If Len (sFoundAssetTag) <> 0 Then
      Set conn = CreateObject("ADODB.Connection")
      Connection_string = "Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=Rollout;Data Source=" & SeedServer
      Conn.Open Connection_string, sRODUserName, sRODPassword
      Set rs=CreateObject("ADODB.Recordset")
      rs.open "SELECT * FROM dbo.NonBranchSiteList WHERE (UPPER(dbo.NonBranchSiteList.SiteSubFix)) LIKE '%" & sLocationLine & "%'",conn,3,3
       sUSDStaging = rs.Fields(3)
       sURCRoot = rs.Fields(4)
       sUAMSector = rs.Fields(5)
       If IsNull(sUAMSector) Or IsNull(sURCRoot) Or IsNull(sUSDStaging) Then
       LogWrite("One or more of the required CA Management Servers have not been found in the NonBranchSiteList table.")
       sCode = "Management Servers not found"
       AddtoCSVFile sTarget, sCode
       Set conn = Nothing
       Set rs = Nothing
       Else
        LogWrite("The UAM Sector Server for the Target " & sTarget & " has been identified as " & sUAMSector & ".")
        LogWrite("The URC Root Management Server for the Target " & sTarget & " has been identified as " & sURCRoot & ".")
        LogWrite("The USD Staging Server for the Target " & sTarget & " has been identified as " & sUSDStaging & ".")
        InstallDir = "\C$\SYSMGT\"
        If FileCheck("\\" & sTarget & InstallDir & "UAM\AGENTS\UMCLISVC.EXE") = True Then
         If FileCheck("\\" & sTarget & InstallDir & "USD\BIN\TRIGGAG.EXE") = True Then
          If FileCheck("\\" & sTarget & InstallDir & "URC\RCHOST.EXE") = True Then
           If StopStartService(sTarget,"AmoAgent","Stop") = True Then
            If SetServiceStartup(sTarget,"AmoAgent","Automatic") = True Then
             If StopStartService(sTarget,"SDService","Stop") = True Then
              If SetServiceStartup(sTarget,"SDService","Automatic") = True Then
               If StopStartService(sTarget,"rcHost","Stop") = True Then
                If SetServiceStartup(sTarget,"rcHost","Automatic") = True Then
                 If StopStartService(sTarget,"CA-MessageQueuing","Stop") = True Then
                  If SetServiceStartup(sTarget,"CA-MessageQueuing","Disabled") = True Then
                   If SetServiceStartup(sTarget,"CA-MessageQueuing","Automatic") = True Then
                    If WriteRegKey(sTarget,"HKLM",LTSBRegKey,"LTSB_FJS_CA_UAMSECSVR",sUAMSector,"String") = True Then
                     If WriteRegKey(sTarget,"HKLM",LTSBRegKey,"LTSB_FJS_CA_USDSTGSVR",sUSDStaging,"String") = True Then
                      If WriteRegKey(sTarget,"HKLM",LTSBRegKey,"LTSB_FJS_CA_URCROOTSVR",sURCRoot,"String") = True Then
                       If ConfigureAgent(sTarget,sUAMSector,sURCRoot,sUSDStaging,sLocationLine,sFoundAssetTag) = True Then
                        If DisableTivoli(sTarget) = True Then
                         If StopStartService(sTarget,"CA-MessageQueuing","Start") = True Then
                          If StopStartService(sTarget,"AmoAgent","Start") = True Then
                           If StopStartService(sTarget,"SDService","Start") = True Then
                            If StopStartService(sTarget,"rcHost","Start") = True Then
                            LogWrite("The script has completed successfully for the target " & sTarget & ".")
                            sCode = "Successful"
                            AddtoCSVFile sTarget, sCode
                            End If
                           End If
                          End If
                         End If
                        End If
                       End If
                      End If
                     End If
                    End If
                   End If
                  End If
                 End If
                End If
               End If
              End If
             End If
            End If
           End If
          End If
         End If
        End If    
       End If
      End If
     End If 
    End If
  End If
 Next
ElseIf sEnvironment = "Branch" Then
 For intI = 0 To UBound(arrComputer)
  MsgBox (arrComputer(intI)) & " Branch" 'Branch Machine Start
 Next
End If
MsgBox ("Script Has Finished")
WScript.Quit(0)
 
 
Post #: 1
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 3:56:48 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Are you using On Error Resume Next anywhere in your script? If so, comment it out and see if it generates an error.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to sidler)
 
 
Post #: 2
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 8:28:18 PM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline
Hi
I'm not using On Error Resume Next anywhere in the script.
If i use the variable sEnvironment = "Branch", the array outputs the all the machines correctly and pops up the message boxes correctly
but if the variable is set to sEnvironment = "HeadOffice" and the bulk of the script is actioned, it dosn't list all the machines in the array.
it just exits after "success"

thanks
Sid

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 9:52:35 PM   
  ginolard


Posts: 1051
Score: 21
Joined: 8/10/2005
Status: offline
you might want to consider replacing all those IF statements with a single Select Case

For example,

Select Case True
   Case   sLocalUAMServer = GetUAMServer(sTarget)
      'do stuff
   Case  sLocalUSDServer <> ""
      'do stuff
   .
   .
   .
   .
   .
End Select

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to sidler)
 
 
Post #: 4
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 10:22:43 PM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline
Thats a good idea...
I'm very new to this so i'll give it a go and let you know
thanks for your help

(in reply to ginolard)
 
 
Post #: 5
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 11:40:45 PM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline
I was thinking about this.
if i use select case, will it work sequentially ie, it'll only run the next True function if the previous True function was correct?
thanks

Sid

(in reply to sidler)
 
 
Post #: 6
 
 RE: Array Error - For Loop Exits Early - 1/23/2008 11:43:41 PM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline
......If the Function was false, it'd move onto the Next machine in the array....(i meant to add)

(in reply to sidler)
 
 
Post #: 7
 
 RE: Array Error - For Loop Exits Early - 1/24/2008 12:52:00 AM   
  twilliamsen

 

Posts: 195
Score: 0
Joined: 1/18/2007
Status: offline
Replace all this with Select Case


      

Something like this

      

(in reply to sidler)
 
 
Post #: 8
 
 RE: Array Error - For Loop Exits Early - 1/24/2008 1:55:50 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
First, when you use Select - Case, there must be an expression on the Select line, so that example would not compile. Second, Select - Case will not replace nested If statements which is what the OP is using. Select - Case will replace sequential If statements.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to twilliamsen)
 
 
Post #: 9
 
 RE: Array Error - For Loop Exits Early - 1/24/2008 1:58:44 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Could you just go ahead and post the whole thing. I started reading through what you posted but I didn't even get past the first line before I needed to see more. I need to see what GetPCNameFromTxt does. I'm sure I will have other needs to help you so just posting the whole thing will save the trouble of me repeatedly asking for more.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: Array Error - For Loop Exits Early - 1/24/2008 2:41:10 AM   
  sidler

 

Posts: 7
Score: 0
Joined: 1/22/2008
Status: offline