 A visual programming
language (VPL) is any programming
language that lets users create
programs by manipulating program
elements graphically rather than by
specifying them textually.
A VPL allows programming with
visual expressions, spatial
arrangements of text and graphic
symbols, used either as elements
of syntax or secondary notation.
The Basics: How Programming
Works
 :How a programming language
works, along with basic terminology.
Representing Words, Numbers,
and Values with Variables
 :How variables store values and
represent information, along with
how to use variables.
On its own, a computer isn't very smart.
A computer is essentially just a big
bunch of small electronic switches that
are either on or off. By setting different
combinations of these switches, you can
make the computer do something:
 for example, display something on the
screen or make a sound. That's what
programming is at its most basic—telling
a computer what to do.
s
 A programming language acts as a
translator between you and the computer.
Rather than learning the computer's native
language (known as machine language), you
can use a programming language to instruct
the computer in a way that is easier to learn
and understand.
What is a Programming
Language?
A programming language acts as a translator
between you and the computer. Rather than learning the
computer's native language (known as machine language), you
can use a programming language to instruct the computer in a
way that is easier to learn and understand.
A specialized program known as a compiler takes the
instructions written in the programming language and converts
them to machine language. This means that as a Visual Basic
programmer, you don't have to understand what the computer
is doing or how it does it. You just have to understand how the
Visual Basic programming language works.
The language you write and speak has structure:
for example, a book has chapters with paragraphs that
contain sentences consisting of words. Programs written
in Visual Basic also have a structure: modules are like
chapters, procedures are like paragraphs, and lines of
code are like sentences.
When you speak or write, you use different
categories of words, such as nouns or verbs. Each
category is used according to a defined set of rules. In
many ways, Visual Basic is much like the language that
you use every day. Visual Basic also has rules that define
how categories of words, known as programming
elements, are used to write programs.
Written and spoken language also has
rules, or syntax, that defines the order of words
in a sentence. Visual Basic also has syntax—at
first it may look strange, but it is actually very
simple. For example, to state "The maximum
speed of my car is 55", you would write:
Car.Speed.Maximum = 55
Variables are an important concept in computer
programming. A variable is a letter or name that can store a
value. When you create computer programs, you can use
variables to store numbers, such as the height of a building,
or words, such as a person's name. Simply put, you can use
variables to represent any kind of information your program
needs.
There are three steps to using a variable:
Declare the variable. Tell the program the
name and kind of variable you want to use.
Assign the variable. Give the variable a
value to hold.
Use the variable. Retrieve the value held in
the variable and use it in your program.
Declaring a Variable
When you declare a variable, you have to
decide what to name it and what data type to
assign to it. You can name the variable anything
that you want, as long as the name starts with a
letter or an underscore. When you use a name
that describes what the variable is holding, your
code is easier to read. For example, a variable
that tracks the number of pieces of candy in a
jar could be named totalCandy
You declare a variable using the Dim and As keywords, as
shown here.
This line of code tells the program that you want to
use a variable named aNumber, and that you want it to
be a variable that stores whole numbers (the Integer data
type).
Because aNumber is an Integer, it can store only
whole numbers. If you had wanted to store 42.5, for
example, you would have used the Double data type. And
if you wanted to store a word, you'd use a data type
called a String. One other data type worth mentioning at
this point is Boolean, which can store a True or False
value.
VB
Dim aNumber As Integer
Here are more examples of how to declare variables.
Note:
You can create a local variable without declaring the type of the
variable by using local type inference. When you use local type
inference, the type of the variable is determined by the value that is
assigned to it. For more information, see Local Type Inference.
VB
Dim aDouble As Double
Dim aName As String
Dim YesOrNo As Boolean
You assign a value to your variable with the =
sign, which is sometimes called the assignment
operator, as shown in the following example.
This line of code takes the value 42 and stores it in
the previously declared variable named aNumber.
VB
aNumber = 42
Declaring and Assigning Variables
with a Default Value
As shown earlier, you can declare a
variable on one line of code, and then later
assign the value on another line. This can cause
an error if you try to use the variable before
assigning it a value.
For that reason, it is a better idea to
declare and assign variables on a single line.
Even if you don't yet know what value the
variable will hold, you can assign a default value.
The code for declaring and assigning the same
variables shown earlier would look like the
following.
VB
Dim aDouble As Double = 0
Dim aName As String = "default string"
Dim YesOrNo As Boolean = True
Try it!
In this exercise, you will write a short program that creates
four variables, assigns them values, and then displays each value in
a window called a message box. Let's begin by creating the project
where the code will be stored.
To create the project
1. If it is not already open, open Visual Basic from the
Windows Start menu.
2. On the File menu, click New Project.
3. In the New Project dialog box on the Templates
pane, click Windows Forms Application.
4. In the Name box, type Variables and then click OK.
Visual Basic will create the files for your program and open the
Form Designer.
Next, you'll create the variables.
To create variables and display their values
1.Double-click the form to open the Code Editor.
The Code Editor opens to a section of code called Form1_Load. This
section of code is an event handler, which is also referred to as a procedure.
The code that you write in this procedure is the instructions that will be
performed when the form is first loaded into memory.
2. In the Form1_Load procedure, type the following code.
VB
Dim anInteger As Integer = 42
Dim aSingle As Single = 39.345677653
Dim aString As String = "I like candy"
Dim aBoolean As Boolean = True
 This code declares four variables and assigns their default values. The four
variables are an Integer, a Single, a String, and a Boolean.
Tip: As you typed the code, you may have noticed that after you typed As, a list
of words appeared underneath the cursor. This feature is called IntelliSense. It
enables you to just type the first few letters of a word until the word is selected
in the list. Once the word is selected, you can press the TAB key to finish the
word.
3. Beneath the code you wrote in the previous step, type the following.
 This code tells the program to display each value that you assigned in the previous
step in a new window, using the MsgBox function.
4. Press F5 to run your program.
Click OK for each message box as it appears. Note that the value of each
variable is displayed in turn. You can close the form by clicking the x in the upper-right
corner of the form. After the program has finished, you can go back and change the
values that are assigned in the code—you'll see that the new values are displayed the
next time that you run the program.
VB
MsgBox(anInteger)
MsgBox(aSingle)
MsgBox(aString)
MsgBox(aBoolean)
Note:Whenever you represent actual text in a program, you must enclose it in
quotation marks (""). This tells the program to interpret the text as actual text
instead of as a variable name. When you assign a Boolean variable a value of True or
False, you do not enclose the word in quotation marks, because True and False are
Visual Basic keywords with special meanings of their own.
Visual Programming

Visual Programming

  • 2.
     A visualprogramming language (VPL) is any programming language that lets users create programs by manipulating program elements graphically rather than by specifying them textually. A VPL allows programming with visual expressions, spatial arrangements of text and graphic symbols, used either as elements of syntax or secondary notation.
  • 3.
    The Basics: HowProgramming Works  :How a programming language works, along with basic terminology. Representing Words, Numbers, and Values with Variables  :How variables store values and represent information, along with how to use variables.
  • 4.
    On its own,a computer isn't very smart. A computer is essentially just a big bunch of small electronic switches that are either on or off. By setting different combinations of these switches, you can make the computer do something:  for example, display something on the screen or make a sound. That's what programming is at its most basic—telling a computer what to do.
  • 5.
    s  A programminglanguage acts as a translator between you and the computer. Rather than learning the computer's native language (known as machine language), you can use a programming language to instruct the computer in a way that is easier to learn and understand.
  • 6.
    What is aProgramming Language? A programming language acts as a translator between you and the computer. Rather than learning the computer's native language (known as machine language), you can use a programming language to instruct the computer in a way that is easier to learn and understand. A specialized program known as a compiler takes the instructions written in the programming language and converts them to machine language. This means that as a Visual Basic programmer, you don't have to understand what the computer is doing or how it does it. You just have to understand how the Visual Basic programming language works.
  • 7.
    The language youwrite and speak has structure: for example, a book has chapters with paragraphs that contain sentences consisting of words. Programs written in Visual Basic also have a structure: modules are like chapters, procedures are like paragraphs, and lines of code are like sentences. When you speak or write, you use different categories of words, such as nouns or verbs. Each category is used according to a defined set of rules. In many ways, Visual Basic is much like the language that you use every day. Visual Basic also has rules that define how categories of words, known as programming elements, are used to write programs.
  • 8.
    Written and spokenlanguage also has rules, or syntax, that defines the order of words in a sentence. Visual Basic also has syntax—at first it may look strange, but it is actually very simple. For example, to state "The maximum speed of my car is 55", you would write: Car.Speed.Maximum = 55
  • 9.
    Variables are animportant concept in computer programming. A variable is a letter or name that can store a value. When you create computer programs, you can use variables to store numbers, such as the height of a building, or words, such as a person's name. Simply put, you can use variables to represent any kind of information your program needs.
  • 10.
    There are threesteps to using a variable: Declare the variable. Tell the program the name and kind of variable you want to use. Assign the variable. Give the variable a value to hold. Use the variable. Retrieve the value held in the variable and use it in your program.
  • 11.
    Declaring a Variable Whenyou declare a variable, you have to decide what to name it and what data type to assign to it. You can name the variable anything that you want, as long as the name starts with a letter or an underscore. When you use a name that describes what the variable is holding, your code is easier to read. For example, a variable that tracks the number of pieces of candy in a jar could be named totalCandy
  • 12.
    You declare avariable using the Dim and As keywords, as shown here. This line of code tells the program that you want to use a variable named aNumber, and that you want it to be a variable that stores whole numbers (the Integer data type). Because aNumber is an Integer, it can store only whole numbers. If you had wanted to store 42.5, for example, you would have used the Double data type. And if you wanted to store a word, you'd use a data type called a String. One other data type worth mentioning at this point is Boolean, which can store a True or False value. VB Dim aNumber As Integer
  • 13.
    Here are moreexamples of how to declare variables. Note: You can create a local variable without declaring the type of the variable by using local type inference. When you use local type inference, the type of the variable is determined by the value that is assigned to it. For more information, see Local Type Inference. VB Dim aDouble As Double Dim aName As String Dim YesOrNo As Boolean
  • 14.
    You assign avalue to your variable with the = sign, which is sometimes called the assignment operator, as shown in the following example. This line of code takes the value 42 and stores it in the previously declared variable named aNumber. VB aNumber = 42
  • 15.
    Declaring and AssigningVariables with a Default Value As shown earlier, you can declare a variable on one line of code, and then later assign the value on another line. This can cause an error if you try to use the variable before assigning it a value. For that reason, it is a better idea to declare and assign variables on a single line. Even if you don't yet know what value the variable will hold, you can assign a default value. The code for declaring and assigning the same variables shown earlier would look like the following.
  • 16.
    VB Dim aDouble AsDouble = 0 Dim aName As String = "default string" Dim YesOrNo As Boolean = True
  • 17.
    Try it! In thisexercise, you will write a short program that creates four variables, assigns them values, and then displays each value in a window called a message box. Let's begin by creating the project where the code will be stored. To create the project 1. If it is not already open, open Visual Basic from the Windows Start menu. 2. On the File menu, click New Project. 3. In the New Project dialog box on the Templates pane, click Windows Forms Application. 4. In the Name box, type Variables and then click OK. Visual Basic will create the files for your program and open the Form Designer. Next, you'll create the variables.
  • 18.
    To create variablesand display their values 1.Double-click the form to open the Code Editor. The Code Editor opens to a section of code called Form1_Load. This section of code is an event handler, which is also referred to as a procedure. The code that you write in this procedure is the instructions that will be performed when the form is first loaded into memory. 2. In the Form1_Load procedure, type the following code. VB Dim anInteger As Integer = 42 Dim aSingle As Single = 39.345677653 Dim aString As String = "I like candy" Dim aBoolean As Boolean = True  This code declares four variables and assigns their default values. The four variables are an Integer, a Single, a String, and a Boolean. Tip: As you typed the code, you may have noticed that after you typed As, a list of words appeared underneath the cursor. This feature is called IntelliSense. It enables you to just type the first few letters of a word until the word is selected in the list. Once the word is selected, you can press the TAB key to finish the word.
  • 19.
    3. Beneath thecode you wrote in the previous step, type the following.  This code tells the program to display each value that you assigned in the previous step in a new window, using the MsgBox function. 4. Press F5 to run your program. Click OK for each message box as it appears. Note that the value of each variable is displayed in turn. You can close the form by clicking the x in the upper-right corner of the form. After the program has finished, you can go back and change the values that are assigned in the code—you'll see that the new values are displayed the next time that you run the program. VB MsgBox(anInteger) MsgBox(aSingle) MsgBox(aString) MsgBox(aBoolean) Note:Whenever you represent actual text in a program, you must enclose it in quotation marks (""). This tells the program to interpret the text as actual text instead of as a variable name. When you assign a Boolean variable a value of True or False, you do not enclose the word in quotation marks, because True and False are Visual Basic keywords with special meanings of their own.