Login | |
|
 |
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)
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|