Solved

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

Posted on 2013-11-10
7
1,809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39637220
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
ID: 39637240
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
ID: 39637397
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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 

Author Comment

by:jayligda
ID: 39637466
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
ID: 39637443
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
ID: 39637467
I thought something weird was going on ;-).  I think I changed it now.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39637468
Yep, thanks again!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

690 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