Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

some issues with File IO in VB.NET compared to VB6

Status
Not open for further replies.

moron3

Technical User
Dec 2, 2008
17
US
I'm moving to VB.NET after using VB6 for quite a few years.

File operations in VB.NET seem to have some drawbacks.

In VB6 you can use an array of anything- bytes or structures for a buffer

Buffer = String(10000," ")
Get #1, Buffer

and if the array is larger than the file it will just read in the available bytes.

But in VB.NET

FileGet(1,Buffer)

generates an error if Buffer is bigger than the available bytes.

Do you have to check the available bytes left in the file before you read from it? If so, can you tell me how?

I don't mind reading one record at a time as long as there's some internal buffering going on behind the scenes. I think that's the way C works but this method is still not as nice as VB6.

Also in VB6 you didn't have to use fixed length strings in your UDTs for easier file reading. If you read in an array of UDTs it would parse everything for you automatically. The VB.NET examples I've seen use fixed length strings. That means you have to RTrim your strings when displaying them to the user and in Combo/Listboxes etc..

I know it's basic question but this is an area I'll be using heavily and I don't want to get on the wrong track...
 
FileGet is in the Microsoft.VisualBasic namespace. That's where a lot of methods for VB6 compatibility reside. However, I would recommend coding with "normal" .Net methods.

For example:
Code:
SomeByeArrayVariable =        System.IO.File.ReadAllBytes("C:\SomeFile.txt")
SomeStringArrayVariable =        System.IO.File.ReadAllLines("C:\SomeFile.txt")
SomeString =        System.IO.File.ReadAllText("C:\SomeFile.txt")

You can also use the My namespace. For example: My.Computer.FileSystem.ReadAllBytes. Also note that the intellisense for Microsoft.VisualBasic.FileGet states The My feature gives you better productivity and performance in file I/O operations than FileGet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top