?
Solved

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

Posted on 2013-11-10
7
Medium Priority
?
1,834 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 2000 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
What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

 

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

Independent Software Vendors: 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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 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