Chapter 5 - VB.NET Language and Syntax - Part 2
Qualifying With System.Math
As I said, this isan advanced topic, so we'll see more about it later in the course but here's an experiment you can do now to see the difference.
- Run the My Framework Math sample code from the book. Notice that there is an Imports System .Math statement already in it.
- Delete the Imports statement and replace
Result = Sqrt(625)
Result = System.Math.Sqrt(625)
- Run the application again. Notice that it works just like it did before.
Adding System.Math to the Sqrt object is called qualifying it and if you have to use Sqrt very much in your code, you will get very tired of typing the qualification over and over. So VB.NET gives you a way to let the computer do the work for you and this is the Imports statement.
This leads directly to my second point. This is a powerful and fundamental concept and it's at the very heart of Object Oriented Programming (OOP). It's especially important when you start using "third party software" for your libraries of objects rather than just Microsoft libraries. (Maybe this is another example of MS Press tunnel vision?) For example, if you want to use what are called "complex numbers" (an advanced mathematical rather than programming topic which we won'tcover later) you will find that there's really nothing in .NET to help out. Fortunately, there ARE libraries available from third party software companies that DO let you use complex numbers. (For example, see this page.)
- How to use InputBox and MsgBox as the first examples of function statements
- "Magic" Numbers in the Code
- Trying Out Changes in the Book's Code
- Windows Form Designer Generated Code
- More on Numbers and VB.NET
- Math and Programming
- Examples of the Math Operators
- What Should Have Been Included in the Book
- Qualifying With System.Math
- The Bottom Line!