0

I have received the misfortune task of upgrading an old and cranky (as much as it's code) VB6 app to c#. in many places along the code I'm seeing this # symbol before a number and it seems like some sort of viable.

For example:

Dim line As String 

f$ = File.Path + "\" + File.FileName 
Open f$ For Input As #2 
Line Input #2, a$ 

later he will use the a$ as the line value, but I can't see any use of the #2. so what exactly the 2# used for?

Slime recipe
  • 2,223
  • 3
  • 32
  • 49
  • A very bad style. Always use variables for file handles. `nFile = FreeFile : Open sFile For Input As nFile : Line Input nFile, sLine` – wqw Nov 04 '12 at 20:20
  • 4
    *Sigh* These are _not_ "file handles" at all, but indexes into a file info table in the runtime. They are called "file numbers" because that's what they are. The table is broken into two ranges with different sharing semantics. Actual file handles live inside the opaque table entries. – Bob77 Nov 04 '12 at 23:50
  • @Bob: Correct. You mean "Actual `Win32 API` file handles live..." – wqw Nov 05 '12 at 11:16

1 Answers1

4

The #2 is a file handle.

The file is opened and associated with the file handle here:

Open f$ For Input As #2

Then the input statement reads a line from that file and puts in the a$ variable:

Line Input #2, a$ 
Guffa
  • 687,336
  • 108
  • 737
  • 1,005