Solved

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

Posted on 2013-11-10
7
1,762 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
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

856 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