Need vb help to determine if a file doesn't exist

I have code from http://www.myitforum.com/articles/21/view.asp?id=9633 that I am tweaking a specific subroutine to create a .txt file of some of the output.

My vb  is pretty much nonexistent.

When the script runs through the subroutine 'GetDefInfo' I want it to track in the .txt file the status of machines.   Currently it all works but does not track machines that are offline.   The subroutine looks for a specific file on a foreign computer and reads it to find info that is recorded.

I have attempted to add code that will write to my .txt file when the specific file does not exist, with some canned information.  This isn't working, and I'm sure it's because my syntax isn't good for checking for the non-existence of the file.

The code sample below shows the full code from the site I reference above, with my tweaks.  At the very bottom is the section that I am trying to get to work.
'Entire Code:
'------
On Error Resume Next

Const ForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002
x = 2

'Create an Excel Work Sheet

Set objExcel = CreateObject("Excel.Application")
'objExcel.Visible = True
objExcel.Visible = False
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Parent Server"
objExcel.Cells(1, 3).Value = "SAV Version"
objExcel.Cells(1, 4).Value = "Definition Date"
objExcel.Cells(1, 5).Value = "Rev"
objExcel.Cells(1, 6).Value = "Status"
objExcel.Cells(1, 7).Value = "Report Time Stamp"

objExcel.Range("A1:G1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

objExcel.ActiveWorkBook.SaveAs "C:\jobs\Sysadmin\SAVUpdates\SavStatus.xls"

' Create a txt file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\jobs\Sysadmin\SAVUpdates\SavStatus.txt")

'Read machine names from a txt file


Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("SAVVerCheck.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

intRow = x

objExcel.Cells(intRow, 1).Value = strComputer

GetRegInfo

GetDefInfo

objExcel.Cells(intRow, 7).Value = Now() 

set strValue = Nothing
set dwValue = Nothing
set strSavVersion = Nothing
set objFSO = Nothing3
Set objFile = Nothing
Set dtDefDate = Nothing
Set strRevNumber= Nothing
Set strAlert= Nothing

x = x + 1

Loop

'Wscript.Echo "Done"
objExcel.DisplayAlerts = False
objExcel.ActiveWorkBook.SaveAs "C:\jobs\Sysadmin\SAVUpdates\SavStatus.xls"
objExcel.Quit

'*********************************************************************************************************
'Get information from Registry

Sub GetRegInfo

Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\INTEL\LANDesk\VirusProtect6\CurrentVersion"
strParent = "Parent"
strProversion = "ProductVersion"

oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strParent,strValue

objExcel.Cells(intRow, 2).Value = strValue

oReg.GetDWORDValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strProversion,dwValue

Select Case dwValue

Case 393217016
strSavVersion ="10.1.6.6000"

Case 328336375
strSavVersion ="10.1.5.5010"

Case 23528424
strSavVersion = "10.0.0.359"

Case 65537001
strSavVersion = "10.0.1.1000"

Case 65995753
strSavVersion = "10.0.1.1007"

Case 66061289
strSavVersion = "10.0.1.1008"

Case 131073002
strSavVersion = "10.0.2.2000"

Case 131138538
strSavVersion = "10.0.2.2001"

Case 131728362
strSavVersion = "10.0.2.2010"

Case 132383722
strSavVersion = "10.0.2.2020"

Case 132449258
strSavVersion = "10.0.2.2021"

Case 25822194
strSavVersion = "10.1.0.394"

Case 25953266
strSavVersion = "10.1.0.396"

Case 26215410
strSavVersion = "10.1.0.400"

Case 26280946
strSavVersion = "10.1.0.401"

Case 65536905
strSavVersion = "9.0.5.1000"

Case 72090503
strSavVersion = "9.0.3.1100"

Case 65536903
strSavVersion = "9.0.3.1000"

Case 65536902
strSavVersion = "9.0.2.1000"

Case 65536901
strSavVersion = "9.0.1.1000"

Case 22152068
StrSavversion = "9.0.0.338"

Case 21562155
strSavVersion = "8.1.1.329"

Case 21168939
strSavVersion = "8.1.1.323"

Case 20906795
strSavVersion = "8.1.1.319"

Case 20579115
strSavVersion = "8.1.1.314"

Case 54068001
strSavVersion = "8.1.0.825"

Case 29950753
strSavVersion = "8.0.1.457"

Case 614597408
strSavVersion = "8.0.0.9378"

Case 614335264
strSavVersion = "8.0.0.9374"

Case 29229856
strSavVersion = "8.0.0.446"

Case 28640032
strSavVersion = "8.0.0.437"

Case 28443424
strSavVersion = "8.0.0.434"

Case 28115744
strSavVersion = "8.0.0.429"

Case 27853600
strSavVersion = "8.0.0.425"

Case 85197700
strSavVersion = "7.60.926"

Case 61997817
strSavVersion = "7.6.1.946"

Case 61473529
strSavVersion = "7.6.1.938"

Case 60949241
strSavVersion = "7.6.1.930"

Case 60687096
strSavVersion = "7.6.1.926"

Case 55509743
strSavVersion = "7.5.1.847"

Case 48366268
strSavVersion = "7.0.0"

End Select

objExcel.Cells(intRow, 3).Value = strSavVersion
objExcel.Cells(intRow, 8).Value = dwValue

End Sub

'*******************************************************************************************************************
'Get Virus definition from definfo.dat.

Sub GetDefInfo

objExcel.Cells(intRow, 4).Value = "The file definfo.dat does not exist"

Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check for w2003 or w2008 path
if objFSO.FileExists("\\" & strComputer & _
  "\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat") Then 
 'W2003 Path
  Set objFile = objFSO.GetFile("\\" & strComputer & _
  "\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat")
Else
 ' W2008 path
 Set objFile = objFSO.GetFile("\\" & strComputer & _
  "\c$\ProgramData\Symantec\Definitions\VirusDefs\definfo.dat")
  End if
 
objExcel.Cells(intRow, 9).Value = objFile
 
 Set objDatFile = objFSO.OpenTextFile(objFile, 1)
 if not objFile.FileExists Then
   Wscript.Echo intRow & vbTab & strComputer & vbTab & "Not Online!"
   Set objTextFile = objFSO.OpenTextFile ("C:\jobs\Sysadmin\SAVUpdates\SavStatus.txt", 8, True)
   objTextFile.WriteLine ( intRow & vbTab & strComputer & vbTab & "Not Online!" )
   objTextFile.Close
  End if
 Do Until objDatFile.AtEndOfStream
 strLine = objDatFile.Readline
 intCurDefs = InStr(strLine , "CurDefs")
   If intCurDefs > 0 Then
   strCurDefs = strLine 
   strDateDefs = Mid(strCurDefs, 9, 8)
   dtYear = Left(strDateDefs, 4)
   dtMonth = Mid(strDateDefs, 5, 2)
   dtDay = Right(strDateDefs, 2)
   DateVirDefs = dtMonth & "/" & dtDay & "/" & dtYear
   dtDefDate = CDate(DatevirDefs)
   objExcel.Cells(intRow, 4).Value = dtDefDate
    If (date - dtDefDate) < 2 Then
     objExcel.Cells(intRow, 6).Value = "OK!"
	 strAlert="OK!"
    Else 
     objExcel.Cells(intRow, 6).Value = "ALERT!"
     objExcel.Cells(intRow, 6).Font.ColorIndex = 3
	 strAlert="ALERT!"
    End If
   strRevNumber = Right(strCurDefs, 3)
   objExcel.Cells(intRow, 5).Value = strRevNumber
   
   'Output to plain text file
   'Wscript.Echo strComputer & vbTab & dtDefDate & vbTab & strAlert
   Set objTextFile = objFSO.OpenTextFile ("C:\jobs\Sysadmin\SAVUpdates\SavStatus.txt", 8, True)
   objTextFile.WriteLine ( intRow & vbTab & strComputer & vbTab & dtDefDate & vbTab & strAlert )
   objTextFile.Close
  End If
  Loop
  objDatFile.Close
  
   'Output to plain text file
   Wscript.Echo intRow & vbTab & strComputer & vbTab & dtDefDate & vbTab & strAlert
   Set objTextFile = objFSO.OpenTextFile ("C:\jobs\Sysadmin\SAVUpdates\SavStatus.txt", 8, True)
   objTextFile.WriteLine ( intRow & vbTab & strComputer & vbTab & dtDefDate & vbTab & strAlert )
   objTextFile.Close

'End If

'---------
'Specific code that I am trying to get to work:
if not objFile.FileExists Then
   Wscript.Echo intRow & vbTab & strComputer & vbTab & "Not Online!"
   Set objTextFile = objFSO.OpenTextFile ("C:\jobs\Sysadmin\SAVUpdates\SavStatus.txt", 8, True)
   objTextFile.WriteLine ( intRow & vbTab & strComputer & vbTab & "Not Online!" )
   objTextFile.Close
  End if

Open in new window

LVL 1
nummagumma2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel WilsonCommented:
you really need to be using objFSO.FileExists.

objFSO.GetFile will throw an error if the file doesn't exist ... so objFile is, in that case unitialized.

http://msdn.microsoft.com/en-us/library/sheydkke(v=VS.85).aspx

Please try:

Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check for w2003 or w2008 path
if objFSO.FileExists("\\" & strComputer & _
  "\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat") Then 
 'W2003 Path
  Set objFile = objFSO.GetFile("\\" & strComputer & _
  "\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat")
Else if objFSO.FileExists("\\" & strComputer & _
  "\c$\ProgramData\Symantec\Definitions\VirusDefs\definfo.dat")
 ' W2008 path
 Set objFile = objFSO.GetFile("\\" & strComputer & _
  "\c$\ProgramData\Symantec\Definitions\VirusDefs\definfo.dat")
Else
'Your error/complaint code here
  End if

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IPTNCommented:
Did you first set objfile to the file that you want to check to see if it exists? you must do this before checking to see if file exists and you need to place it in the code where it won't get set to something else before you run the bit at the end there.
0
Daniel WilsonCommented:
Also, during development, get rid of ON ERROR RESUME NEXT.  It's hiding the errors from you.  You may want it on in production, but not in development.
0
nummagumma2Author Commented:
Daniel - worked perfectly, thank yoU!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.