Chapter 13: Exploring Text Files and String Processing


Chapter 13

Exploring Text Files and String Processing

After completing this chapter, you will be able to:

  • Display a text file by using a text box object, the LineInput function, and the StreamReader class.

  • Use the My object, a new “speed dial” feature within Microsoft Visual Studio 2005.

  • Save notes in a text file by using the PrintLine function and the SaveFileDialog control.

  • Use string processing techniques to compare, combine, and sort strings.

Managing electronic documents is an important function in any modern business, and Microsoft Visual Basic 2005 provides numerous mechanisms for working with different document types and manipulating the information in documents. The most basic document type is the text file, which is made up of non-formatted words and paragraphs, letters, numbers, and a variety of special-purpose characters and symbols.

In this chapter, you'll learn how to work with information stored in text files on your system. You'll learn how to open a text file and display its contents in a text box object, and you'll learn how to create a new text file on disk. You'll also learn more about managing strings in your programs, and you'll use methods in the Microsoft .NET Framework String and StreamReader classes to combine, sort, and display words, lines, and entire text files.

Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005

If you're experienced with Microsoft Visual Basic 6, you'll notice some new features in Visual Basic 2005, including the following:

  • In Visual Basic 6, you open and manipulate text files by using the Open, Line Input #, Print #, EOF, and Close keywords. Beginning with Microsoft Visual Basic .NET 2002, there's a new set of functions that manage text file operations. These functions are provided by the FileSystem object in the Microsoft.VisualBasic name-space and include FileOpen, LineInput, PrintLine, and FileClose.

  • In addition to the FileSystem object functions just mentioned, you can use the My object and objects in the System.IO namespace to open and manipulate files, browse drives and folders, copy and delete files, process text streams, and complete other file-management tasks. These objects have the advantage of being available in all Visual Studio languages, so if you plan to try Microsoft Visual C++ programming eventually (for example), you might prefer using them. System.IO objects are very efficient and easy to use, so I'll teach them along with the “Visual Basic only” file operation techniques.

  • In terms of string processing, several of the older Visual Basic text functions have been supplemented and replaced by new methods in the .NET Framework String class. For example, the new SubString method provides functionality similar to the Visual Basic Mid function, and the ToUpper method is similar to the Visual Basic UCase function. You can use either method to manipulate text strings, but the newer .NET Framework methods are recommended.

  • By using the new My object, you can quickly query the system for useful information and perform common programming tasks, such as opening text files.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net