Solved

Expected Loop error

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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