Link to home
Start Free TrialLog in
Avatar of reason4xistence
reason4xistenceFlag for United States of America

asked on

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

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

Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Your problem is that your "Else If" statements should be "ElseIf".  Fix that, and I think your Do...Loop message
will disappear.
it must be ElseIf and not Else if ...
Avatar of reason4xistence

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I missed that. Thanks!