Question

VBSCRIPT: "Input past EOF" error

Asked by: mbritojr

This is a script from www.windowsITpro.com http://www.windowsitpro.com/Article/ArticleID/39111/39111.html that worked for a while and worked great but now has started failing. It has never been modified. I don't know what the problem is. It fails at random points in the file processing with the following error:

Script: \\server\share\buildreport.vbs
Line: 278
Char: 5
Error: Input past end of file
Code: 800A003E
Source: Microsoft VB Script Runtime Error

Line 278 is starred...

I can provide examples of the files being proccessed if needed. I normally wouldn't ask a question this broad or post code like this but I really am at a total loss... Thanks for any help...

**********************START CODE*******************

'Constants used in this script
Const ForReading = 1
Const xlNormal = &HFFFFEFD1
Const xlWBATWorksheet = &HFFFFEFB9
Const xlRight = &HFFFFEFC8
Const xlOtherSessionChanges = 2

'Initialize global variables
strInvFilePath = "\\server\share\profiles\"
strReportPath = "\\server\share\report\"

'New sheet names. This is outside of a specific sub-routine
'because multiple subroutines use it.
arrWBNames = Array("Computer Systems","Page Files","RAM", _
  "SCSI Controllers","IDE Controllers","Disk SerNums", _
  "Removable Media","Fixed Disks","Processors", _
  "NICs","Monitors","Video Adapters","MotherBoards", _
  "BIOS")

'Creat Excel workbook globally because it's used by several routines
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Add  'new
Call PrepareWorkSheet

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(strInvFilePath)
Set objFiles = objFolder.Files

'intRowPosition = 2 'Inventory data begins to be written to row 2 of each worksheet
For Each File in objFiles
  If Mid(File.Name,1,9) = "HrdWrInv_" Then
    strFileName = File.Name
    'Use the value of computer name for the first instance of each row of data.
    strComputerName = Mid(strFileName,10,(Instr(strFileName,".") - 10))
    WScript.Echo "Processing inventory for " & strComputerName
    Set objTextFile = objFSO.OpenTextFile(strInvFilePath & strFileName,ForReading)
   
    'Using a sepearate text file object because you don't want to put the
    'cursor at the end of the file and the readall method will do this
    'and then you can't use readline, etc. to move through the file's contents.
    Set objFileForSearching = objFSO.OpenTextFile(strInvFilePath & strFileName,ForReading)
    'read the file and use this for determining if a particular section head is
    'found anywhere in the file.
    strTextFile = objFileForSearching.ReadAll
   
    arrItems = Array("SkipLine","SkipLine","Caption","Version")
    Call GenReport("OSInformation:",strTextFile, _
      "CreationClassName: Win32_OperatingSystem",arrItems)
    arrItems = Array("SkipLine","Manufacturer","Model", _
     "SkipLine","NumberOfProcessors","SystemType","TotalPhysicalMemory")
    Call GenReport("ComputerSystem:",strTextFile, _
      "CreationClassName: Win32_ComputerSystem",arrItems)
    arrItems = Array("MaximumSize","Name")
    Call GenReport("PageFileSetting:",strTextFile, _
      "MaximumSize:",arrItems)
    arrItems = Array("SkipLine","MaxCapacity","Tag")
    Call GenReport("PhysicalMemoryArray:",strTextFile, _
      "CreationClassName: Win32_PhysicalMemoryArray",arrItems)
    arrItems = Array("SkipLine","Description","SkipLine","Manufacturer","Name")
    Call GenReport("SCSIController:",strTextFile, _
      "CreationClassName: Win32_SCSIController",arrItems)
    arrItems = Array("SkipLine","Description","SkipLine","Manufacturer","Name")
    Call GenReport("IDEController:",strTextFile, _
      "CreationClassName: Win32_IDEController",arrItems)
    arrItems = Array("SkipLine","SerialNumber","SkipLine")
    Call GenReport("PhysicalMedia:",strTextFile, _
      "CreationClassName: Not available",arrItems)
    arrItems = Array("SkipLine","Description","DeviceID","SkipLine")
    Call GenReport("LogicalDisk:",strTextFile, _
      "CreationClassName: Win32_LogicalDisk",arrItems)
    arrItems = Array("Caption","SkipLine","Description","SkipLine", _
      "InterfaceType","Manufacturer","MediaType","Model","Partitions", _
      "Size")
    Call GenReport("DiskDrive:",strTextFile, _
      "CreationClassName: Win32_DiskDrive",arrItems)
    arrItems = Array("SkipLine","DeviceID","ExtClock","Manufacturer", _
      "MaxClockSpeed","SkipLine","Revision","Version")
    Call GenReport("Processor:",strTextFile, _
      "CreationClassName: Win32_Processor",arrItems)
    arrItems = Array("AdapterType","SkipLine","SkipLine", _
      "MACAddress","Manufacturer","ProductName")
    Call GenReport("NetworkAdapter:",strTextFile, _
      "CreationClassName: Win32_NetworkAdapter",arrItems)
    arrItems = Array("SkipLine","Description","SkipLine","MonitorType")
    Call GenReport("DesktopMonitor:",strTextFile, _
      "CreationClassName: Win32_DesktopMonitor",arrItems)
    arrItems = Array("AdapterRAM","SkipLine","SkipLine", _
      "MaxRefreshRate","Name")
    Call GenReport("VideoController:",strTextFile, _
      "CreationClassName: Win32_VideoController",arrItems)
    arrItems = Array("SkipLine","Description","Manufacturer", _
      "Product","SkipLine")
    Call GenReport("BaseBoard:",strTextFile, _
      "CreationClassName: Win32_BaseBoard",arrItems)
    arrItems = Array("Manufacturer","Name","SMBIOSBIOSVersion", _
      "SMBIOSMajorVersion","SMBIOSMinorVersion","SoftwareElementID", _
      "SkipLine","SkipLine","Version")
    Call GenReport("BIOS:",strTextFile, _
      "SoftwareElementID",arrItems)
 End If 'End reading inventory file
Next
objWorkBook.Save
objWorkBook.Sheets("Computer Systems").Select        
objExcel.Visible = True

'*****Subroutines and Functions*********
Sub GenReport(SectionHead,TextFile,UniqueLabel,ReportItemsArray)
  Call MoveToSectionHead(SectionHead,TextFile)
  intInstances = FindValues(UniqueLabel,TextFile)
  If intInstances > 0 Then
    For i = 1 to intInstances
      'Determine the next available row in the current worksheet
      intRow = NextRowCount(SectionHead)
      'Move over to the fourth column if the SectionHead is "ComputerSystem:"
      'because this sheet first gets 3 cols of data from the OSInformation section.
      If SectionHead = "ComputerSystem:" Then
        intColPosition = 4
      Else    
        intColPosition = 2
      End If
      For Each Item in ReportItemsArray
        If item = "SkipLine" Then
          'Doing this because you don't want to advance to the next
          'column for a skipped line.
          intColPosition = intColPosition - 1
          objTextFile.SkipLine
        Else
          strItem = ReadVal(Item)
          If strItem = " " Then
            strItem = "Not Listed"
          End If
          Call InsertValues(SectionHead,intRow,intColPosition,strItem,i)
        End If
        intColPosition = intColPosition + 1
      Next
      objTextFile.SkipLine
    Next
  End If
End Sub

'Select the worksheet based on the section of data being read
Function SelectWorkSheet(SectionHead)
  arrSectionNames = Array("OSInformation:ComputerSystem:", _
   "PageFileSetting:","PhysicalMemoryArray:","SCSIController:", _
   "IDEController:","PhysicalMedia:","LogicalDisk:","DiskDrive:", _
   "Processor:","NetworkAdapter:","DesktopMonitor:", _
   "VideoController:","BaseBoard:","BIOS:")
  If SectionHead = "OSInformation:" Or _
   SectionHead = "ComputerSystem:" Then
   SelectWorkSheet = 0
  Else
    i=0
    Do Until arrSectionNames(i) = SectionHead
      i=i + 1
    Loop
    SelectWorkSheet = i
  End If
End Function

Function NextRowCount(SectionHead)
  objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
  If SectionHead = "ComputerSystem:" Then
    NextRowCount = objExcel.ActiveSheet.UsedRange.Rows.Count
  Else
    NextRowCount = objExcel.ActiveSheet.UsedRange.Rows.Count + 1
  End If
End Function

'this is the routine that inserts values in the spreadsheet
Sub InsertValues(SectionHead,RowPosition,ColPosition,Item,Instances)
  Select Case SectionHead
    Case "OSInformation:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
    Case "ComputerSystem:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:H1")
    Case "PageFileSetting:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:C1")
    Case "PhysicalMemoryArray:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:C1")
    Case "SCSIController:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:D1")
    Case "IDEController:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:D1")
    Case "PhysicalMedia:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:B1")
    Case "LogicalDisk:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:C1")
    Case "DiskDrive:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:I1")
    Case "Processor:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:G1")
    Case "NetworkAdapter:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:E1")    
    Case "DesktopMonitor:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:C1")
    Case "VideoController:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:D1")
    Case "BaseBoard:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:D1")
    Case "BIOS:"
      objWorkBook.Sheets(arrWBNames(SelectWorkSheet(SectionHead))).Select
      Call FillCells(ColPosition,RowPosition,Item,Instances)
      Call FormatWorkSheet("A1:H1")                  
  End Select
End Sub

Sub FillCells(ColPosition,RowPosition,Item,Instances)
  'An instance value of 0 means there's nothing to write
  'the section exists in the text file but there's no data
  'in it.
  If Instances = 1 Then
    objExcel.Cells(RowPosition,1).Value = strComputerName
    objExcel.Cells(RowPosition,ColPosition).Value = Trim(Item)  
  ElseIf Instances > 1 Then
    objExcel.Cells(RowPosition,ColPosition).Value = Trim(Item)
  End If
End Sub

Sub MoveToSectionHead(HeadName,TextFile)
  Set objRegExp = New RegExp
  objRegExp.Pattern = HeadName 'Look for this value
  objRegExp.IgnoreCase = False 'Look for value w/specific case
  objRegExp.Global = False 'Find only the first match
  Set arrSectionHead = objRegExp.Execute(TextFile)
  If objRegExp.Test(TextFile) <> False Then
    strText = objTextFile.ReadLine
    objRegExp.Execute(strText)
    Do Until objRegExp.Test(strText) = True
      strText = objTextFile.ReadLine
      objRegExp.Execute(strText)
    Loop
  End  If
End Sub

'This tells you how many values you have in a section of hardware inventory
'data. Knowing this then tells you what you have to read from the section.
Function FindValues(Label,TextFile)
  Set objRegExp2 = New RegExp
  objRegExp2.Pattern = Label 'Look for this value
  objRegExp2.IgnoreCase = False 'Look for value w/specific case
  objRegExp2.Global = True 'Find all matches in this section
  Set arrValues = objRegExp2.Execute(TextFile)
  i = 0
  For Each Value in arrValues
    i = i + 1
  Next
  FindValues = i
End Function

Function ReadVal(Label)
'*****************************LINE 278**********************************
    ReadVal = Mid(objTextFile.ReadLine,Len(Label) + 3)
'*****************************LINE 278**********************************
End Function

Sub PrepareWorkSheet()
  objWorkBook.SaveAs strReportPath & "InvReport.xls",xlNormal
  objExcel.SheetsInNewWorkBook = 14
  'Ensure that the worksheet has enough sheets to run
  'correctly. If not, use the Add method to add worksheets.
  If objWorkBook.Sheets.Count < 14 then
        For i = objWorkBook.Sheets.Count to 14
              objWorkBook.Sheets.Add()
        Next
  End if

   'iterate the array of new sheet names and rename the sheets
  i=1
  For Each WBName in arrWBNames
    RenameSheets "Sheet" & i,WBName
    i = i + 1
  Next
  'Column naming Section
  'Name the Computer Systems columns
  arrColumns = Array("Caption","Version","Manufacturer","Model", _
    "# Processors","System Type","RAM")
  Call NameColumns(0,arrColumns)
  'Name the Page Files columns
  arrColumns = Array("Maximum Size","Name")
  Call NameColumns(1,arrColumns)
  'Name the RAM columns  
  arrColumns = Array("Maximum Capacity","Tag")
  Call NameColumns(2,arrColumns)
  'Name the SCSI controllers columns
  arrColumns = Array("Description","Manufacturer","Name")
  Call NameColumns(3,arrColumns)
  'Name the IDE controllers columns
  arrColumns = Array("Description","Manufacturer","Name")
  Call NameColumns(4,arrColumns)
  'Name the Disk SerNums columns
  arrColumns = Array("Serial Number")
  Call NameColumns(5,arrColumns)
  'Have to do this because Excel interprets a serial
  'number (w/only numbers) as a numeric value rather
  'than a string and then
  'clips the value and uses and exponent designation
  objWorkbook.ActiveSheet.Columns("B:B").Select
  objExcel.Cells.EntireColumn.NumberFormat = "@"
  objExcel.Cells.HorizontalAlignment = xlRight
  objExcel.Range("A1").Select
  'Name the Removable Media columns
  arrColumns = Array("Descripton","Device ID")
  Call NameColumns(6,arrColumns)
  'Name the Fixed Disk columns
  arrcolumns = Array("Description","Device ID","Interface Type", _
    "Manufacturer","Media Type","Model","# of Partitions","Size")
  Call NameColumns(7,arrColumns)
  'Name the Processors columns
  arrColumns = Array("DeviceID","External Clock","Manufacturer", _
    "Maximum Speed","Revision","Version")
  Call NameColumns(8,arrColumns)
  'Name the NICs columns
  arrColumns = Array("Adapter Type","MAC Address", _
    "Manufacturer","Product Name")
  Call NameColumns(9,arrColumns)
  'Name the Monitors columns
  arrColumns = Array("Description","MonitorType")
  Call NameColumns(10,arrColumns)
  'Name the Video Adapters columns
  arrColumns = Array("Adapter Memory","Maximum Refresh Rate","Name")
  Call NameColumns(11,arrColumns)
  'Name the Motherboards columns
  arrColumns = Array("Description","Manufacturer","Product")
  Call NameColumns(12,arrColumns)
  'Name the BIOS columns
  arrColumns = Array("Manufacturer","Name","BIOS Version", _
    "Major Version","Minor Version","Software Element ID", _
    "Version")
  Call NameColumns(13,arrColumns)
  'objWorkBook.Sheets("Computer Systems").Select
  objWorkBook.Save
End Sub

Sub NameColumns(SheetNum,ColumnsArray)
  objWorkBook.Sheets(arrWBNames(SheetNum)).Select  
  i=2
  For Each ColumnHead in ColumnsArray
   'All sheets will have ComputerName as the first column name
   'so hard code it here.
   objExcel.Cells(1,1).Value = "Computer Name"
   objExcel.Cells(1,i).Value = ColumnHead
   i = i + 1
  Next
End Sub
       
'Rename each sheet
Sub RenameSheets(CurrentName,NewName)
  objWorkBook.Sheets(CurrentName).Select
  objWorkbook.ActiveSheet.Name = NewName
End Sub        
 
'This is for formatting each worksheet.
Sub FormatWorkSheet(HeadCellRange)
  objExcel.Range(HeadCellRange).Font.Bold = True
  objExcel.Cells.EntireColumn.AutoFit
  objExcel.Cells.EntireRow.AutoFit
End Sub

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-04-26 at 07:47:52ID21828171
Tags

vbscript

,

past

,

end

,

file

,

eof

Topic

Programming Languages

Participating Experts
2
Points
500
Comments
3

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. For every worksheet in the workbook, select cell a1
    I have a workbook with multiple worksheets and chart sheets. I have a clean up routine that does some formatting. I'd like to end it with each worksheets a1 cell selected.
  2. Open worksheet in cell A1
    Hi! This should be easy for u!! How do I get Excel to always open a worksheet in cell A1 when I click on the worksheet tab? Regards, EricM
  3. Create Worksheet from Spreadsheet?
    Hi Let me explain. I have an app that allows me to export to Excel 4 XLS spreadsheet file. I would like to take several of these and make them into one Worksheet with multiple sheets - each sheet being one of the spreadsheet that I have created. Is there away to do this? I am...
  4. Jumping to cell A1 of another worksheet.
    I just did saving the workbook, Id like to jump to worksheet 'B' cell A1. How to code that in VBA....
  5. Resetting all the sheets in a workbook to A1
    I want to be able to reset the sheets in a workbook so they are all lined up the same way before they go out. The sub below works of course, but how do I do it with less code, and no or very little selecting? Thanks, John Sub ResetSheets() Sheets("Multifamily"...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: TazDev00Posted on 2006-04-26 at 12:35:22ID: 16547373

If objTextFile.AtEndOfStream = False Then
ReadVal = Mid(objTextFile.ReadLine,Len(Label) + 3)
Else
    '  At the end of file
    ReadVal = " "
End If

 

by: TazDev00Posted on 2006-04-26 at 12:37:06ID: 16547392

Oops sorry, posted that accidentally.
Anyway, try replacing the ReadVal code with this.
It just checks for the end of the file before doing any further processing.
I leave it up to you to decide what to do if you're at the end of the file.

 

by: ADSaundersPosted on 2006-05-03 at 01:27:22ID: 16594217

Hi,
->    arrItems = Array("SkipLine","SkipLine","Caption","Version")
This is the sort of thing that can cause your problem. Here you are assuming that there are at least three remaining lines in the file at this point, two to be ignored, and one to be processed. If the file at this point does not contain at least three lines, then you will get the error you describe. Whenever i'm reading a file line by line (in VB or VBScript, using FSO or otherwise, I do just that, read it line by line, and check for EOF (or AtEndOfStream) for each line without assumptions. In my opinion, I would probably use ReadLine, and then either ignore it's contents or parse the input linestring:
LineString = objFile.Readline
SkipLines = 2
Do While Not objFile.AtEndOfStream
    SkipLines = SkipLines - 1
    If Skiplines > 0 then Loop
    ' - - - Parse data in line and process - - - <- Only get here if having skipped 2 lines, we are still not at end
    ' Indicate that we actually have processed something
    SkipLines = -1
    LineString = objFile.Readline ' And read the next line (if required)
Loop
' At this point, if SkipLines is anything other than -1 Then we have a short file!

An alternative is to process your actions based on the 'line number' incoming . . .:

LineString = objFile.Readline
Do While Not objFile.AtEndOfStream
    Select Case objFile.Line
        Case 3
              'Process first Line Type
        Case 4
              ' Process Second line type
        Case 6
              ' Process third line type
        ' etc. etc.
        Case Else
              Loop
    End Select
    LineString = objFile.Readline ' And read the next line (if required)
Loop

The above will process Lines 3,4,6 in the file, skipping the others. This is ideal if the number and order of lines in the file is predictable (as yours seeems to be).
In either case, the loop will drop through at end of file (stream) without giving the error experienced.

Regards . . Alan

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...