Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

My Do...Loop statement returns "'loop' without 'do'" error

Posted on 2009-04-15
5
Medium Priority
?
604 Views
Last Modified: 2012-05-06
I do not know why I get the following error message from my vbscript:
Microsoft VBScript compilation error: 'loop' without 'do': Loop

An excerpt from my code is below.
Thanks.
Const ForWriting = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
strFile = "UserList.txt"
strCSV = "UsersCreated.csv"
SSARF = "111111"
Set objFile = objFSO.OpenTextFile("C:\MyScripts\Script IO\Divestiture\Test\" & strFile, 1)
Set objOutFile = objFSO.CreateTextFile("C:\MyScripts\Script IO\Divestiture\Test\" & strCSV, ForWriting)
 
objOutFile.WriteLine """Full Name"",""First Name"",""MI"",""Last Name"",""EID"""
 
Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine
	If inStr(strLine, ",") Then
		strData = split(strLine, ",", -1, 1)
		strFName = strData(0)
		strLName = strData(1)
			If strData(2) = "" Then
				strFullName = strLName & ", " & strFName
				strCNName = strLName & "\, " & strFName
			Else If instr(strData(2), ".") Then
				strMIP = strData(2)
				strMI = replace(strMIP,",","")
				strFullName = strLName & ", " & strFName & " " & strMIP
				strCNName = strLName & "\, " & strFName & " " & strMIP
			Else
				strMIP = strData(2)
			End If
		strMEID = strData(3)
			If Left(strMEID, 4) = "Temp" Then
				strMEID = Right(strMEID, 4)
				strFEID = "MLT" & strMEID
			Else If Left(strMEID, 4) = "TEMP" Then
				strMEID = Right(strMEID, 4)
				strFEID = "MLT" & strMEID
			Else If Left(strMEID, 1) = "T" Then
				strMEID = Right(strMEID, 7)
				strFEID = "MLT" & strMEID
			Else If Left(strMEID, 1) = "C" Then
				strMEID = Right(strMEID, 7)
				strFEID = "MLC" & strMEID
			Else If Left(strMEID, 3) = "MLT" Then
				strFEID = strMEID
			Else If Left(strMEID, 1) = "W" Then
				strFEID = "ML" & strMEID
			Else If Left(strMEID, 1) = "H" Then
				strFEID = "ML" & strMEID
			Else
				strFEID = "ML" & strMEID
			End If
		strPwd = "Ftbco51!"
'		wscript.Echo strFullName & ", " & strMEID & ", " & strFEID
 
		On Error Goto 0
	
			strContainer = "ou=example,ou=Domain Users,"
			strDNSDomain = "dc=example,dc=ex,dc=com"
			Set objRootLDAP = GetObject("LDAP://example")
			Set objContainer = GetObject("LDAP://" & strContainer & strDNSDomain)
		
			' Build the actual User.
			Set objUser = objContainer.Create("User", "cn=" & strCNName)
			objUser.Put "sAMAccountName", strFEID
			objUser.Put "userPrincipalName", strFEID & "@ftbco.FTN.com"
			objUser.Put "givenName", strFName
			objUser.Put "SN", strLName
			objUser.Put "displayName", strFullName
			ObjUser.Put "info", "jp #" & SSARF & " New Access " & nowDate
			objUser.Put "userAccountControl", 544
			objUser.SetInfo
			objUser.SetPassword strPwd
			objUser.put "pwdLastSet", 0
				If strData(2) = strMI Then
					objUser.Put "initials", strMI
				Else If strData(2) = strMIP Then
					objUser.Put "initials", strMIP
				Else
					objUser.Put "initials", ""
				End If
			objUser.SetInfo
	
			objUser.Put "scriptPath", "ctxbranch.bat"
			objUser.TerminalServicesProfilePath = "\\ctxfs02\profiles\" & strFEID
			objUser.TerminalServicesHomeDrive = "U:"
			objUser.TerminalServicesHomeDirectory = "\\ctxfs01\users\" & strFEID
			objUser.SetInfo
			
				If strData(3) = strMIP Then	
					objOutFile.WriteLine """" & objUser.Get("displayName") & """,""" & objUser.Get("givenName") _
											  & """,""" & objUser.Get("initials") & """,""" & objUser.Get("SN") _
											  & """,""" & objUser.Get("sAMAccountName") & """"
				Else
					objOutFile.WriteLine """" & objUser.Get("displayName") & """,""" & objUser.Get("givenName") _
						  & """,""" & "" & """,""" & objUser.Get("SN") _
						  & """,""" & objUser.Get("sAMAccountName") & """"
			wscript.echo objUser.Get("displayName") & " (" & objUser.Get("sAMAccountName") _
						 & ") was created in the FTBCO domain."
	End If
Loop
 
objFile.Close
objOutFile.Close
MsgBox "Finished"
WScript.Quit

Open in new window

0
Comment
Question by:reason4xistence
5 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 24151455
Your problem is that your "Else If" statements should be "ElseIf".  Fix that, and I think your Do...Loop message
will disappear.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24151463
it must be ElseIf and not Else if ...
0
 

Author Comment

by:reason4xistence
ID: 24151562
I corrected the Else If to ElseIf (I had that problem before and figured it out, I don't know why I didn't remember), but I still get the same error message. Below is the full code.
'=========================================================================
' VBScript Source File -- Created with XLnow OnScript
'
' AUTHOR:  Joel Pace II 
' COMPANY: First Tennessee Bank N A
' DATE:    4/10/2009
' COMMENT: <comment>
'=========================================================================
 
On Error Resume Next
 
Function FormatYYYYMMDD(timeStamp)
Dim dateMonth : dateMonth = DatePart("M", timeStamp)
Dim dateDay : dateDay = DatePart("D", timeStamp)
Dim dateYear : dateYear = DatePart("YYYY", timeStamp)
Dim dateString
 
dateString = dateYear
 
	If dateMonth < 10 Then
		dateString = dateString & "0" & dateMonth
	Else
		dateString = dateString & dateMonth
	End If
	
	If dateDay < 10 Then
		dateString = dateString & "0" & dateDay
	Else
		dateString = dateString & dateDay
	End If
	
	FormatYYYYMMDD = dateString
End Function
 
' Get the current date and time.
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dateTime.SetVarDate Now
nowDate = FormatYYYYMMDD(dateTime.GetVarDate)
 
Const ForWriting = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
strFile = "UserList.txt"
strCSV = "UsersCreated.csv"
SSARF = "111111"
Set objFile = objFSO.OpenTextFile("C:\MyScripts\Script IO\Divestiture\Test\" & strFile, 1)
Set objOutFile = objFSO.CreateTextFile("C:\MyScripts\Script IO\Divestiture\Test\" & strCSV, ForWriting)
 
objOutFile.WriteLine """Full Name"",""First Name"",""MI"",""Last Name"",""EID"""
 
Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine
	If inStr(strLine, ",") Then
		strData = split(strLine, ",", -1, 1)
		strFName = strData(0)
		strLName = strData(1)
			If strData(2) = "" Then
				strFullName = strLName & ", " & strFName
				strCNName = strLName & "\, " & strFName
			ElseIf instr(strData(2), ".") Then
				strMIP = strData(2)
				strMI = replace(strMIP,",","")
				strFullName = strLName & ", " & strFName & " " & strMIP
				strCNName = strLName & "\, " & strFName & " " & strMIP
			Else
				strMIP = strData(2)
			End If
		strMEID = strData(3)
			If Left(strMEID, 4) = "Temp" Then
				strMEID = Right(strMEID, 4)
				strFEID = "MLT" & strMEID
			ElseIf Left(strMEID, 4) = "TEMP" Then
				strMEID = Right(strMEID, 4)
				strFEID = "MLT" & strMEID
			ElseIf Left(strMEID, 1) = "T" Then
				strMEID = Right(strMEID, 7)
				strFEID = "MLT" & strMEID
			ElseIf Left(strMEID, 1) = "C" Then
				strMEID = Right(strMEID, 7)
				strFEID = "MLC" & strMEID
			ElseIf Left(strMEID, 3) = "MLT" Then
				strFEID = strMEID
			ElseIf Left(strMEID, 1) = "W" Then
				strFEID = "ML" & strMEID
			ElseIf Left(strMEID, 1) = "H" Then
				strFEID = "ML" & strMEID
			Else
				strFEID = "ML" & strMEID
			End If
		strPwd = "Ftbco51!"
'		wscript.Echo strFullName & ", " & strMEID & ", " & strFEID
 
		On Error Goto 0
	
			strContainer = "ou=example,ou=Domain Users,"
			strDNSDomain = "dc=example,dc=ex,dc=com"
			Set objRootLDAP = GetObject("LDAP://example")
			Set objContainer = GetObject("LDAP://" & strContainer & strDNSDomain)
		
			' Build the actual User.
			Set objUser = objContainer.Create("User", "cn=" & strCNName)
			objUser.Put "sAMAccountName", strFEID
			objUser.Put "userPrincipalName", strFEID & "@ftbco.FTN.com"
			objUser.Put "givenName", strFName
			objUser.Put "SN", strLName
			objUser.Put "displayName", strFullName
			ObjUser.Put "info", "jp #" & SSARF & " New Access " & nowDate
			objUser.Put "userAccountControl", 544
			objUser.SetInfo
			objUser.SetPassword strPwd
			objUser.put "pwdLastSet", 0
				If strData(2) = strMI Then
					objUser.Put "initials", strMI
				ElseIf strData(2) = strMIP Then
					objUser.Put "initials", strMIP
				Else
					objUser.Put "initials", ""
				End If
			objUser.SetInfo
	
			objUser.Put "scriptPath", "ctxbranch.bat"
			objUser.TerminalServicesProfilePath = "\\ctxfs02\profiles\" & strFEID
			objUser.TerminalServicesHomeDrive = "U:"
			objUser.TerminalServicesHomeDirectory = "\\ctxfs01\users\" & strFEID
			objUser.SetInfo
			
				If strData(3) = strMIP Then	
					objOutFile.WriteLine """" & objUser.Get("displayName") & """,""" & objUser.Get("givenName") _
											  & """,""" & objUser.Get("initials") & """,""" & objUser.Get("SN") _
											  & """,""" & objUser.Get("sAMAccountName") & """"
				Else
					objOutFile.WriteLine """" & objUser.Get("displayName") & """,""" & objUser.Get("givenName") _
						  & """,""" & "" & """,""" & objUser.Get("SN") _
						  & """,""" & objUser.Get("sAMAccountName") & """"
			wscript.echo objUser.Get("displayName") & " (" & objUser.Get("sAMAccountName") _
						 & ") was created in the FTBCO domain."
	End If
Loop
 
objFile.Close
objOutFile.Close
MsgBox "Finished"
WScript.Quit

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24151592
Looks like you're missing an "End If" before line 138.
0
 

Author Closing Comment

by:reason4xistence
ID: 31570635
I missed that. Thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 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