Solved

Expected Loop error

Posted on 2009-05-06
2
230 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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