|
-
Feb 23rd, 2012, 05:43 AM
#1
Thread Starter
New Member
expected end of statement error
Hi,
I dont understand this Microsoft VBScript compilation error "expected end of statement line 41, char 131"
'On Error Resume Next
Dim arrFileLines()
'Dim arrMembers()
Set objFSO = CreateObject("Scripting.FileSystemObject")
'objWorkbook.SaveAs(strFileName)
'objExcel.Visible = True
'set objWorkbook = objExcel.Workbooks.Open(strFileName)
'set objWorksheet = objWorkbook.Worksheets(1)
'objExcel.DisplayAlerts = False
FileLocation = ".\"
ADGROUP = "extracted_data"
Const ForAppending = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set GpFile = objFSO.CreateTextFile(FileLocation & "Gp.txt", ForAppending, True)
'Set objFile = objFSO.OpenTextFile(FileLocation & "Gp.txt", 1)
Set UserFile = objFSO.CreateTextFile(FileLocation & ADGROUP & ".txt", ForAppending, True)
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT displayname, name, st, wwwhomepage, description FROM 'LDAP://ou=nuh,dc=nhg,dc=local' WHERE objectClass='Person' and userAccountControl <> 514"
Set objRecordSet = objCommand.Execute
'Wscript.Echo objCommand.CommandText
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
UserFile.WriteLine objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("name").Value & ";" & UserFile.WriteLine objRecordSet.Fields("st").Value & ";" & UserFile.WriteLine objRecordSet.Fields("wwwhomepage").Value & ";" & UserFile.WriteLine objRecordSet.Fields("description").Value
objRecordSet.MoveNext
Loop
'GpFile.Close
UserFile.Close
Wscript.Echo "Done"
-
Feb 23rd, 2012, 05:59 AM
#2
Re: expected end of statement error
The method UserFile.WriteLine seems not a function and it doesn't return a value, therefore you cannot use the & operator with it. Try to replace the line 41 with
vb Code:
UserFile.WriteLine objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("name").Value & ";" UserFile.WriteLine objRecordSet.Fields("st").Value & ";" UserFile.WriteLine objRecordSet.Fields("wwwhomepage").Value & ";" UserFile.WriteLine objRecordSet.Fields("description").Value]
-
Feb 23rd, 2012, 08:48 AM
#3
Addicted Member
Re: expected end of statement error
Try:
Code:
UserFile.WriteLine objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("name").Value & ";" & objRecordSet.Fields("st").Value & ";" & objRecordSet.Fields("wwwhomepage").Value & ";" & objRecordSet.Fields("description").Value
-
Feb 24th, 2012, 10:58 AM
#4
Re: expected end of statement error
If you really want this to be on one line you can [or should be able to] use : to place what should be a new line on the same line. It has been years since I used this method but I would imagion it is still supported.
Code:
UserFile.WriteLine objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("name").Value & ";" : UserFile.WriteLine objRecordSet.Fields("st").Value & ";" : UserFile.WriteLine objRecordSet.Fields("wwwhomepage").Value & ";" : UserFile.WriteLine objRecordSet.Fields("description").Value
Your best bet is to go with the advice in post#2
-
Feb 27th, 2012, 06:02 PM
#5
Thread Starter
New Member
Re: expected end of statement error
Thanks Folks. I guess the script is not working from my windows 7. I'm able to run the script from a windows 2000 server.
Thanks for your help!!
-
Feb 27th, 2012, 06:18 PM
#6
Re: expected end of statement error
On windows 7 some folders are protected against write. This may be why you have gotten it to work under windows 2000 but fail on 7.
Where is the file located that you are trying to write to?
-
Feb 27th, 2012, 06:38 PM
#7
Thread Starter
New Member
Re: expected end of statement error
 Originally Posted by DataMiser
On windows 7 some folders are protected against write. This may be why you have gotten it to work under windows 2000 but fail on 7.
Where is the file located that you are trying to write to?
Its located on my desktop
-
Feb 27th, 2012, 07:23 PM
#8
Re: expected end of statement error
hmm not sure about that path in windows 7. I have never written a program that used files on my desktop. I know program files is restricted and system folders are restricted in Windows 7. Not sure about the desktop.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|