You are not logged in.

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

1

Saturday, September 5th 2009, 11:17pm

Opening a file for read creates an empty file

Hi,
I've tried the following:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
   Dim f As VBFileHandler 
   Dim s As String

   f = Open(fileName, Input, Read, Shared)
   
   If f <> Null Then       
         Do While Not f.EOF 
            s = f.readLine
            ....
          loop
  end if

  f.close


This code creates an empty file, if "fileName" does not exist.

To avoid this behaviour, I am now using:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
   Dim f As VBFileHandler 
   Dim s As String

   f = Open(fileName, Input, Read, Shared)
   
   If f <> Null Then       
         if f.exists then
           Do While Not f.EOF 
              s = f.readLine
              ....
            loop

            f.close
         end if
  end if


The "f.close" has to be omitted, unless you opened an existing file.

Greetings

A1880

Rate this thread
WoltLab Burning Board