3

In a program I am migrating from vb6 to VB.net, there are three Line Input# statements, all the same:

Line Input #9, dummy
Line Input #9, dummy
Line Input #9, dummy

Will this just overwrite the variable each time, or do something stupid like append the input to dummy each time?

My second question, what's the difference between Input# and Line Input#? I had been using:

foo = bar.readline 

for Input #.. and now I'm afraid that I've done it all wrong and should have used:

foo = bar.Read 

or something All help greatly appreciated
Thanks guys!
Nick

Nick
  • 147
  • 1
  • 5
  • 16
  • Since the variable is called "dummy", the purpose of these code lines is probably to ignore three lines of text from the input file. So overwriting "dummy" is OK here. – Olivier Jacot-Descombes Nov 21 '11 at 14:49

3 Answers3

4

The language reference is still, surprisingly, available. Input #, Line Input #. You're correct that they are not the same.

To your first question, it will overwrite the variable, so it just seems to be a way to skip 2 lines and read the third line.


You're probably better off using the VB Runtime facilities to read files that have been produced by VB 6, rather than the ".NET" style of filesystem work, since I think it would be quite difficult to reproduce the behaviour of Input # using Read. Use FileSystem.Input instead.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • I had read those, but to me they sound pretty much the same, except the Line Input # specifically states that it reads a single line, does that mean that Input # reads more than one? – Nick Nov 21 '11 at 14:11
  • +1 but if you are trying to reproduce `LineInput` I suggest you use [`FileSystem.LineInput`](http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.lineinput.aspx) ! – MarkJ Nov 21 '11 at 14:44
3

The Line Input statement reads all the text in the input file up until the next CR or CR-LF sequence and puts it in the variable dummy. So these statements will, as you surmise, overwrite the variable dummy each time.

Input reads input until the next CR, CR-LF sequence or delimiting comma, and saves the data read in dummy.

I'm inclined to the view that you are right, you should really use bar.Read for Input # and bar.ReadLine for Input Line.

See Input # and Line Input # for more.

Brian Hooper
  • 21,544
  • 24
  • 88
  • 139
  • As the example in the documentation for `Input #` says, `"1,2""X"` is read as two strings, `"1,2"` and `"X"` - so it's not just commas as separators within the line. That's why I'd recommend using the already built VB6 interop classes. – Damien_The_Unbeliever Nov 21 '11 at 14:51
  • Before recommending the use of the interop classes for VB6, it would be useful to know what the program actually does. Rather than just a blind conversion, perhaps using a StreamReader or BinaryReader could be used. – Chris Dunaway Nov 21 '11 at 17:29
2

The Line Input # command doesn't do anything special like appending to the variable. The value is simply assigned to the varaible, so if you have three lines like that it will overwrite the first two values.

The Read # command expects a special format for the data, so ReadLine won't work as a replacement. The reference for the Write # command has details for how the data looks that the Read # command expects.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005