Visual Basic for Very Bright Kids - Part 5 - Beyond this Book

February 2007

Bb297398.9a4871d4-2a3f-40a8-b15f-a6d21b71dcaf(en-US,VS.80).png

We don't have the means to download all the information we need directly into our heads. Besides, what fun would that be - half the enjoyment is in the learning. Remember how you felt when you got your first program running? Well, there's a lot more out there waiting to be conquered.

This book has not tried to teach you everything about Visual Basic programming. It has rather tried to give you grounding in the basic concepts and enough exposure to real examples for you to now take yourself forward.

Bb297398.22731f0a-b6ef-471b-bd2c-f9985edf7293(en-US,VS.80).png

The Code that Visual Basic Express Puts Down For You

The examples we’ve used in this book have always used single file to write the code in. Visual Basic Express sometimes splits the code across a few files. We should point out particularly what it does when you start a new "Windows Application" project, so that you know where to start writing your form code.

The screen grab below illustrates what happens in that case – we’ve arranged the windows a bit differently from the default in order to show you clearly what is created for you.

Bb297398.86aaa7ed-3993-4de4-b9bf-7de7171cdc6f(en-US,VS.80).png

Let’s discuss the four windows above:

  1. Code view of Form1.vb – this holds the file where you will add code that does things on the form. You will, for example, add an event handler for a button here.

  2. Designer view of Form1.Designer.vb – this is where you can drag-and-drop controls such as buttons from the toolbox. That saves you having to hand-code everything.

  3. Code view of the Form1.Designer.vb – when a button, for example, is dropped on the designer surface, Visual Basic Express writes some code for you to declare a button instance. That code gets put in this file. So this file is really for the system’s own use – to represent in code the things that you do on the design surface. You will not normally change or add code in this file. In fact, the system draws the designer view out of the information it finds in this file. (The designer view doesn’t have another file – this is its file).

  4. Code view of Program.vb. This file contains the familiar Main() method and some code to automatically create an instance of your Form class. So it’s the file responsible for starting the whole program. In the case of a Windows Application you will not normally change this file.

This splitting of code across files is made possible by something called Partial classes – you can have bits of your class in different physical files. Why on earth does the class above have to be split across files? It doesn’t, but there’s a good reason for doing it – to keep code apart that has different basic purposes. Although it may seem complex to have three files, what it’s achieved is giving you a single, clean file, Form1.vb, where you can write all the code that you’re interested in. The system often creates code for you and you’d get quite offended if it dumped that code in the file you’re trying to write in. Similarly, Visual Basic Express could get horribly confused if you started messing with the files that it thinks it owns. The "Partial" scheme allows everyone to have their own space to work in. Your territory is the top two windows in the view above – the designer view and the code view of Form1.vb.

Of course, you can always choose to delete Program.vb and Form1.vb and start with your own files instead.

Some Further Tips

As with any new field that you learn, many questions will arise as you continue. These will often fall within the following areas:

  1. What do I do when I get an error message in Visual Basic Express?

    Bb297398.cb8fcbb0-0901-455a-9a3f-bb320b2fb889(en-US,VS.80).png

    Calm down and listen to what the computer is trying to tell you. Admittedly, it's sometimes not clear enough, but trying to put yourself in its shoes helps.

    Read more about "debugging" in Visual Basic Express - it allows you to do a slow-motion step through a program one line at a time, even inspecting the values of your variables, behind the scenes, along the way. This doesn't do the fixing for you, but helps your own brain by exposing more information. The real detective work is up to you.

    If it's not making sense, try doing a search for that error message in the help, or on your favorite Internet search engine. Often you will get clues which make you think differently and so grasp the nature of the problem.

  2. In the .NET Framework Class Library ...

    1. How do I know what classes I can find?

    2. How do I know what methods those classes have?

    3. How do I know what parameters to pass to those methods?

    Visual Basic Express includes a thorough reference to all the classes in the .NET Framework Class Library. Select Help -> Contents to call up the help and then locate the topic ".NET Framework SDK". In the example below, suppose we were looking for information on what classes are available in the System.Windows.Forms namespace. We'd select "Class Library" and then scroll down the right-hand page to "System.Windows.Forms".

    Bb297398.454f3035-571e-4096-9513-f994d255b327(en-US,VS.80).png

    When you click the Systems.Windows.Forms hyperlink, a list of classes (in this case things like Button, Label, ComboBox, etc) will be displayed. Once you select a specific class (like ComboBox) you'll be shown something similar to the picture below. Then clicking the "Members" hyperlink will take you to a page which lists all the methods, properties and events available in that class and specifies their details.

    Bb297398.8de9c377-a55a-40d2-b4d8-85b8502c2d0d(en-US,VS.80).png

    What's really great is the huge number of examples that are included in the reference. The cold reference can sometimes seem a bit meaningless, but click "Example" and suddenly things start to fall into place. If you don't find a suitable example by navigating the reference, do a search in the general help and you will often turn up useful examples that are stored in other places.

  3. Where can I find out more?

    You'll get to a point where you can't figure out more on your own. Then it's time to hit the community out there, see what other people are up to with Visual Basic and look at how they solve various problems with Visual Basic.

    Bb297398.cbbc3aaf-f795-42da-9c7f-1460bd37bf6d(en-US,VS.80).png

    You would do well to spend some time on websites such as these :

    Don't be afraid to ask some "newby" questions at the discussion forums but make sure you browse through first to see whether someone else has already asked such a question.

Enjoy your learning journey!

About the Book

Visual Basic is both a powerful and easy to use programming language. It presents a great opportunity for the new generation of developers to start out with a language that is highly respected in the modern workplace.

This text introduces object-oriented programming to the young developer (core target age is 12-16) in a lightweight fashion, allowing them to get started with real programs in a Windows environment.

About the Author

Martin Dreyer is an ex-high school teacher who now heads a team of software developers in South Africa.

His formal qualifications are a Higher Diploma in Education : Physical Science and a Bachelor of Science Degree : Computer Science and Information Systems.