Solved

Expected Loop error

Posted on 2009-05-06
2
232 Views
Last Modified: 2012-05-06
Hi guys,
Ive been trying to work out what is wrong with the following code.
Im getting the following error:

Expected 'Loop'

Any help greatly appreciated.
<head>
<title>Enumerate System Information on Remote Computers</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Enumerate System Information"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
<style type="text/css">
 
html {
font-family:arial;
font-size:smaller;
 
}
 
table {
border-collapse:collapse;
border:solid 1px black;
font-family:arial;
font-size:0.8em;
}
 
tr, td, th {
border-collapse:collapse;
border-style:solid;
}
 
td { border-width: 1px; }
 
 
</style>
 
 
</head>
<script language="vbscript">
Sub Window_onLoad
        intWidth = 600
        intHeight = 480
        Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub
 
Sub GetInfo
        run_button.disabled = True
        ComputerListFile.disabled = True
        Const ForReading = 1
        Const ForWriting = 2
        Set objFSO = CreateObject("Scripting.FileSystemObject")
 
        If ComputerListFile.Value <> "" Then
                If objFSO.FileExists(ComputerListFile.Value) = True Then
                        Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
                        
                        strHTML = "<table width='40%' border=1 bgcolor='white'>" &_
                        "<th style='background:c0c0c0'><b>System</b></th><th style='background:c0c0c0'><b>Service Pack</b>"
                        Results.InnerHTML = strHTML
 			strHTML2 = "<table width='40%' border=1>" &_
                        "<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
			Totals.InnerHTML = strHTML2
			iArch1 = 0
			iArch2 = 0
			iArch3 = 0
			iArch4 = 0
			iArch5 = 0
			iArchU = 0
			iUnreach = 0
                        Do Until List.AtEndOfStream
                                strComputer = List.ReadLine
                                If Ping(strComputer) Then
 
                                        Set objWMIService = GetObject("winmgmts:" _
                                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                				    Set colProcessors = objWMIService.ExecQuery _
                				    ("Select * From Win32_Processor")
 
                                        For Each objProcessor in colProcessors
							strArch = "Arch Unknown"
							If objProcessor.Architecture = 0 Then strArch = "x86"
							If objProcessor.Architecture = 1 Then strArch = "MIPS"
							If objProcessor.Architecture = 2 Then strArch = "Alpha"
							If objProcessor.Architecture = 3 Then strArch = "PowerPC"
							If objProcessor.Architecture = 9 Then strArch = "x64"
                                        Next
 
                                        strHTML =  strHTML &"<tr><td width='40%' border=1>" & strComputer &_
                                        	"</td><td bgcolor='green'><font color='white'>" &strArch & "</font><br>"
                                	
							If strArch = "x86" then iArch1=iArch1+1
								Elseif strArch = "MIPS" then iArch2=iArch2+1
								Elseif strArch = "Alpha" then iArch3=iArch3+1
								Elseif strArch = "PowerPC" then iArch4=iArch4+1
								Elseif strArch = "x64" then iArch5=iArch5+1
							Else
								iArchU=iArchU+1
							End If
 
                                Else
							iUnreach = iUnreach + 1
                                        	strHTML =  strHTML &"<tr><td width='40%'>"& strComputer & "</td><td bgcolor='red'><font color='white'>Unreachable</font></td></tr><br>"
                                End If
                        Loop
			strHTML2 =  strHTML2 &"<tr><td width='80%' border=1>x86"&_
                         	"</td><td>" &iArch1 & "<br>"&_
				"<tr><td width='80%' border=1>MIPS"&_
                         	"</td><td>" &iArch2 & "<br>"&_
				"<tr><td width='80%' border=1>Alpha"&_
                         	"</td><td>" &iArch3 & "<br>"&_
				"<tr><td width='80%' border=1>PowerPC"&_
                         	"</td><td>" &iArch4 & "<br>"&_
				"<tr><td width='80%' border=1>x64"&_
                         	"</td><td>" &iArch5 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
                         	"</td><td>" &iArchU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
                         	"</td><td>" &iUnreach & "<br>"&_
                        List.Close      
                        Totals.InnerHTML = strHTML2 &"</table>"
                        Results.InnerHTML =  strHTML &"</table>"
                Else
                        MsgBox "File does not exist: " & ComputerListFile.Value
                End If
        Else
                MsgBox "Please specify a file name."
        End If
        run_button.disabled = False
        ComputerListFile.disabled = False
 
End Sub
        
Function Ping(strComputer)
        Dim objShell, boolCode
        Set objShell = CreateObject("WScript.Shell")
        boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
        If boolCode = 0 Then
                Ping = True
        Else
                Ping = False
        End If
End Function
 
</script>
 
<body>
<input type="button" value="Run Script" name="run_button" onClick="GetInfo">
<input type="file" name="ComputerListFile"> <br><br>
<span id = "Totals"></span><br><br>
<span id = "Results"></span>
</body>
</html>

Open in new window

0
Comment
Question by:Simon336697
[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
2 Comments
 
LVL 10

Accepted Solution

by:
TakedaT earned 500 total points
ID: 24322913
Here you go Simon.  Your IF statement from line 89 to 96 was syntaxed wrong.  When you continue an If statement after the "then" on the same line, that terminates the statement.  The elseif's had the same problem.  All I did was add the carriage returns after the thens.

I also changed the title of the second column to "Processor type" instead of "Service Pack" as it looks like you changed what you wanted it to display.
<head>
<title>Enumerate System Information on Remote Computers</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Enumerate System Information"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
<style type="text/css">
 
html {
font-family:arial;
font-size:smaller;
 
}
 
table {
border-collapse:collapse;
border:solid 1px black;
font-family:arial;
font-size:0.8em;
}
 
tr, td, th {
border-collapse:collapse;
border-style:solid;
}
 
td { border-width: 1px; }
 
 
</style>
 
 
</head>
<script language="vbscript">
Sub Window_onLoad
	intWidth = 600
	intHeight = 480
	Me.ResizeTo intWidth, intHeight
	Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
End Sub
 
Sub GetInfo
        run_button.disabled = True
        ComputerListFile.disabled = True
        Const ForReading = 1
        Const ForWriting = 2
        Set objFSO = CreateObject("Scripting.FileSystemObject")
 
        If ComputerListFile.Value <> "" Then
                If objFSO.FileExists(ComputerListFile.Value) = True Then
                        Set List = objFSO.OpenTextFile(ComputerListFile.Value, ForReading)
                        
                        strHTML = "<table width='40%' border=1 bgcolor='white'>" &_
                        "<th style='background:c0c0c0'><b>System</b></th><th style='background:c0c0c0'><b>Processor Type</b>"
                        Results.InnerHTML = strHTML
 			strHTML2 = "<table width='40%' border=1>" &_
                        "<th colspan='2' style='background:c0c0c0'><b>Number of Servers with:</b>"
			Totals.InnerHTML = strHTML2
 
			iArch1 = 0
			iArch2 = 0
			iArch3 = 0
			iArch4 = 0
			iArch5 = 0
			iArchU = 0
			iUnreach = 0
                        Do Until List.AtEndOfStream
                                strComputer = List.ReadLine
                                If Ping(strComputer) Then
                                        Set objWMIService = GetObject("winmgmts:" _
                                        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
                				    Set colProcessors = objWMIService.ExecQuery _
                				    ("Select * From Win32_Processor")
                                        For Each objProcessor in colProcessors
							strArch = "Arch Unknown"
							If objProcessor.Architecture = 0 Then strArch = "x86"
							If objProcessor.Architecture = 1 Then strArch = "MIPS"
							If objProcessor.Architecture = 2 Then strArch = "Alpha"
							If objProcessor.Architecture = 3 Then strArch = "PowerPC"
							If objProcessor.Architecture = 9 Then strArch = "x64"
                                        Next
                                        strHTML =  strHTML &"<tr><td width='40%' border=1>" & strComputer &_
                                        	"</td><td bgcolor='green'><font color='white'>" &strArch & "</font><br>"
					If strArch = "x86" then
						iArch1=iArch1+1
					Elseif strArch = "MIPS" then
						iArch2=iArch2+1
					Elseif strArch = "Alpha" then
						iArch3=iArch3+1
					Elseif strArch = "PowerPC" then
						iArch4=iArch4+1
					Elseif strArch = "x64" then
						iArch5=iArch5+1
					Else
						iArchU=iArchU+1
					End If
                                Else
					iUnreach = iUnreach + 1
                                        strHTML =  strHTML &"<tr><td width='40%'>"& strComputer & "</td><td bgcolor='red'><font color='white'>Unreachable</font></td></tr><br>"
                                End If
                        Loop
			strHTML2 =  strHTML2 &"<tr><td width='80%' border=1>x86"&_
                         	"</td><td>" &iArch1 & "<br>"&_
				"<tr><td width='80%' border=1>MIPS"&_
                         	"</td><td>" &iArch2 & "<br>"&_
				"<tr><td width='80%' border=1>Alpha"&_
                         	"</td><td>" &iArch3 & "<br>"&_
				"<tr><td width='80%' border=1>PowerPC"&_
                         	"</td><td>" &iArch4 & "<br>"&_
				"<tr><td width='80%' border=1>x64"&_
                         	"</td><td>" &iArch5 & "<br>"&_
				"<tr><td width='80%' border=1>Unknown"&_
                         	"</td><td>" &iArchU & "<br>"&_
				"<tr><td width='80%' border=1>Unreachable"&_
                         	"</td><td>" &iUnreach & "<br>"&_
                        List.Close      
                        Totals.InnerHTML = strHTML2 &"</table>"
                        Results.InnerHTML =  strHTML &"</table>"
                Else
                        MsgBox "File does not exist: " & ComputerListFile.Value
                End If
        Else
                MsgBox "Please specify a file name."
        End If
        run_button.disabled = False
        ComputerListFile.disabled = False
 
End Sub
        
Function Ping(strComputer)
        Dim objShell, boolCode
        Set objShell = CreateObject("WScript.Shell")
        boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
        If boolCode = 0 Then
                Ping = True
        Else
                Ping = False
        End If
End Function
 
</script>
 
<body>
<input type="button" value="Run Script" name="run_button" onClick="GetInfo">
<input type="file" name="ComputerListFile"> <br><br>
<span id = "Totals"></span><br><br>
<span id = "Results"></span>
</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:Simon336697
ID: 24323009
Takeda,

I dont know how you do it, but you do, and you do it incredibly well.
Thank you again mate.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 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