//
you're reading...
.Net Programming Course, .Net Programming Training, .Net Training, .NET Training Ahmedabad, VB.NET classes

Read a Text File Using VB Dot Net

Read Text File using Classic VB

In classic VB reading a file is not that easy as we do in vb.net. The first and easy way to access is using the simple file open method available in classic Visual Basic. Using this method, we can allocate a unique file number for opening the file. Further the same number has to be used for closing the file handle.

In addition to this, there are various modes a file can be opened. Some of them are Append, Binary, Input, Output, or Random. By default Random will be used.

Read text file in VB.Net

In VB.net we can read files very easily. The System.IO namespace contains really very useful set of functions which can reduce the effort and time in coding file related activities. One of the easiest is reading into string System.IO.File.ReadAllText(FilePath).

Using FileSystemObject in VB6 to Read a Text File

With FileSystemObject File IO operations are very easier in VB. Almost all the required functions are well defined. For reading, we have to use OpenTextFile method in the FileSystemObject. Once opened, A TextStream object can be used to fetch the data. To fetch line by line we need to loop through until we reach EOF. To find the EOF, FileSystemObject has a property AtEndOfStream. When it is true, it represents that the end of file is reached.

Using the Open method in VB6

Using a open method is much easier and effective way. It is well supported from a earlier versions of the visual basic. Because of it’s simplicity, we can see this in a lot of applications. Once it is opened please close it immediately after done working with the whole text fetched. This open method is working based on FileNumber. So the same FileNumber has to be used to close aswell.

Search using Regular Expressions

If search string is not specified the function will give the entire content. If the search string is specified then the search results will be appended to a text and will be returned. The search is regular expression based search

Since the search is regular expression based, the regular expression should be validated before using the function. Or else the function will be hanging due to invalid regular expression.

Article Source: http://EzineArticles.com/5884230

.Net Training, VB.NET classes

Advertisements

About DS Training Academy

We provide live international training under all of our Triple Certification courses and trained by industry professionals. We provide Job oriented training course in ASP.NET, PHP, Web Designing, C and C , SEO, Flash, Flex in Ahmedabad We run .NET training centre, PHP Classes in Gujarat, SEO courses in Ahmedabad, Web design institute.

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Advertisements
%d bloggers like this: