33,59 €
Whether you’re an absolute beginner or an experienced developer looking to learn the Visual Basic language, this book takes a hands-on approach to guide you through the process. From the very first chapters, you'll delve into writing programs, exploring core concepts such as data types, decision branching, and iteration. Additionally, you’ll get to grips with working with data structures, file I/O, and essential object-oriented principles like inheritance and polymorphism.
This book goes beyond the basics to equip you with the skills to read and write code across the entire VB family, spanning VB Script, VBA, VB Classic, and VB.NET, enabling you to handle legacy code maintenance with ease.
With clear explanations, practical examples, and hands-on exercises, this book empowers you to tackle real-world software development tasks, whether you're enhancing existing projects or embarking on new ones. It addresses common challenges like distinguishing between the variations of the VB programming language to help you choose the right one for your projects.
Don't let VB's extensive legacy daunt you; embrace it with this comprehensive guide that equips you with practical, up-to-date coding skills to overcome the challenges presented by Visual Basic's rich history of over two decades.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Veröffentlichungsjahr: 2023
Visual Basic Quickstart Guide
Improve your programming skills and design applications that range from basic utilities to complex software
Aspen Olmsted
BIRMINGHAM—MUMBAI
Copyright © 2023 Packt Publishing
All rights reserved.
No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Kunal Sawant
Publishing Product Manager: Akash Sharma
Senior Editor: Rounak Kulkarni
Technical Editor: Shruti Thingalaya
Copy Editor: Safis Editing
Project Coordinator: Deeksha Thakkar
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Production Designer: Joshua Misquitta
DevRel Marketing Coordinator: Sonia Chauhan
Business Development Executive: Samriddhi Murarka
First published: October 2023
Production reference: 1210923
Published by Packt Publishing Ltd
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1RB
ISBN 978-1-80512-531-0
www.packtpub.com
To the surviving family members of the many computer science students who were taken too soon. Their creativity was too much for this world and I am sure they are developing great software projects in the next world.
– Aspen Olmsted
Aspen Olmsted is an associate professor and program director at Wentworth Institute of Technology in the Computer Science department. He obtained a Ph.D. in Computer Science and Engineering from the University of South Carolina. Before his academic career, he was CEO of Alliance Software Corporation. Alliance Software developed N-Tier enterprise applications for the performing arts and humanities market. Dr. Olmsted’s research focuses on developing algorithms and architectures for distributed enterprise solutions that guarantee security and correctness while maintaining high availability. Aspen mentors over a dozen graduate and undergraduate students in his Secure Data Engineering lab each year.
I would like to, first and foremost, thank my loving and patient wife, Kirsten, and children, Freya and Seamus, for their continued support, patience, and encouragement throughout the long process of writing this book.
Muhammad Hameem Ibne Kabir is passionate about visual coding and secure design and is presently working as a freelance developer. He studied cybersecurity at New York University. He has also done a number of courses on computer science from MIT and Harvard. Muhammed has designed user-friendly and phonetically interrelated keyboard layouts for different languages. He has also developed web-based and desktop apps to run them.
In this book, you will learn about the Visual Basic language and all its different use cases. This journey will enable you to apply that understanding to maintain, enhance, administer, and secure Visual Basic console or Windows applications, Visual Basic websites, or Visual Basic scripts. This book starts from an understanding that many programmers will need to use Visual Basic for many different purposes. In each chapter, we highlight topics across the many different use cases Visual Basic is used for.
When learning how to program in a new language, you always want to give yourself time to digest the concepts. Many iterations of the topic help to solidify it in your mind. To get the most out of this book, you are encouraged to have your computer open as you read the book. Another terrific approach is to read a chapter for the first time and then go to your computer and revisit the examples by plugging them in yourself on your computer.
I also encourage you to dig deep into your creativity and think of ways to use the skills we cover in a creative project. I suggest several projects in the last chapter of the book, but you should try to find something meaningful for you. Good luck!
If you work in software engineering, information technology, or cybersecurity and need to maintain, enhance, administer, or secure Visual Basic console or Windows applications, Visual Basic websites, or Visual Basic scripts, then this book is for you.
At the time of writing this book, Microsoft is reducing its investment in Visual Basic. Despite that, there are many software development jobs that involve maintaining, enhancing, administering, and defending Visual Basic programs, websites, and scripts. These jobs will continue to exist for decades to come. This book is designed for software developers and web developers who find themselves in one of those jobs or want to acquire one of those jobs. This book presents all the different use cases of Visual Basic in a concise way.
Chapter 1, The Visual Basic Family of Programming Languages, provides an overview of VB and its use cases over the years.
Chapter 2, Console Input and Output, teaches you how to retrieve keyboard input and send the results of computations to the computer screen.
Chapter 3, Data Types and Variables, discusses the different ways to store data in the computer memory during the program execution.
Chapter 4, Decision Branching, talks about how to build different pathways inside of our code based on an external environment such as input from the user.
Chapter 5, Iteration, shows how to repeat sections of code either a fixed number of times or until an environment is in a certain state.
Chapter 6, Functions and Procedures, dwells on modularizing sections of code for reuse. This makes it easier to have fewer bugs by only having one copy of code that does a specific thing.
Chapter 7, Project Part I, enables you to apply the programming skills you have learned to this point.
Chapter 8, Formatting and Modifying Data, explores the concept of rearranging data to use for display or for saving externally.
Chapter 9, File Input and Output, shows how to read and write data from and to files on the disk drive.
Chapter 10, Collections, discusses storing multiple values in one variable and then accessing those variables in code.
Chapter 11, Project Part II, provides an opportunity to apply the programming skills we have learned up to this point.
Chapter 12, Object-Oriented Programming, deals with arranging code into objects. Each object can have a state and actions it can perform.
Chapter 13, Inheritance, teaches us how to reuse code through the creation of taxonomies where we specify generic functionality higher in the tree.
Chapter 14, Polymorphism, shows us how to allow VB to execute the proper version of a method at runtime based on the context of the running program.
Chapter 15, Interfaces, explores code reuse through the definition of contracts for implementations that can be developed later but executed by our code.
Chapter 16, Project Part III, allows us to apply the programming skills we have learned up to this point.
Chapter 17, The Request and Response Model, discusses the web application communication model and how we send messages between partitions of our application.
Chapter 18, Variable Scope and Concurrency, explores handling multiple users on a web application.
Chapter 19, Project Part IV, provides a final opportunity to try out what we have learned.
Chapter 20, Conclusions, reviews the topics covered and suggests further learning and projects.
We cover many different platforms and use cases of Visual Basic in this book. You should focus on the VB family members that make sense to you at the time of reading and revisit the book later to think about the other family members. No prior programming experience is required, but if you have programmed in another language, you will find VB comes easily to you.
Software/hardware covered in the book
Operating system requirements
VB.NET
Windows, macOS, or Linux
ASP.NET
Windows
VB6
Windows
VBA
Windows
VBScript
Windows
For VB6, we recommend you install Windows XP in a virtual machine such as VirtualBox.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Learn-Visual-Basics-Quick-Start-Guide-. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The following is sample Visual Basic.NET Windows Form code that would be stored in a file, with a name such as program.vb.”
A block of code is set as follows:
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load MsgBox("Hello, World!") End Sub End ClassBold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Choose Standard EXE as the project type.”
Tips or important notes
Appear like this.
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Once you’ve read Visual Basic Quickstart Guide, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere?
Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link belowhttps://packt.link/free-ebook/9781805125310
Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directlyIn the first part of this book, we will focus on teaching you the basic programming skills needed to write core code in any of the Visual Basic family members. If you have learned any other programming language, all of these topics will be familiar, as most programming languages have similar topics.
This part has the following chapters:
Chapter 1, The Visual Basic Family of Programming LanguagesChapter 2, Console Input and OutputChapter 3, Data Types and VariablesChapter 4, Decision BranchingChapter 5, IterationChapter 6, Functions and ProceduresChapter 7, Project Part IPeople have been programming Visual Basic for over 23 years. Microsoft has deployed Visual Basic in many different environments over the years, including Windows Desktop development with Classic Visual Basic and Visual Basic.NET Windows Forms. Visual Basic has also been used as a server-side programming language in Classic ASP and ASP.NET. Visual Basic for Applications has been used to embed Visual Basic in both Microsoft Office products along with many third-party products. Lastly, many scripts have been used to control specialized hardware or automate administrative tasks. You will walk away from this chapter with a strong foundation to meet your Visual Basic requirements.
In this chapter, we’re going to cover the following main topics:
Visual Basic.NET Windows FormsVisual Basic ClassicVisual Basic for Applications (VBA)Visual Basic Scripting Edition (VBScript)Classic ASPASP.NETEach Visual Basic family member will have different technical requirements. We will provide installation options and steps in each subsection for the different family members. Some of these products are old and should be installed in a virtual machine (VM) or development machine that does not need to maintain security. All example code for this book is available at the following GitHub repository: https://github.com/PacktPublishing/Learn-Visual-Basics-Quick-Start-Guide-.
Visual Basic.NET Windows Forms is a user interface (UI) framework to create desktop applications on the Windows operating system. It allows developers to create visually appealing and interactive applications using a drag-and-drop interface, without needing to write all the code from scratch.
Windows Forms provides a set of pre-built controls such as buttons, textboxes, labels, and menus that can be easily placed on a form to create a UI. These controls can be customized by changing properties such as color, size, and font, and they can be programmed to respond to user input and events.
Visual Basic.NET is a programming language that can be used to write code for Windows Forms applications. It is a high-level language that is easy to learn and use, and it provides a wide range of features to develop complex applications.
Some of the features of Visual Basic.NET Windows Forms include the following:
Rapid application development: Windows Forms provides a quick and easy way to create desktop applications using a visual designer.Data binding: Windows Forms supports data binding, which allows developers to connect controls to data sources such as databases or XML files.Advanced controls: Windows Forms includes a set of advanced controls such as DataGridView and the Chart control, which can be used to create more sophisticated UIs.Object-oriented programming (OOP): Visual Basic.NET supports OOP, which allows developers to write reusable and maintainable code.OOP
OOP is a programming paradigm based on the concept of objects, which are entities that contain both data and behavior. In OOP, objects are created from classes, which define the data and behavior the objects will have. The main principles of OOP include the following:
• Encapsulation: This principle involves bundling data and behavior into objects and hiding the implementation details from the outside world. Encapsulation helps to ensure that objects are used correctly and that the data they contain is not modified in unintended ways.
• Inheritance: This principle involves creating new classes by extending existing classes. Inheritance allows new classes to inherit the data and behavior of their parent classes, and it also allows them to add their unique features.
• Polymorphism: This principle allows objects of different classes to be treated as the same object type. Polymorphism is achieved through interfaces or abstract classes, which define a set of standard methods that can be used by all objects that implement the interface or inherit from the abstract class.
OOP has many advantages, including improved code organization, increased code reusability, and better maintainability.
Overall, Visual Basic.NET Windows Forms is a powerful tool to create desktop applications on the Windows platform, and it is a popular choice among developers due to its ease of use and wide range of features.
Unfortunately, Microsoft has announced they will not be evolving the Visual Basic.NET language in the future. This announcement does not mean the language is dead – on the contrary, billions of lines of production code out there will continue to execute for many decades. It just means new language features will not be added to the language. Now that we have familiarized ourselves with Visual Basic.NET Windows Forms, let us look at coding a simple example.
Visual Basic.Net Windows Forms code is stored in text files with an extension of .vb. The following is sample Visual Basic.NET Windows Form code that would be stored in a file, with a name such as program.vb. Running the program will display a message box that displays Hello World!on startup:
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load MsgBox("Hello, World!") End Sub End ClassNext, we will see how to implement this code.
The following steps will install Visual Basic.NET onto a Windows machine:
Download your Visual Studio Community Edition from this link: https://learn.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2022.Double-click the VisualStudioSetup.exe bootstrapper to start the installation.Choose the .NET desktop development workload.Let the installer finish.Most users will use the Microsoft Windows operating system (OS) and Microsoft’s implementation of Visual Basic.NET, but there are projects and products that allow installation on different OSs, which we will discuss next.
The following list shows other options to work with Visual Basic.NET-compatible code:
Mono: Mono is an open source development platform based on the .NET framework. It includes a Visual Basic.NET compiler and VB.NET runtime. You can download Mono from here: http://mono-project.com..NET SDK: The .NET Software Development Kit (SDK) is a set of tools, libraries, and components to develop applications that target the .NET platform. It includes everything you need to build and deploy .NET applications, including a compiler, runtime, and various libraries.The .NET SDK is available for multiple platforms, including Windows, Linux, and macOS. It supports multiple programming languages, including C#, F#, and Visual Basic.