Programming
Fundamental Lab
Lecture 1
Dastan Faruq Ismail
dastan.faruq1995@gmail.com
Outline
Introduction:
Computers, Information, and Information
Processing
Software vs. Hardware
Programming Languages
Interpreted vs. Compiled Languages
Visual Basic (VB)
VB.NET
Our IDE for Windows Applications: Visual
Studio.NET
Introduction
Basic Operation
Introduction to Basic Program
Design
Basic process for program preparation
Simple Example: ‘Hello World’
Programming
Languages
Many Programming Languages have been
developed.
Some well-known compiledHigh-Levell
Languages include (older to newer):
Programming Languages
Many others, including interpreted languages:
Python, Perl, Ruby, etc
Languages allow communication between humans
and computers…
This involves converting abstract algorithms for
solving problems into a form
understandable by the computer.
An ‘executable’ (i.e., run-able) form.
Such a converted algorithm is called a program.
The people that do the conversion (at the
high level) are us…the programmers.
Visual Basic vs.
VB .NET
BASIC
Beginner’s All-purpose Symbolic Instruction Code
Developed as an extension of C, to be a general-purpose
programming language.
Visual BASIC (VB)
BASIC + a Graphical User Interface (GUI)
Greatly eases the creation of Windows applications
Especially, by facilitating the use of re-usable components
Visual BASIC .NET
A programming language based on VB 6.0
Working on the .NET framework of the Microsoft
Corporation
A Platform for cross-language development (C#, VB. NET, C+
+, F#)
Includes a large standard library called the BCL (Base Class
Library)
Visual Studio
Starting Visual
Studio
Go to Programs 2012
> All Programs > Microsoft Visual Studio 2012
(click)
After a few moments, Visual Studio 2022 (VS 2022) should
open…
With the Start Page shown in the central window.
As shown, there are shortcuts for Project Creation and
Project Opening, here…
One way to quickly
make a new project is
by clicking the ‘New
Project’, shortcut,
here…
Shortcuts for
opening your
Recent Projects
can also be
useful…
Creating a New Project
Instead, let’s create a new Visual Basic Project using
the VS Menu…:
First, open the VS 2012 Menu > File Tab and click
‘New Project’…
The New Project Dialog will appear (see next slide)
…
Creating a New Project
(cont.)
Use the ‘New Project’ Dialog to set the new project’s type, name,
etc:
1. Select the Visual Basic Templates from the left-hand
window…
Then, select ‘Windows Forms Application’ as our project
type.
2. Choose a Name and Location to store your Project; for now…
Keep the default Project Name (WindowsApplication1) and
Location (later, copy to your USB)
3. Finally, make sure ‘Create a directory for Solution’ is
checked…
And press OK …
Visual Studio 2012 Main
Screen
The main screen will
appear:
Solution Explorer
Open Projects are
listed
here…
Properties Window
Properties available
for the selected
object are listed
here…
…used to set Form
and
Control Properties.
Windows
ToolBox Window
Form
Contains reusable Designer
components for your We will draw the
application. project interface
here…
Visual Studio Main
Screen (cont)
Double-clicking the Design Window brings up the
Code Editor.
This shows your project’s current VB code.
Code Editor
Window
The Project’s current code
is displayed here…
Note that you can
return to the Form
Designer by clicking its
Tab…
Output
Window
Results,
information, and
error messages
displayed here…
Flow Chart for Program
Preparation
In this course, we will build VB projects an Incrementa
Development Process
Let’s Make a Simple
Program
We start by making a Program Plan:
A simple description of the desired characteristics
and functionality.
Often includes an efficient method of solution
(algorithm)
Example: a plan for adding two decimal
numbers.
Simple ‘Welcome’ program (plan):
Program purpose: Display a simple message;
exit.
We will use 2 Buttons (each called a ‘Control’)
We will use Visual Studio’s Design Window to
create these.
Let’s Make a Simple
Program
Desired functionality (program behavior):
TextBox: Allows our user to input his/her name
Clicking Button 1 (‘“Welcome” Button):
Display ‘Hello <User Name>! Welcome to
Visual Basic.’
Clicking Button 2 (‘Exit’ Button):
Exit (close the program)
We will add each Control to our Form using the
Design Window…
…and then add some simple VB .NET code.
Step 1: Making the
Project
Click ‘New Project’ in the start screen to display the
New Project Dialog:
Choose settings to make a VB Windows Form
(WinForm) Project, as below:
Name your project ‘Welcome Project’; also, keep
Type of
your default location.
Application
Type of Project
Project Name
and Location
Step 2: Form and Controls
Arrangement
We now add 1 Label , 1 TextBox, and 2 Buttons to
our form…
Step 2: Adjust the properties
Step 3: Setting Control
Adjust the Properties of each Control…
1. Select the desired control (by single-clicking)
Its Properties will be shown in the Properties
Properties
Window
2. Click each desired Property, one by one.
(Name) = Form1
Text = Hello Visual
Basic!
(Name) = Label1
Text = Enter Your Name
(Name) = txtWelcome
Text =
(Name) = (Name) =
btnOK Text = btnExit Text =
OK Exit!
Notice the distinctive way we name
our Controls…
Step 4: Adding Program
Code
Now, let’s add the VB code to make the program
work…
We do this by coding a Subroutine (mini-program)
for each active Control.
By “active” we mean a Control that will be
coded by us to respond to user input.
This type of Subroutine is called an Event Handler.
Let’s make our Program respond when a user clicks
btnOK
To get started, just double-click the Control, btnOK
in the Design Window...
This takes us to Code View and gives us an
empty Event Handler (red box)
Step 4: Adding Program
Code
Next, we will add code here!
Next, we will add VB code to Handle the Click Event
of btnOK…
Events are identified as ControlName + . +
EventName btnOK.Click
Event Handers are named similarly, but using an
underbar btnOK_Click
Step 4 (cont.): Adding
Program Code
Now, add the VB code below to btnOK_Click:
Note: Any code we put it in btnOK_Click will
execute whenever btnOK is pressed, one time
from top to bottom.
Here, we will display a small MessageBox to
welcome our user.
The 1st line (green text) is a comment statement,
which does nothing.
The 2nd line, MessageBox.Show() accepts 2
arguments separated by a comma and a
Step 4 (cont.): Adding
Program Code
1.Here, the 1st argument makes a String to hold our
message, in 4 steps:
a.First, we make a short String (“Hello “)
b.The user’s name is then fetched from the Text
Property of txtWelcome
c.We then make a third String: ” Welcome to Visual
Basic!”
d.Our message is then made from these 3 Strings
using the & operator.
2.The 2nd argument specifies the text for the Title Bar
of the MessageBox
Step 4 (cont.): Adding
Program Code
Next, let’s add the VB code for btnExit_Click:
First, return to the Design Window (left tab), and
double-click btnExit.
Next, add the code shown below to your new,
empty Event Handler:
Here, we are coding to let the user exit our
program by pressing btnExit.
Using a single VB Keyword End
Step 4 (cont.): Adding
Program Code
This style of programming is known as “Event Driven
Programming”
In this style, our program behaves like a simple
automaton (robot)…
It waits for one of our defined user Actions to
happen…
1.User Clicks the OK button (btnOK)
2.User Clicks the Exit button (btnExit)
Then, it responds to each action by executing the
corresponding Handler.
Step 5: Program Testing
Click the green triangle (Start) to Compile and Run your
Program:
Here, Compiling means taking your VB source code and
converting it into
a machine-usable form.
Then, test your program (as the User):
1. First, type your
name in
txtWelcome…
3. Press btnExit to
Exit the Program
2. Press btnOK to
show the Welcome
Step 6a: Saving the
Program
To save your Program (Visual Studio Solution):
1. Select ‘File’ from the Visual Studio 2102 Main Menu…
2. Select ‘Save All’ to save all files (note: there is no general-
use ‘Save As’).
To confirm, first check your Visual Studio Projects
Folder:
MyDocuments > Visual Studio 2012 >
MyProjects > Welcome
Project
Here, you are in your ‘Welcome Project’ Solution
Folder, and you will see :
The ‘Welcome Project’ folder is your Project
Folder
Note: You have only 1 Project in this
Solution.
‘Welcome Project.sln’ is your Solution File
Step 6b: Confirming the
Save
Next, let’s find your
executable file …
( = Welcome Project.exe )
First, enter your Project
Folder…
Then, enter your Project’s bin folder to view your
exe file.
You may run your program directly by clicking this
icon…
Note: your Project will NOT open.
Using Visual Studio Help
Visual Studio 2012 features an extensive set of Help Tools,
including:
A Window-based Help System allowing you to view
documentation;
An intelligent, programmable tool-tip based system called
Intellisense
You will become familiar with Intellisense as you gain
experience; however, be aware that you may access the VS
Help Window in several ways:
1.Through the Visual Studio Main Menu (> Help > View Help):
Summary
In this lecture, we have discussed:
Computers and Information Processing
Programming Languages
Visual Basic (VB .NET)
We have also learned the basics of using Visual Studio 2012,
our Integrated Development Environment (IDE):
How to use the ToolBox to place Controls in the Designer
Window.
How to set Control Properties
How to add code to your Form in the Code Window.
How to build (compile), run, and view your code.
How to get help.
And we also made and ran our very first VB Application:
Welcome User
THANK YOU