FIX: File Control's EOF Property Is Always Set to False

ID: Q180887


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 5.0, version 1.0


SYMPTOMS

When using the File Control and reading from a file using either the LineInputString or InputFields methods, the EOF property is always False, even when it has reached the end of the file. One of the following error messages will be generated:

An error was encountered while running this program.
-or-
-2147467259


CAUSE

The file EOF property is not set to True when the file pointer reaches the end of the file.


RESOLUTION

There are two options for resolving this issue in the Windows CE Toolkit for Visual Basic 5.0:

Option1

Obtain the Windows CE ActiveX Control Pack available from the Microsoft Web site located at:

http://www.microsoft.com/windowsce/downloads/pccompanions/actxconpak1.asp

Option 2

Instead of checking the EOF property of the File control, use the LOC property and compare it against the LOF property. For example:

   While File1.LOC < File1.LOF
      'put code here
   Wend 


STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.


MORE INFORMATION

Steps to Reproduce Behavior

NOTE: This example uses the LineInputString method. The error also occurs using the InputFields method.
  1. Start a new Windows CE project in Visual Basic 5.0. Form1 is created by default.


  2. Add a File control, two CommandButton controls, and a TextBox to Form1.


  3. Set the Text1.Multiline property to True.


  4. Add the following code:


  5. 
          Option Explicit
    
          Private Sub Form_Load()
             Command1.Caption = "Write to file"
             Command2.Caption = "Read from File"
          End Sub
    
          Private Sub Command1_Click()
             'Write file via LinePrint
             File1.Open "\test.txt", 2
             File1.LinePrint "line one"
             File1.LinePrint "line two"
             File1.LinePrint "line three"
             File1.Close
          End Sub
    
          Private Sub Command2_Click()
             'Read file via LineInputString
             Dim sLine
             On Error Resume Next
             Text1.Text = ""
             File1.Open "\test.txt", 1
             Do Until File1.EOF
                sLine = File1.LineInputString
                If Err.Number <> 0 Then
                   Text1.Text = Text1.Text & "error: " &  _
                   Err.Number & " " & Err.Description & vbCrLf
                   File1.Close
                   Exit Sub
                End If
                Text1.Text = Text1.Text & sLine & ":  File1.EOF = " _
                             & File1.EOF & vbCrLf
             Loop
             File1.Close
          End Sub
     
  6. Press the F5 key to run the project and note that the error -2147467259 is encountered because File1.EOF is never set to True.



REFERENCES

Books Online for Microsoft Windows CE Toolkit for Visual Basic 5.0

Additional query words: wce vbce vbce5 vbce6

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbWinCE kbWinCE100 kbGrpVB
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: July 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.