Results 1 to 8 of 8

Thread: expected end of statement error

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    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"

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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:
    1. UserFile.WriteLine objRecordSet.Fields("displayName").Value & ";" & objRecordSet.Fields("name").Value & ";"
    2. UserFile.WriteLine objRecordSet.Fields("st").Value & ";"
    3. UserFile.WriteLine objRecordSet.Fields("wwwhomepage").Value & ";"
    4. UserFile.WriteLine objRecordSet.Fields("description").Value]



  3. #3
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    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

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    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!!

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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?

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: expected end of statement error

    Quote Originally Posted by DataMiser View Post
    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

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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
  •  



Click Here to Expand Forum to Full Width