Visual Basic 101 (part 1)

Programming is Fun

I'm sure many of you reading this have been exposed to at least a little bit of a programming language, be it HTML, PowerShell, VBScript, or whatever. Some of you may enjoy programming, some may not. (I know I do.)


Let me begin by saying that it is virtually impossible for any single programmer to know everything about a given language. Also, there are countless ways to program the same thing. Some solutions may be more elegant than others, but in general, there is no single right answer, as long as the program works correctly. That said, you should feel a little less intimidated by the amount of available reference on the inter-tubes concerning programming languages. This article will explore the tiniest fraction of Visual Basic. Hopefully this will encourage you to explore more on your own once you begin to realize it's not as mysterious as you may have thought.


Here are links to the whole series of posts:

Part 1 - Getting the environment set-up

Part 2 - Creating the VB form

Part 3 - Writing the code

Part 4 - Compiling the code


The Gift

A while back, I took it upon myself to create an internal tool we needed here at SolarWinds. Hence, the Bandwidth Calculator was born. This calculator was designed specifically for SAM to estimate the recommended amount of bandwidth needed for a certain amount of component monitors based on their protocol. As you can see below, 21 WMI component monitors would, on average, use the same amount of bandwidth as 10,000 SNMP component monitors. In this series I will explain step by step how I built this calculator, explain what everything means, then give you all the code needed along the way so you can build this yourself. This will be your Visual Basic classroom starting today. At the end, you get to keep the calculator you've re-created below (it even talks).


Note:
The only way to get this calculator is to build it following the steps in this series. It will not be available for download nor will SolarWinds offer support for this tool. The code for this tool is made available for educational purposes
only.

calc.png

Lesson 1 - Installation

Before we begin, you'll need to install Visual Basic Express 2010, free courtesy of Microsoft. Click this link to begin downloading, followed by the installation.

Lesson 2 - The Environment

Now open Visual Studio Express and select New Project from the File menu. A new window will pop open. From there, select Windows Form Application, then click OK. If you done everything successfully, your screen should now look like this:

ide.png

Now you have all you need to build the Bandwidth Calculator, minus the code. Let me explain what you're looking at above:

  • Highlighted in red is a Form. A form, in essence, is a window; hence the name, Windows. A form is an empty workspace where all of your buttons and controls will live, once you put them there. (Notice the form of the calculator above with all of its controls.)
  • Highlighted in green is the Toolbox. The toolbox contains all of the controls you will need to build almost anything, including the calculator. (In fact, you can even build your own controls, but I will not cover that in this series.) These controls may be placed on the form as needed. As you can see in the calculator, there are multiple text boxes, sliders, labels, a pie chart, and a button. These all came from the toolbox.
  • Highlighted in purple is the Properties window. Every control, or object (including the form itself) has certain properties. These properties can be set and changed both before running the program and while the program is running. Think about the properties of a television. One property is its color. Other properties include the TV's height, weight, picture resolution, and so on. The reason the button on the calculator says, "Reset" is because I changed the Text property of the button in the Properties window to read, "Reset."

Homework

Play around with this new environment and try to get comfortable. Explore the controls and the properties of the more common controls.
Tip: Once you place a control on the form and select it, the Properties window will show the properties of that control.

Thwack - Symbolize TM, R, and C