1. Technology

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.

  1. Run the My Framework Math sample code from the book. Notice that there is an Imports System .Math statement already in it.
  2. Delete the Imports statement and replace

    Result = Sqrt(625)


    Result = System.Math.Sqrt(625)

  3. 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.)

  1. How to use InputBox and MsgBox as the first examples of function statements
  2. "Magic" Numbers in the Code
  3. Trying Out Changes in the Book's Code
  4. Windows Form Designer Generated Code
  5. More on Numbers and VB.NET
  6. Math and Programming
  7. Examples of the Math Operators
  8. What Should Have Been Included in the Book
  9. Qualifying With System.Math
  10. The Bottom Line!

<< Previous | Next >>

©2014 About.com. All rights reserved.