chap 1
chap 1
e s e... la n g u a g e o n s u s in g la n ~ s L ib ra ry ~ ~ e nt~
o ri e n te d p a ra s a re c a ll e d
. E T c o m li a n t
a g e s h k e V is
u a l B a s ic L). lt
'0
d ig m . All th e la n g u a g e a
c o m m u n ic a te s e la n g u a g e s n d
w it h e a c h o th a re a b le to· a c c e s u p p o ~C# _anu
P ro g ra m s w ri e r. T h e re is n s s t e fr a m e
tt e n u s in g .N o .NET la n g u a g w o rk a s obJeq_
ET c o m p li a n e w it h o u t th
d e a li n g w it h
th e ?s_ it se lf i F ig u re t la n g ua g e s d
1''7. ·s h o w s t~ e e a l w it h .NE
e
T
.N
c
E
o
T F r Well a~
d e _amework.
a rc h it e c_tu re
o f .N E T Fram
ew:-~~ead Qf
Figu re 1.1: Archite
cture of .NET
Framework
\V B \ \c++\ ~ \ JScript \ \ M a n y m o re
.... \
Languages
S u pp ort ~
.NET F ra m e w
o rk C la s s L ib ra ry
fo r A p p li c a ti o
COMMON LA n s lFCL)
NGUAGE RUN
TIME (CLR)
\
\c T s \ \c L s \
\ J IT \ \ GC \
\M e ta d a ta\ \A
s s e m b li e s \
Runs on
O p e ra ti n g S y
s te m
T h e m a in c o
m p o n e n ts of
.NET F ra mew
► Co m m o o rk a re :
n L a n g u a ge
R u n ti me (CLR
► .NET F ra )
m e w o rk C la s
s L ib ra ry (FC
L)
overview of Visual Stiwio .NET IIJ
ill~ Common Language Runtime (~LR)
' Common Language Runtime (CLR) is the !virtual machine componeny of .NET
Framew~. It provides runtime environment for all types of .NET applications. The
source code of applicatidns de ~ ed usmg .r{ET compliant languages is c-0mpiled by
that language's compiler ~r:_to ~tgi_intermediate Jan~age ~alf_:3
_MSI~ (Microso_ft
Intermediate Language) or In·erme 1a e an.cc . . .,co.cc-. . 1: c0ctet!Y"platform
independent. It is comparable to byt~code in Java. Metadata is also g~nerated 'durjng
compilation along with MSIL code and is stored· in a file kri wn as Manifest fi . This
i ~ etadata }J generally about.members, types which are require y CLF for execution.,of
MSIL code. A Just-in-Time (JIT) compil~inporient'-of CLR converts MSIL code intQ
native code of t:1e machine. ~his code is platform dep~f CLR manag~s me~ory,
threads, exception&..-.c_o de-exe@tion, c o ~, verillcation and compilation . Figure '
1.2 shows the conversion of source code mto native code.- - -
Figure 1.2: Converting Source Code Into Native Code.
~
The main components of CLR are: ~ C/ L)
, Common type System(CTS)
, Common Language Specification(CLS) /
, Garbage Collector(GC) .../
, Just in Time Compiler (JIT)
, Metadata and Assemblies ./
r
(i) Common Type System (CTS): Common Type System (CTS) provides
I _.. •
guidelines for decl~uing,_using and managing data types at runtime .. It offers
cross-language communication. For exampll (VB.Nlfr has 'Integer' data type
and C# has 'int' data type for managing integers. After compil~tion, 'lnt,32: is
used by~both d~ typ,Vo, CTS provides the data typ: s used by managed
code (code compiled using the .. NET Framework). Cbmmon Type System helps
in writing language-independent code. It provides two categories of Types.
• Value Type: A Value Type sto_res the data in memory allocated on the
stack or inline in a structure. This category of Type holds the data directly.
If value of one varia_~ ~ - ~.Qpied to Qffiyr, both tp_e__~ab~e~ st.9re data
independeney. It can be of built-in types, user-defined or enumeration
types. Built-in types are primitive data types like numeric, b_o olean, _Ehar
-
and date. User-definecf types are created by users in the source code. An
enumeration refers to set of enumerated values which are represented by
labels but sto:r:ed as a numeric type.
◄
dynamic memory aHocation. Reference Type does not hold actual data
directly but h-elds - address ·of data. Whenever a copy_ Qf _Refe~enc~ ! YJ?e
object is made, it copies addre-ss and not actual data. Therefore two
variables/ obje~ts will refer to same data. ff data of one Reference Type
object is changed, · the same· is reflect'ed for the other obje~t. Reference
Types can be self:-desctibing types, pointer 'types or interface types. The
self-describing types may be strin&__fil.ray and class types which store
metadata about themselves. .. . ... ---
'
The Figure 1.3 shows the difference between Value Type and Reference
Type.
I
VB. Net Statement&- .. --r r.
Dim cnt as Integer = 4 ~ ---- •·· .... ~
Dim tmp as Integer= 30 , - ~ .... . ,:J. Value e
Dim langname as String= VB.Net'
I
--
,, - - - - - - - - - - _.._ - - - - - - - - -- -·- ....
,------ --- -- - --,
I STACK
~--------, /I
I
HEAP
\
I
I
cnt 4
II ~ - - ----,
II
1
I VB.Net '
I
tmp 30 I
I I
I I
langname String Refere~ce I I
I
f I i
\. _________________ ~ _______ .,../ I
\ - ---~-- - - - - - - _..✓
/
Reference Type
J
OVeruiew of Visual Stiroio .NET
CLR. It converts the MSIL code into native code (i.e. machine specific code).
The . .NET program i~ c~rppfled either explicitly or implicitly. In explicit
compilation, developer or· progi:~mer calls.a .part .Jf.µl~ mpiler to compile
the · program. In implicit co11?,pi!a_ti~I), the~ program is compilecj. twice. The
source code is compiled· into Microsoft Intermediate Language (MSIL} during
-- first compilation' process. In I se~~md compilation pro~ess, the MSIL code is
converted into native code: This process is.called JIT compilation.. There are
three . types of JIT compilers \ -Pre Econ and ,....Norm;}) Pre JIT iJer
comp1 es en ire code into native code befor execution. ono JIT
Compiler compiles only those parts of MSIL code which are re wred duong
executio~ and remove those parts which are _not _ITquired @ Y mo~ No al
JIT Compiler also compiles only those parts of MSIL code which are require
during execution, but places them in cache for future use. It does not require
recompilations of already used parts as they_ have _b_ee!} _elaced in cache
memory-:- ·
(v) Metadata and Assemblies: Metadata is Tbinarv informatiod about the
program, which is either stored in a CLR Portable Executable file (PE) along
with MSIL code or in the memoty. During execution of M$IL, metadata is also
loaded into memory for proper interpretation of cla§_s_es_ an<L._r~lated
information used in code.So, metad~t~ is nelpful in ~femei).ting code in
language-neutral mannel'orin achieving language interoperability.
- --~. - . . - - - -·- ~
-
security permissions anci~ any in-ore~ -- - - ~ ----- -
When an application developed using .NET framework language is executed , it
creates one or mor~ assemblies which are run by CLR. CLR needs version and
_./
permissions information alon~ wi! 1rj fi:e ~~-!~ ,Eo~~ So~ ~ e!!}hly ..also
includes manifest. An ! ss~bly mapifegju;.o..mmhl_Llo_ a table _of contents
having nameaiid version of the assembly. The manifest also includes list of
other assemblies to be used by the current assembly and security information
to manage security issues. An assembly also includes modules. Each module
is an internal file havin·g ready to execute MSIL code. So, each module
contains types i.e. classes and interfaces used in the corresponding source
I
I\ code. Assembly also includes information about how its various modules
interact with each other. So, an assembly is complete unit of information that
CLR is able to execute.
,, U~man~ged Code'. The code developed ~-qtsi~e .NET Framework and compiled
directly mto machme language is called/unmanaged code. S_uch code fioes not]
run under the control of the GLR, but runs under proces~ of Operating system.
For example, code written in C++. for accessmg low level functions of the
operating system. The .NET Fr~~work does not provide direct backward
compatibility to code written using older versions of languages like VB, C++, but
through unmanaged code.
Source Code ( •• .. .. • t
· • Others
Operating System
~
r-m overview of Visua( Stiwio.Nl:.l'
(ii) Cros s Language Interoperability: The .Net
Fram ewo rk prov ides supp ort
. fo~ ss lang uage inte roperat:nficy whic h impl ies code
writ ten in one language
can be used by anot her lang uage . For exam ple, code
writ ten in VB.NET can be
used .with the mod ules developed in C#.NET.
(i!j;) Developer Productivity: Due to cros s lang uage inter
oper abili ty, developer
can us.e . any._ .NET .language of his choice for
deve lopm ent, whic h in turn
incr ease s pro.ductiyi_ty ,__ Mon ~ov~r, __n:umerous ..in.,b
uilt ..clas ses- and . reus ing of
existing class es mak e the application development
easy. For exam ple, Visual
Basi c is referred as RAD lang uage whe re RAD
stan ds for Rapid Application
Development.
I "1lvj Performance: Its CLR environment promotes
safe exec ution of co~ ,
eliminate ~.per:_f_<:> rman ce bottl en~ ~ ~~rough ~!~
~~~~ r, min~m~es
\ sof~ are developm ent con'Ilicts thro ugh n0-!!!~§Qa<;_~~
conflicts thro ugh assembly manifest. ·
~~ p- , . . . . r ~
l:!.V01ds verSJomn g
Configuring teed...
'· .
► Select location and type of installation (Default) and then click on 'Install'
button. It will prompt for confirmation . Click on 'Yes' button as shown in Figure
1.6.
- Figure 1.6: Choosing Location and Installation Type
► First time when Visual Studio is launched, it prompts user to sign in to VisuaJ
Studio. For signing, click on link - 'Sign in', otherwise click on the li nk • 'Not
now, may be later' as shown in Figure 1.9.
.I
c<i Visual Studio I
W el_c orne. Sign in 10 Visua l Studro.
V,\u,11 ~\ol'Ci•o ~.. ,u ~t,11n.,1,,.-t!-. l , ~ ~e-- t-;,rf"d ,'\ \,-. , .....
:rt"11n1~ t ~<1"1'1 :lr-·,,e--_ ~,.;t cc1v•~ C1 ~.: .:,,,h""C ck-,4. :,:,e, "" .._,_..,,
1'
Stan
Featured Videos
We 1 rt: urwbk 10 d owN01d conlr.nl due l o n~ wori: tau~ .
c, Sn1pP"'9TOOI
kt:cp P•9t' opt11 1ffe, ptOJffi
lc1d1
✓ She. p11 , on "1•,tup
► Now an applica tion can be d evelope d using Visual Studio. The Start Page of IDE
consist s majorly of the followin g options .
(iJ The New Project : This helps in creatin g new project s. Various
applica tions can be built using differen t program ming languag es __like
Visual Basic, Visual C#, Visual C++, Visual F#, JavaSc ript, Python etc.
(HJ The Open Project s: This shows a lis t of recently create d/used projects .
For openin g an exis ting project, Click on Open Pr ojects.
(iii} News: This section provide s latest online news, announ ces new release s.
and update s.
overviewof Visual Stumo .NET
~,~·.
,-v■
Elltensibility Shared Projtct Visual Basic
lightSwitch
IE'lj
Offic<!SNrePoint (l~VI Class Libra,y Visual Basic
Stlvtrlight
Test Clm Libra,y (Portable) VLSual Basic
WCF
Woritflow
~ Typexript
t Other Languages
t Other Projtct Types
Samples
~ Online
.---~
OK II C.ncd :
F~llow the steps given below 8:!'t er Clicking on New Project option.
- ·--- -----
.. _
(i) Select Visual-Basic from Templates (First Pane)
-
(ii) Select Windows (First Pane)
(iii) Select Wirldows Forms Application (Middle Pane)
(iv) Type the name of project as FirstWindowApp (Bottom Pane)
(v) Click OK button.
After creating a new solution in previous step, Visual Basic.NET IDE appears as
-
shown in Figure 1.13. The Title bar indicates the name of solution specified ir1 the
previous step. This screen displays Form window, Solution Explorer wirldow and
Property window besides many other menus, tabs and windows. Developer can now
start designirlg of GUI to develop applications using Visual Studio .NET.
f
Figure 1.13: First Screen after creating a new Solution in Visual Studio 2015
DiQ r w a ~ • Mtc1e1oft VllualS1Wio
[~t io• Y•- e~JKI 11'-"d Qtbug Tum F~INI Iocff ~T111 - ~IJ'l!. , 'P':'6°"' . ~P_____ _.. _
C • ,1 ~ • ~ Iii ~ t \ '} • 1' • Otbu~ • /1..,., CDlJ • · ► StMI • 1 • ! ~ /f :
: Form I ,·b IOwgnl "' l(
IF=-
~ , , ,.,., • r
I> ,
B ,.,.___,
; Myolro,e~
t • • P.dtnnee
.,: , i.~.n rl-9
I> £:i h,mi l....ti
r- 1 !r,'flan.Wr.OOw"JO/fff'rU'Otffi
I,,,
:!! ~•_.!?.. f
R.rloldt1. ~-o..e ,...
~ !ton ,-
131c,
Sho,,,ffli ~t
'~
)IXl;.:.o
Sc,Gnpl<yl,
StJ:ftFO$.CJ(ln
"""'
~Jl,llttoc~
1,.
Tm ,-,
,.,,.
TOf1M011
1,..,
lht l c.olH!.0<,.lf'd••·•tt1lh<l! CCfClol
Q T~ her~ to Y-arc.h 0
The Visual Studio IDE includes various windows. The main windows of IDE
are described as follows.
(i) Form/Design Window: On creating a new project, a Form is displayed in
middle pane as shown in Figure 1.13. '-3 Form is also considered a
control by itself. It has 'Forml' written in its Title Bar. The default
Form is an object and an instance of the System.Windows.Forms.Form
class of System names ace. Click anywhere in the Form's empty space,
then Form l's r roperty window hows its properti@like Name, Text, Size,
Font, Location, oreground coloF, background color, MaximizeBox,
MinimizeBox etc. These properties can be changed by typing a value or
selecting a value from a drop-down list. The title of the Form is defined
by the Text property and its default value is Form 1. To change the
Form's title, click in the box on the right of the Text property and type
text. Title always appears in the- title bar of Form window. 'Forml ' is also
used as the default name for the Form and it· can be changed by
changing its Name property. The current Form is represented by the
name 'Me' in coding. For example,
Me.Text="Sample Title of Form"
-'
(ii) Toolbox:[oolbox acts as a palette) It contains many controls that~ be-
placed in Visual Studio forms for designing Graphical User Interfac/ /
Controls are categorized further into ten different categories such as AH ,
Wi~dows Forms, Co~ mon CQ.ntrols, Containers, Menus & toolbars, Data,
Components, Printing, Dialogs -'and W'PF!nteroperability and Gerier'al.
r-- .--- ..-- .
_)
overoiew of Visual Stiwio .mr
Generally, Toolbox is shown on the left side of Visual Studio IDE. The
developer can drag a control from Toolbox and drop it on the already
open FormJTo see the commonly used controls, click on 'All Windows
Forms'. The partial list of controls is shown in the left pane of Figure
1.14.
Forml vb (Oosign] ~ X ·
- ----- ·-- • q X
p .
,. All Windowt. Forms ... •9 Forml
'" Pointer ; I
if' 81ckgroundWorkor f
~• BmdingNavigator
iil BindmgSource
Iii! Button
liZ] ChockBo,
I: Check<dlrstBox
{i,:', ColorDialog
~ ComboBo,
0 ContO't.MenuStrip
~ D,t,GridView
OateT,mePiclcer
(ill, Propertie1 Window: It displays all the properties and their current
settings related to the selected control. The properties window comprises
Object drop-down list, List of properties and the Bottom section.
► Object drop-down Lilt: In the properties window, the item that
appears at the top part of the property window is the control currently
► --
selected. -
Li1t of Propertie1: It describes property name in left column and its
present state in right column. Every time a user selects a control
either from the Form or from Object drop-down list, its corresponding
properties are shown in the window. State of any property can be
changed either at design time or run time. Change the properties of
the Form at run time by writing the . relevant code. For example, the
property of the object ·can be defined by writing the object's name
followed by a dot and property name.
Me.Text="Sample Title of Form"
Me.MaximizeBox=False
Me.MinimizeBox=False
/D :,. The Bottom Section: It shows a description of the selected property.
~ Solution Explorer: 1Solution r provides an organized view f
. / r ]Tim:!8:eicrte
solutions, projects an 1les. t 1s a p ace o er for coir.n~e:]or:
projects and their build or configuration settings. A project is always
OVeroiew of Vwu,l Stltbfo Jilt
Ill
included within a solution. When a new project is created, Visual Stllcti0
creates a solution by default, name as 'WindowsApplication 1' and so
- --- - , on
until the user changes the default name to some otlier name. Solution
name is also shown in the title bar .of Visual Studio IDE. By default, names
of solution and project are same which can be changed and given different
names. Eachproje~t holds the code ~an~ data related ·to a V!sual, Studio
application. More..than one pro}ect caifbe c~ea,ted undeia solutionz ""
Visual ~tudio uses tw~ file typ~~~~4-
.S~f!] for. storing set~ngs related
to solutions: A text file having extension .slrr-aescnbes a solut?on. It.has a
unique format and it is edited by the system automatically. Another1tle
with extension .suo stands for Solution User Options. It is a binary file. It
stor~s user-\evel customized settings like li'st of files op e last
usage of solution or the location ·of breakpoints etc. It is a hidden fi - and
can be seen only if 'show· hidden files' option is enabled for Window
explorer. A project is saved with extension .vbproj .r ·
To access Solution Explorer, select Solution Explorer on the View menu. It
looks like as shown in Figure 1.15.
(v) Data Source: Data Source is used to show the available database
connections. (Database connections as covered later in this book).
(vi) Code Window: The Code Window is used to write, display and edit code
related to a Form. The code window appears either by double-clicking on
any part of the form or selecting 'View code' by right clicking on the
Form. Alternatively, function ~ an be used to bring the code
definition window and press 'S~ to get design wincfow of Form. By
defa:ttlt, the Code window shows the structure of a class 'Form 1', default
name of Form. A class starts with 'Public class' and ends with 'End
Class' keywords.
Public Class Forml
Private Sub Form l_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
End Class
If we get this window b double clicking on any part of the form , it also
includes default event procedure f Form named as Form_Load. An event
-
procedure ~starts wit . 'Private Sub' c!Ild ends with 'End Sub' keywords . The
'Forml' class and the event 'Load' are joined together- with an underscore to
make Forml_Load. Here, it is doing nothing other than loading an empty form .
In the arguments of 'Form_Load' proc~dure, 'Sender' and 'e' are parameters of
event handlers where~ inforiIDttttm aboutthe object which
generated the event and 'e' is the event itse·lf. The code window includes three
drop down l~sts for listing projects, objects of selected controls and events
related to selected object as slio~ in Figure r. 16. '
Figure 1.18: Code Window
Form1.vb* -ll X
~ WindowsApprication1
S Public Class .?~
l Private Sub Forml_Load(s~nder As Object, e As EventArgs ) Handles MyBase.Load
, End Sub
1 End Class
Each window in VS.NET has three icons on its right side-Window Position, Auto
Hide (thumb tack) and .Close as shown in Figure 1.17.
Figure 1.17: Icon• on tht right of a Window
.
,--------
' l\ · -
S.U-, u,,lo,,, •O l(
} "'1,..,.a
positions-to set
windows
----'-"-'-
G Eii1 ~ I ,.1
..:.I
. ::c:z:::·
(iv) Dock: Window is fixed to a dock on any one of the four borders of the window.
If the window is to be docked again, right click on tab, select Dock as shown in
Figure 1.20. Dock option is chosen for Solution Explorer window.
(v) Hide and Auto Hide: If Auto Hide is selected, the window is h~dden as shown
in Figure 1.21. In Auto Hide mode, when window is clicked, the complete
window appears. To bring back the window, click on window, select Dock
option from Window Position as shown in Figure 1.22.
-
I ll INTRODUCTION TO VB.NET
' .
Visual Basic .NET (VB.NET) is an object-oriented programming language su
by .NET Framework. It was launched by Microsoft in 2002. Visual Basic ~:;e_ci
successor to VB6, but it is not backward compatible with VB6. However l~
, 1atest
versions of .NET. framework support- -older versions of .NET Framework. The Wor
'Visual' refers to the visual -appeal of Graphical User Interface (GUI, pronounced It
GOOEY) and the 'Basic' word is taken from an earlier language 'Beginners All Purp0: :
Symbolic Instruction Code'. The word 'NET' stands for network as this language
includes functionality for developing web applications and services. The 2;1am features
of VB. NET are as follows --..
► VB.NET is an object-oriented programming language as it supports classes,
objects, abstraction, inheritance and polymorphism concepts of object-oriented
paradigm.
► VB.NET provides Rapid Application Development (RAD) environment whic
helps programmers in developing applications quickly. Programmers d o n o
have to spend much time on creating appearance of user interface elements
such as TextBox, Label and many more, rather they can be placed on a Fonn
just by dragging and dropping.
► VB.NET enables programmers to develop GUis that can be used as front end for
database related applications. A typical GUI includes visual components such
as TextBoxes, Labels and Buttons. Due to visual appeal, GUI based applications
are preferred over console applications, also called Character User Interface
(CUI) applications.
► VB.NET is an event driven programming language. It allows user in writing code
which is executed"anly when a particular even t fires such as clicking of a mouse
or a key.
► VB.NET supports procedures and functions for supporting modular
programming.
► VB.NET also provides classes to creE!te web applications and web services. It
becomes easy for the user to learn and develop different types of applications
using familiar interface.
)
>
Label Control
TextBox Control
Labell
~ - - - -I~
1 IUtonl
l __ __ _ ,
. .
- - - - - -, - ButtonControl
• q X
l :!! ~' I ~ f I ,.
l ft.lStylt Sundtrd
Text' property of Label is set to jf3 font Miuo,oll S,,ns Sen, ~
'Enter Value'. After setting, it looks J Fo,.Calo< ■ Con1ro1Tet
like as given below. Similarly, the l lm19t ·--- □ ~ --
MiddltC.....,
remaining properties ~ be set~ I IIN9fAlign
lm,9elndo O c-i
lm19<ky o ,-i
J:l Form1 l.,o..:J!' ~ l""'9M1 c,-e)
No
R'9htloldt
-
Tat Enlerv.li,e
TotAign Toplcft
True
&ter Vu -------J
._I I U..Wtit<:ursor Ftlse
Jg ............
Figure 1.24: Design Time layout ot Form, Solution E.xplor9r Ind Property Settlngs
:;=;:-0
Form,- ~~--~c
,,-.~...-= =:,
::;•~fiii1
Solution Explorer • J , Propetbes • i 'JC
(J C I
t'.i'l '(9 • ~ G ~ '® I () , .. ....._, ~Wndow'Jo:-,r~
llseMnemonoc T""
To execute the Form; click on Start button available at top. The Form wi!J start its
execution. Figure 1.25 shows the run time screen. On clicking button 'Click Here·, 8
dialog box with message will appear as shown in the right side of Figure 1.24. When
button Ok is clicked, the control will come back to form. Then click on Exit button to
close the Form. It will stop execution. Project 1.1 shows the code.
~ Form1 D X
Ol
OUeruiew of Vi&JCai ~
Save the project and solution. The files can be saved in default path or th •
h . Th e Path
your c 01~e. e default_path is 'C: \Users\ <user name>\ Documents\Visuai Stu ~!
2015-~ProJects .. Under this default path or path of developer's choice, a folder ~ 10
solution name 1s created. In case of this example, solution name is 'FirstVBNetS 1 . th
and it is stored in e: \ vbprojects folder. The physical structure of this solution :/tioir
a~ shown in the left side of Figure 1.26. The solution file is stored at one level up ~;~
hierarchy as shown on right side of Figure 1.26. t
} bin
. My Project
obj
Name
Y~App
~ FirRVBNetSolutK>n
"
.firstVBNetSofution
·!
.QD F irst.VBNetSolutoon.vbproj ··- --··
. - - -.. _.,.. - -- ....
' .... .,
lib
C,
Forml.Oes.igner.vb
Forn-ol
,gg FirstVBNetSolution
fill Form"l .vb
\
• DEVELOPING CONSOLE APPLICATIONS IN VB.NET \
I
Console applications are also called Character User Interface (CUI) ApJ?lications.
1
Such applications are easy to develop in comparison to Graphical User _Interface (GUij
applications. A console application is used to read input data from console and write
output data to console. The Languages like C and Java support console applications.
A console application in VB.NET is executed in DOS environment and it does not
use graphics. It is considered efficient as it consumes fewer resources. When console
application is executed, operating system provides three input and output streams to
console application named as standard input stream, standard output stream and
standard error output stream.
Console applications use a system namespace called Console. The Console
namespace includes methods required to read input and write output from/to console,
The commonly used methods are described in brief as shown in the Table 1.1.
Method Description
Write This method writes string to standard output.
Writeline This method writes string to standard output followed by a newline
character.
Readkey This method reads one character at a time from standard input.
Read This method reads next character from standard input.
Readline This method reads entire line.
overviewof Visual ~tJWio NET
~ Temp~ tcs
u Windows Forms Applic.ation Vuuc?IB.!s.ic
T,,c ..-~...i S.,-:
A p,o,«J la, a wn;• ,..,.,,..,,... .....
-~ -
.. Visual Brnc
Unrlersal
r··J
•••
ii
IVPF Applic,tion Vau.:I 64sic
'flSUOI Basic
tpplou'. x,n
,....
Console Application
Windows8
Classic Desktop Shared Project lftSual 81SJc
Web
li.').J
Cloud n~••
~~
Cius l ibrary Viwal Bnic
Extensibility
LightSwitch 11~¥8 Clm l ibrary (Portable) Visual Bu,c
Officc/Shi,rePoint ~~
Silverlight
Test
WCF
Workflow
, Typ.Script
t, Other l anguages
L, Other Project Types
S.mplos
P Online
(lick here to 99 onlmc and find templates
Name JFirstConsoleApplicalio~
!ilfirn! C~~
- - ~a ·1;~_.l,1 t
1.26 OVeruiew ~ VisMa{ StJtbio
~
1.8.2 Console Application Example
Write a console application to read two numbers, add them and write output
console. The source code of the Project is shown in Project 1.2. to
Module Module 1
Sub Main()
Console.WriteLihe("Program to add two numbers")
Console.Write("Enter first number ")
Dim no 1 = Console.ReadLine()
'dim is used to declare variable
Console.Write("Enter second number ")
Dim no2 = Console.ReadLine()
Console.Write("Addition is ")
Console.WriteLine(Clnt(nol) + Clnt(no2))
'CINT function is used to convert string to numeric
Console.ReadKey()
End Sub
End Module
The output is as follows.
IE IMPORTING NAMESPACES
A ' namespace is a lo 'cal ouping· of related classes and interfaces of .NET
Framewor . They reside in assemblies, wh1c are ep oyable units containing details
a:bout classes, interfaces and structures. The first part up to the last dot of the full
------=,-----
name of a type indicates the namespace, while the last part specifies the type name.
For example, 'System.window.Forms' contains classes for creating User interface
elements. Namespaces can be used by any application using imports statement in
.NE1' Framework language.
The Imports statement helps in enabling types that are contained in a given
namespace to be referenced directly. A namespace name may be a single namespace or
overview of Visual Stu3io .N.ET
a st rin g of
ce
na
by
m
a
es
pe
pa ce s
· rio d.-
w he re
e~ac
h
. ~r un s
e. pa ce
·
IS se pa
· ra
· te-d from the next higher
level
-
na m es pa
DB
Imports Sy st em.Data.OLE us ed
ed at so ur ce co de file level an d ca nn ot be
ar e us
The Im po rt s st at em en ts ul e, in te rfa ce , pr oc ed ur e or block. Howeve r,
s, st ru ct ur e, mod en ts
with in na m es pa ce , cl as y nu m be r of Im po rts statements. These st at em
n co nt ai n an
ea ch so ur ce co de file ca O pt io n St ric t st at em en t. Bu t th es e st at em en ts
st at em en ts like t does
sh ould be w rit te n af te r ts like M od ul e or Cl ass. The Imports st at em en
n st at em en ly
m us t pr ec ed e de cl ar at io ts an d as se m bl ie s av ai lable to a project, bu t on
ot he r projec
no t m ak e el em en ts from es th at ar e al re ad y available to th e project.
alify na m
rem ov es th e ne ed to qu
INC,) SUMMARY
by M icr osof t. It is de signed to build Window
is developed ~an
Th e .NET Fr am ew or k y m or e ty pe s of applications. Developers
ns ol e an d m an
ba se d, Web ba se d, co la ng ua ge s su ch as VB .NET, C# etc. The _obJect
of pr og ra m m in g ne ty of
ch oo se fr om a va rie ty or e po w er fu l tool to develop an d deploy va
e VB.NET m
or ie nt ed fe at ur es m ak
ap pl ic at io ns .
ge Z 01
T e s t Y o u r K n o w le
, (I ) ti=t.,.,i,:ti~?4,1po•ne1'1nttis •of01.N:tET1Framework.
1. N am e m ai n co m
la ng ua ge s su pp or te d by .NET Framework.
2 . N am e
an d FCL.
3 . D es cr ib e CTS, CLR io ?
is .N ET fr am ew or k as so ci at ed with Visual St ud
4 . How
5 . W ha t is ID E?
io .NET?
6 . W ha t is V is ua l St ud . d ?
w in ow. d S 1 tI·on
e us e of pr op er ty ·
7. W ha t is th 'b th e files re la te to a O u
. D es cn e .
8 . W ha t is a Solut10n?
pl or er ? d. VB NET
9 . W ha t is So lu tio n Ex . .
f im po rt an t files us e In
10. Write th e ex
.
te ns w n °
.
is V B. N ET ca lle d RA D?
1 1. Why
, VR_N ET?