Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Visual Basic Quickstart Guide

You're reading from   Visual Basic Quickstart Guide Improve your programming skills and design applications that range from basic utilities to complex software

Arrow left icon
Product type Paperback
Published in Oct 2023
Publisher Packt
ISBN-13 9781805125310
Length 238 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Aspen Olmsted Aspen Olmsted
Author Profile Icon Aspen Olmsted
Aspen Olmsted
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Part 1:Visual Basic Programming and Scripting FREE CHAPTER
2. Chapter 1: The Visual Basic Family of Programming Languages 3. Chapter 2: Console Input and Output 4. Chapter 3: Data Types and Variables 5. Chapter 4: Decision Branching 6. Chapter 5: Iteration 7. Chapter 6: Functions and Procedures 8. Chapter 7: Project Part I 9. Part 2:Visual Basic Files and Data Structures
10. Chapter 8: Formatting and Modifying Data 11. Chapter 9: File Input and Output 12. Chapter 10: Collections 13. Chapter 11: Project Part II 14. Part 3:Object-Oriented Visual Basic
15. Chapter 12: Object-Oriented Programming 16. Chapter 13: Inheritance 17. Chapter 14: Polymorphism 18. Chapter 15: Interfaces 19. Chapter 16: Project Part III 20. Part 4:Server-Side Development
21. Chapter 17: The Request and Response Model 22. Chapter 18: Variable Scope and Concurrency 23. Chapter 19: Project Part IV 24. Chapter 20: Conclusions 25. Index 26. Other Books You May Enjoy

Reading text from files

We will continue to utilize the two different methods for VB.NET and older VB family members. For VB.NET, we will use the File class from the System.IO namespace to read text from files. For VBScript, VBA, and VB6, we will continue to use the FSO we used in the files and directories section.

The File class also provides two methods that make writing text to a file in a single line easy. The ReadAllText and ReadlAllLines methods pull all the text from the file into a single variable. The difference between the two methods is that the second method pulls the data line by line into an array, while the first does not separate the input file lines:

Imports System.IO
Dim myFile As String = "C:\Path\File.txt"
Dim myText As String = File.ReadAllText(myFile)

In VB.NET, the StreamReader class allows you to read text from a file. First, you create a StreamReader instance, and then use its Read or ReadLine methods to read the text:

Imports System.IO...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image