[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1897
  • Last Modified:

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

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
jayligda
Asked:
jayligda
  • 3
  • 3
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
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
 
jayligdaAuthor Commented:
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
 
Robert SchuttSoftware EngineerCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
jayligdaAuthor Commented:
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
 
Robert SchuttSoftware EngineerCommented:
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
 
jayligdaAuthor Commented:
I thought something weird was going on ;-).  I think I changed it now.
0
 
Robert SchuttSoftware EngineerCommented:
Yep, thanks again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now