Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Script, Variable not defined error 1

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
This script reads a list of hostnames from a text file, checks for a file on the remote PC and depending on if it exists or not copies a file down to them. It works fine on the first hostname it reads in, then I get this error and the script stops running (the line in red is the line giving the error):

Script: test.vbs
Line: 6
Char: 1
Error: Object Variable not set
Code: 800A005B
Source: Microsoft VBScript runtime error


Const OverwriteExisting = True
Const ForReading = 1
Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\batch\list1.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
HostName = Split(strNextLine , ",")
strHostName = HostName(0) & "\c$\Program Files\Lincare, Inc\O2Sales\O2SalesLive.mde"
strFileInUse = HostName(0) & "\c$\Program Files\Lincare, Inc\O2Sales\O2SalesLive.ldb"
If objFSO.FileExists(strFileInUse) Then
Set objTextFile = objFSO.OpenTextFile ("\\********\common\it_department\O2 Sales\ForcedUpdates\ForcedUpdate.txt", ForAppending, True)
objTextFile.WriteLine("File NOT Updated on " & HostName(0) & " at " & Time & " on " & Date)
objTextFile.Close
MsgBox "File has NOT been Updated on " & HostName(0),vbokonly,"Not Copied"
Else
objFSO.CopyFile "\\********\accessdb\o2sales\database\O2SalesLive.mde" , strHostName, OverwriteExisting
Set objTextFile = objFSO.OpenTextFile ("\\********\common\it_department\O2 Sales\ForcedUpdates\ForcedUpdate.txt", ForAppending, True)
objTextFile.WriteLine("File UPDATED on " & HostName(0) & " at " & Time & " on " & Date)
objTextFile.Close
MsgBox "File HAS been Updated on " & HostName(0),vbokonly,"Copied"
End If
Loop

I'm using Primalscript to write this if that makes a difference. Thanks in advance for any help on this.
 
This code seems correct to me. The only possible causes I can see for this error are :
- c:\batch\list1.txt doesn't exist or
- you set "option explicit" and forgot to declare a variable.
Water is not bad as long as it stays out human body ;-)
 
I see you have re assigned objTextFile using the Set objTextFile = opentextfile forreading.

try doing

objTextFile.Close
Set objTextFile = Nothing


and then do your

set objTextFile = objFSO.OpenTextFile,,,forreading
 
Yes MrMovie !!! I must be a little tired not to have seen this. A Star for you. Water is not bad as long as it stays out human body ;-)
 
Alternatively, and probably easier. Have a different name for your file you are reading.

Set objReadIni =

then

Set objLogFile =
 
Changing the name of one of my objTextFile to objHostNameText fixed my issue. I was closing the object and never re-opening it to read the next host name. Thanks for your posts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top