DCA201 Notes Unit 1
DCA201 Notes Unit 1
DCA201 Notes Unit 1
Unit I
When Windows Programming (writing programs that run on Windows OS) was very tough and
was confined only to a few people who were good in C and C++, Visual Basic hit the market and
changed the way one would look at windows programming. Visual Basic made windows
programming so simple, even a novice started writing one or two programs for windows in
Visual Basic.
Visual Basic creates standard .EXE file that you can distribute and deploy on any machine. VB
allows developer to access windows API, which gives all the power of windows.
Database Application
Visual Basic allows you to create front-end portion of Client/Server applications, and application
servers in three-tier client/server applications. You can access any database using ODBC and
OLEDB interfaces.
ActiveX Component
Visual Basic allows you to create reusable software components based on ActiveX technology.
Internet Application
Visual Basic allows you to develop application that can run on Internet and Intranet. Support for
Internet application has been enhanced in Visual Basic 6.0 by adding two new project types –
DHTML application and IIS application.
The following are the three editions and what they provide to developers. The editions are
discussed in the order of features.
Learning Edition
Allows programmers to easily create powerful applications for Microsoft Windows and
Windows NT. It includes all intrinsic controls, plus grid, tab, and data-bound controls.
Professional Edition
Provides a full-featured set of tools for developing solutions for others. It includes all the features
of the Learning edition, plus additional ActiveX controls, the Internet Information Server
Application Designer, integrated Visual Database Tools and Data Environment, Active Data
Objects, and the Dynamic HTML Page Designer.
Enterprise edition
Allows professionals to create robust distributed applications in a team setting. It includes all the
features of the Professional edition, plus Back Office tools such as SQL Server, Microsoft
Transaction Server, Internet Information Server, Visual SourceSafe, SNA Server, and more.
When you start Visual Basic IDE, you are prompted to select the type of project - more on this
later in this chapter.
Components of IDE
Visual Basic’s IDE has a collection of components. Each component has a specific task. For
example, Project Explorer is used to display the components of the project. And properties
window allows you to view & change properties.
Menu Bar
Displays the commands you use to work with Visual Basic. Besides the standard File, Edit,
View, Window, and Help menus, menus are provided to access functions specific to
programming such as Project, Format, or Debug.
Context Menus
Contain shortcuts to frequently performed actions. To open a context menu, click the right mouse
button on the object you're using. The specific list of shortcuts available from context menus
depends on the part of the environment where you click the right mouse button. For example, the
context menu displayed when you right click on the Toolbox lets you display the Components
dialog box, hide the Toolbox, dock or undock the Toolbox, or add a custom tab to the Toolbox.
Toolbars can be docked beneath the menu bar or can "float" if you select the vertical bar on the
left edge and drag it away from the menu bar.
Toolbox
Provides a set of tools that you use at design time to place controls on a form. In addition to the
default toolbox layout, you can create your own custom layouts by selecting Add Tab from the
context menu and adding controls to the resulting tab.
Properties Window
Lists the property settings for the selected form or control. A Property is a characteristic of an
object, such as size, caption, or color.
Object Browser
Lists objects available for use in your project and gives you a quick way to navigate through
your code. You can use the Object Browser to explore objects in Visual Basic and other
applications, see what methods and properties are available for those objects, and paste code
procedures into your application.
Form Designer
Serves as a window that you customize to design the interface of your application. You add
controls, graphics, and pictures to a form to create the look you want. Each form in your
application has its own form designer window.
Control Statements are used to control the flow of program's execution. Visual Basic supports
control structures such as if... Then, if...Then ...Else, Select...Case, and Loop structures such as
Do While...Loop, While...Wend, For...Next etc method.
The If...Then selection structure performs an indicated action only when the condition is True;
otherwise the action is skipped.
Syntax of the If...Then selection
If <condition> Then
statement
End If
Syntax of the If...Then...Else selection
Method 1
Method 2
e.g.: Assume you have to find the grade using nested if and display in a text box
e.g.: Assume you have to find the grade using select...case and display in the text box
average = txtAverage.Text
Select Case average
Case 100 To 75
txtGrade.Text ="A"
Case 74 To 65
txtGrade.Text ="B"
Case 64 To 55
txtGrade.Text ="C"
Case 54 To 45
txtGrade.Text ="S"
Case 44 To 0
txtGrade.Text ="F"
Case Else
MsgBox "Invalid average marks"
End Select
Procedures & functions in Visual Basic
In this part of the tutorial, you will learn Visual Basic procedures & functions.
We use procedures and functions to create modular programs. Visual Basic statements are
grouped in a block enclosed by Sub, Function and matching End statements. The difference
between the two is that functions return values, procedures do not.
A procedure and function is a piece of code in a larger program. They perform a specific task.
The advantages of using procedures and functions are:
Procedures
Option Strict On
Module Example
Sub Main()
SimpleProcedure()
End Sub
Sub SimpleProcedure()
Console.WriteLine("Simple procedure")
End Sub
End Module
This example shows basic usage of procedures. In our program, we have two procedures.
The Main() procedure and the user defined SimpleProcedure(). As we already know,
the Main() procedure is the entry point of a Visual Basic program.
SimpleProcedure()
Sub SimpleProcedure()
Console.WriteLine("Simple procedure")
End Sub
Option Strict On
Module Example
Sub Main()
Dim x As Integer = 55
Dim y As Integer = 32
Addition(x, y)
End Sub
End Module
Addition(x, y)
Here we call the Addition() procedure and pass two parameters to it. These parameters are two
Integer values.
Functions
There are two basic types of functions. Built-in functions and user defined ones. The built-in
functions are part of the Visual Basic language. There are various mathematical, string or
conversion functions.
Option Strict On
Module Example
Sub Main()
Console.WriteLine(Math.Abs(-23))
Console.WriteLine(Math.Round(34.56))
Console.WriteLine("ZetCode has {0} characters", _
Len("ZetCode"))
End Sub
End Module
In the preceding example, we use two math functions and one string function. Built-in functions
help programmers do some common tasks.
Option Strict On
Module Example
Dim x As Integer = 55
Dim y As Integer = 32
result = Addition(x, y)
Console.WriteLine(Addition(x, y))
End Sub
End Module
Two values are passed to the function. We add these two values and return the result to
the Main() function.
result = Addition(x, y)
Addition function is called. The function returns a result and this result is assigned to the result
variable.
This is the Addition function signature and its body. It also includes a return data type, for the
returned value. In our case is is an Integer. Values are returned to the caller with
the Return keyword.