Solved

Object doesn't support this property or method: 'objFile.WriteLine'

Posted on 2013-11-10
7
1,717 Views
Last Modified: 2013-11-10
Hi,

I have a script that is supposed to get a remote file and write it locally but I get "Object doesn't support this property or method: 'objFile.WriteLine'" when I try to write.  I have this working on other scripts, but can't seem to figure why it is not working on this script.  Here is code:


    Set objFSO = CreateObject("Scripting.FileSystemObject")
   
    If objFSO.FileExists(getFile) Then
        Set objFile = objFSO.GetFile(getFile)
    Else
        Set objFile = objFSO.CreateTextFile(getFile)
    End If
   
    If objFile.Size > 0 Then
        ' Code to verify file
    Else
   
        strWriteFile = strCompleteFile 'Code from remote file

        Do While InStr(strWriteFile,Chr(10))

            theNewLine = InStr(strWriteFile,Chr(10))
            theLine = Left(strWriteFile,theNewLine-1)
            strWriteFile = Right(strWriteFile,Len(strWriteFile)-theNewLine)
   
            objFile.WriteLine theLine 'THIS IS WHERE IT FAILS

        Loop
   
        objFile.WriteLine strWriteFile
   
    End If      

Set objFSO = Nothing
Set objFile = Nothing
0
Comment
Question by:jayligda
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
Before  objFile.WriteLine theLine 'THIS IS WHERE IT FAILS add

response.write "theLine: "&theLine
response.wend
 objFile.WriteLine theLine 'THIS IS WHERE IT FAILS

Open in new window


Is there data?

try  objFile.WriteLine(theLine)
0
 

Author Comment

by:jayligda
Comment Utility
Yes, I could have mentioned I tested that already.  Here is the response line:

theLine: %CTF: 1.00

I should note that I now get the error:

Object doesn't support this property or method: 'wend'

I also did try objFile.WriteLine(theLine) as well to get the same results.

Thanks!

Jay
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
I'm sure padas meant "response.end" (instead of wend), just to stop the script at that point.

Your actual problem is caused by mixing different types of objects:
- GetFile returns a File object, which has amongst others a Size property, so you need that when checking for Size > 0
- CreateTextFile returns a TextStream object, which you need to be able to use WriteLine for example.

I would suggest to change the code as follows:
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    intFileSize = 0 ' default for when the file doesn't exist and will be created (with size 0)

    If objFSO.FileExists(getFile) Then
        Set objFile = objFSO.GetFile(getFile)
        intFileSize = objFile.Size
        ' when the file exists with size 0, the code below will start writing to it...
        ' you may have assumed this will never happen but it is better to check for it
        If intFileSize = 0 Then
            Set objFile = objFile.OpenAsTextStream(8) ' ForAppending
        Else
            ' guessing that in the verify bit you will be reading the file?
            Set objFile = objFile.OpenAsTextStream(1) ' ForReading
        End If
    Else
        Set objFile = objFSO.CreateTextFile(getFile)
    End If

    If intFileSize > 0 Then
        ' Code to verify file
    Else

        strWriteFile = strCompleteFile 'Code from remote file

        Do While InStr(strWriteFile,Chr(10))

            theNewLine = InStr(strWriteFile,Chr(10))
            theLine = Left(strWriteFile,theNewLine-1)
            strWriteFile = Right(strWriteFile,Len(strWriteFile)-theNewLine)

            objFile.WriteLine theLine

        Loop

        objFile.WriteLine strWriteFile

        objFile.Close ' always a good idea to close the file

    End If

Set objFSO = Nothing
Set objFile = Nothing

Open in new window

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:jayligda
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for jayligda's comment #a39637240

for the following reason:

Yep, that did it.  I have my file(s)!  Thanks!
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
That seems like a positive response but are you aware you have selected your own comment as a solution?

EDIT: well, not anymore ;-) thanks!
0
 

Author Comment

by:jayligda
Comment Utility
I thought something weird was going on ;-).  I think I changed it now.
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
Yep, thanks again!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now