visual programming.pdf
TRANSCRIPT
-
8/14/2019 Visual Programming.pdf
1/96
Advanced Visual and Windows Programming(BCA-205)
NAVGUA!A" C#$$%G%
#& C#'PU"%! APP$CA"#Nu*+ec,Advance visual and windows .rogramming(BCA-205)
u*+ec, Code BCA-205&acul,/Pro1aus3ar G3anc3i
Navgu+ara, BCA Page 4 o 6
-
8/14/2019 Visual Programming.pdf
2/96
Advanced Visual and Windows Programming(BCA-205)
The .NET Framework
The .NET Framework is the next iteration of Microsoft's platform fordeveloping component-based software. It provides fndamental advances inrntime services for application software. It also
spports development of applications that can be free of dependencies onhardware! operating s"stem! and langage compiler.This chapter provides an overview of the architectre of the .NET Framework
and describes the base featres fond in the core of its class librar".
Common Language Infrastructure (CLI) and Common LanguageRuntime (CLR)
At the heart of the .NET Framework is a new mechanism for loading and runningprograms and managing their interactions. This mechanism is described in the Common
Language Infrastructure (CLI! a specification for a runtime en"ironment that allowssoftware components to#
$$$$$$%ass data between each other without regard to the programming language in whicheach component is on paper
$$$$$$E&ecute on different operating s'stems and on different hardware platforms withoutha"ing to recompile the highle"el source code (a lowle"el compilation still automaticall'occurs on the target platform! as will be discussed in this chapter
Although the CLI specification was created b' )icrosoft! it has since been submitted tothe ECMA standards organi*ation (http#++www.ecma.ch! which now has responsibilit'and control o"er it.The CLI is ,ust a specification-it has to be implemented in order to be useful. An
implementation of the CLI is known as a Common Language Runtime (CL. )icrosoft/sCL implementation on the 0indows platform is not under EC)A/s control! but it is)icrosoft/s intention that the CL be a full' compliant implementation of the CLI. As ofthis writing! the CLI has not been implemented on non 0indows platforms! but )icrosoftand others ha"e announced intentions to do so.The CLI specifies how e&ecutable code is loaded! run! and managed. The portion of theCL that performs the tasks of loading! running! and managing .NET applications iscalled the virtual execution system (1E2. Code run b' the 1E2 is called managed code.The CLI greatl' e&pands upon concepts that e&ist in )icrosoft/s Component ObjectModel (C3). As its core feature! C3) specifies how ob,ect interfaces are laid out inmemor'. An' component that can create and consume this la'out can share data with
other components that do the same. C3) was a big step forward when it wasintroduced (circa 4556! but it has its shortcomings.
Common Type System (CTS)
The CLI specification defines a rich t'pe s'stem that far surpasses C3)/s capabilities. It/s calledthe Common Type ystem (CT2. The CT2 defines at the runtime le"el how t'pes are declaredand used.
Navgu+ara, BCA Page 2 o 6
-
8/14/2019 Visual Programming.pdf
3/96
-
8/14/2019 Visual Programming.pdf
4/96
Advanced Visual and Windows Programming(BCA-205)
compiled! subse=uent calls b'pass the compilation mechanism and call the compiled codedirectl'. The compiled code is not sa"ed to disk! so if the application is stopped and restarted! thecompilation must occur again. This is known as just!in!time (9IT compilation and is the mostcommon scenario.In the second case! the application is compiled in its entiret' at deplo'ment time. IL is sa"edto .exe and .dll files. 0hen such a file containing IL is e&ecuted! the CL knows how to in"oke the9IT compiler and e&ecute the resulting code. Note that on the )icrosoft 0indows platforms! IL isalwa's compiled-ne"er interpreted.
Metadata2ource code consists of some constructs that are procedural in nature and others that aredeclarative in nature. An e&le of a procedural construct is#someObject.SomeMember = 5
This is procedural because it compiles into e&ecutable code that performs an action at runtime.Namel'! it assigns the "alue 5 to the 2ome)ember member of the some3b,ect ob,ect.
In contrast! here is a declarati"e construct#Dim someObject As SomeClass
This is declarati"e because it doesn/t perform an action. It states that the s'mbol some3b,ect is a"ariable that holds a reference to an ob,ect of t'pe 2omeClass.
In the past! declarati"e information t'picall' was used onl' b' the compiler and did not compiledirectl' into the e&ecutable. In the CL! howe"er! declarati"e information is e"er'thing> The CLuses t'pe and signature information to ensure that memor' is alwa's referenced in a safe wa'.The 9IT compiler uses t'pe and signature information to resol"e method calls to the appropriatetarget code at 9IT compile time. The onl' wa' for this to work is for this declarati"e information tobe included alongside its associated procedural information. Compilers that target the CLtherefore store both procedural and declarati"e information in the resulting .exe or .dll file. Theprocedural information is stored as IL! and the declarati"e information is stored as metadata.)etadata is ,ust the CLI/s name for declarati"e information.
Modules and Assemblies
A module is an "exe or "dll file. An assembly is a set of one or more modules that together make
up an application. If the application is full' contained in an "exe file! fine-that/s a onemoduleassembl'. If the "exe is alwa's deplo'ed with two "dll files and one thinks of all three files ascomprising an inseparable unit! then the three modules together form an assembl'! but none ofthem does so b' itself. If the product is a class librar' that e&ists in a "dll file! then that single "dllfile is an assembl'. To put it in )icrosoft/s terms! the assembl' is the unit of deplo'ment in .NET.
An assembl' is more than ,ust an abstract wa' to think about sets of modules. 0hen anassembl' is deplo'ed! one (and onl' one of the modules in the assembl' must contain theassembly manifest! which contains information about the assembl' as a whole! including the listof modules contained in the assembl'! the "ersion of the assembl'! its culture! etc.
Memory Management and arbage CollectionIn an' ob,ectoriented programming en"ironment! there arises the need to instantiate and destro'ob,ects. Instantiated ob,ects occup' memor'. 0hen ob,ects are no longer in use! the memor'
the' occup' should be reclaimed for use b' other ob,ects. ecogni*ing when ob,ects are nolonger being used is called lifetime management! which is not a tri"ial problem. The solution theCL uses has implications for the design and use of the components 'ou write! so it is worthunderstanding.In the C3) world! the client of an ob,ect notified the ob,ect whene"er a new ob,ect reference waspassed to another client. Con"ersel'! when an' client of an ob,ect was finished with it! the clientnotified the ob,ect of that fact. The ob,ect kept track of how man' clients had references to it.0hen that count dropped to *ero! the ob,ect was free to delete itself (that is! gi"e its memor' backto the memor' heap. This method of lifetime management is known as reference counting.1isual 7asic programmers were not necessaril' aware of this mechanism because the 1isual
Navgu+ara, BCA Page 8 o 6
-
8/14/2019 Visual Programming.pdf
5/96
Advanced Visual and Windows Programming(BCA-205)
7asic compiler automaticall' generated the lowle"el code to perform this housekeeping. C::de"elopers had no such lu&ur'.eference counting has some drawbacks#
A method call is re=uired e"er' time an ob,ect reference is copied from one "ariable to anotherand e"er' time an ob,ect reference is o"erwritten.
;ifficulttotrack bugs can be introduced if the referencecounting rules are not precisel'
followed. Care must be taken to ensure that circular references are speciall' treated (because circularreferences can result in ob,ects that ne"er go awa'.The CL mechanism for lifetime management is =uite different. eference counting is not used.Instead! the memor' manager keeps a pointer to the address at which free memor' (known asthe #eap starts. To satisf' a memor' re=uest! it ,ust hands back a cop' of the pointer and thenincrements the pointer b' the si*e of the re=uest! lea"ing it in a position to satisf' the ne&tmemor' re=uest. This makes memor' allocation "er' fast. No action is taken at all when anob,ect is no longer being used. As long as the heap doesn/t run out! memor' is not reclaimed untilthe application e&its. If the heap is large enough to satisf' all memor' re=uests during programe&ecution! this method of memor' allocation is as fast as is theoreticall' possible! because theonl' o"erhead is incrementing the heap pointer on memor' allocations.If the heap runs out of memor'! there is more work to do. To satisf' a memor' re=uest when theheap is e&hausted! the memor' manager looks for an' pre"iousl' allocated memor' that can bereclaimed. It does this b' e&amining the application "ariables that hold ob,ect references. Theob,ects that these "ariables reference (and therefore the associated memor' are considered inuse because the' can be reached through the program/s "ariables. Furthermore! because theruntime has complete access to the application/s t'pe information! the memor' manager knowswhether the ob,ects contain members that reference other ob,ects! and so on. In this wa'! thememor' manager can find all of the memor' that is in use. ;uring this process! it consolidates thecontents of all this memor' into one contiguous block at the start of the heap! lea"ing theremainder of the heap free to satisf' new memor' re=uests.This process of freeing up memor' is known as garbage collection (?C! a term that also appliesto this o"erall method of lifetime management. The portion of the memor' manager that performsgarbage collection is called the garbage collector.The benefits of garbage collection are#
No o"erhead is incurred unless the heap becomes e&hausted.
It is impossible for applications to cause memor' leaks.
The application need not be careful with circular references.Although the process of garbage collection is e&pensi"e (on the order of a fraction of a secondwhen it occurs! )icrosoft claims that the total o"erhead of garbage collection is on a"erage muchless than the total o"erhead of reference counting (as shown b' their benchmarks. This! ofcourse! is highl' dependent on the e&act pattern of ob,ect allocation and deallocation that occursin an' gi"en program.
.NET Defined
Beore ge,,ing dee.l/ in,o ,3e su*+ec, we will irs, 9now 3ow Businesses are rela,ed ,o
n,erne,: w3a, 1N%" means ,o ,3em and w3a, e;ac,l/ 1N%" is *uil, u.on1 As .er ,3e.roduc, documen,a,ion rom a Business .ers.ec,ive: ,3ere are ,3ree .3ases o ,3e
n,erne,1 "3e &irs, .3ase ge,s *ac9 ,o ,3e earl/ 40
-
8/14/2019 Visual Programming.pdf
6/96
Advanced Visual and Windows Programming(BCA-205)
eec,ivel/ communica,e wi,3 ,3eir cus,omers and .ar,ners w3o are geogra.3icall/
isola,ed: .ar,ici.a,e in =igi,al %conom/ and deliver a wide range o services1 >ow can
,3a, *e .ossi*le? "3e answer: wi,3 1N%"1
What is .NET ?
'an/ .eo.le rec9on ,3a, i,
-
8/14/2019 Visual Programming.pdf
7/96
Advanced Visual and Windows Programming(BCA-205)
T!PES OF FI"ES #ND T$EI% E&TENSIONS 1uo olu,ion User #.,ion &ile
1V* An/ &ile &rom &ollowing
A Basic Window &orm
A Code &ile
A 'odule &ile &or ,oring &unc,ions
A User Con,rol
As =a,a &orm
A Cus,om Con,rol
An n3eri,ed &orm
A We* Cus,om Con,rol
An n3eri,ed User Con,rol
A Window ervices
An Assem*l/ no &ile 1@sd An @ml c3ema Provided "o Crea,e =a,ase,s
1>,m An >,ml =ocumen,
1";, A "e;, &ile
1!., Cr/s,al !e.or,
1Bm. Bi,ma. &ile
1s scri., &ile
1V*s V*scri., &ile 1Ws Windows cri.,ing &ile
1As.; A We* &orm
1As. An Ac,ive erver Page
1Asm; We* ervice Class
1Vsdisco A =/namic =iscover/ Pro+ec,
1We* A We Conigura,ion &ile
1Asa; A Glo*al A..lica,ion Class
1!e; A !esource &ile "o ,ore !esource norma,ion
1ln olu,ion &ile
1V*.ro+ V* Pro+ec, &ile
1V*.ro+1User V* Pro+ec, User #.,ion &ile
VB .NET IDE
,ar, Page 'enu Bar
"ool*ars
New Pro+ec, =ilog*o;
#*+ec, Browser
"3e "ool*o;
"3e olu,ion %;.lorer
Navgu+ara, BCA Page o 6
-
8/14/2019 Visual Programming.pdf
8/96
Advanced Visual and Windows Programming(BCA-205)
Class View Window
Pro.er,/ Window
=/namic >el. Window
Com.onen, "ra/
"3e erver %;.lorer
"3e #u,.u, Window
"3e "as9 $is,
"3e Command Window
Gra.3ical =esigners
&orm =esigners
We* &orm =esigners
Com.onen, =esigner
@ml =esigneres
Code =esigners
'ODES OF VB .NET
=esign "ime 'ode
!un,ime 'ode
Brea9 "ime 'ode
VB "an()a(e
Visual Basic: ,3e name ma9es me eel ,3a, i, is some,3ing s.ecial1 n ,3e >is,or/ oCom.u,ing world no o,3er .roduc, sold more co.ies ,3an Visual Basic did1 uc3 is ,3e
im.or,ance o ,3a, language w3ic3 clearl/ s,a,es 3ow widel/ i, is used or develo.ing
a..lica,ions1 Visual Basic is ver/ .o.ular or i,
-
8/14/2019 Visual Programming.pdf
9/96
Advanced Visual and Windows Programming(BCA-205)
/s,em1 Collec,ions ncludes classes and in,eraces ,3a, deine various collec,ion
o o*+ec,s suc3 as lis,: ueues:
3as3 ,a*les: arra/s: e,c /s,em1 =a,a ncludes classes w3ic3 le,s us 3andle da,a rom da,a sources
/s,em1=a,a1#le=* ncludes classes ,3a, su..or, ,3e #$%=B 1N%" .rovider
/s,em1 =rawing Provides access ,o drawing me,3ods
/s,em1# ncludes classes or da,a access wi,3 &iles
/s,em1 "3reading ncludes classes and in,eraces ,o su..or, mul,i,3readed
/s,em1 We* ncludes classes and in,eraces ,3a, su..or, *rowser-server
/s,em1Windows1&orms ncludes classes or crea,ing Windows *ased orms
#sse*b+ies
An assem*l/ is ,3e *uilding *loc9 o a 1N%" a..lica,ion1 , is a sel descri*ing collec,iono code: resources: and me,ada,a (da,a a*ou, da,a: e;am.le: name: siDe: version o a ile
is me,ada,a a*ou, ,3a, ile)1 An Assem*l/ is a com.lied and versioned collec,ion o codeand me,ada,a ,3a, orms an a,omic unc,ional uni,1 Assem*lies ,a9e ,3e orm o a
d/namic lin9 li*rar/ (1dll) ile or e;ecu,a*le .rogram ile (1e;e) *u, ,3e/ dier as ,3e/
con,ain ,3e inorma,ion ound in a ,/.e li*rar/ and ,3e inorma,ion a*ou, ever/,3ing elseneeded ,o use an a..lica,ion or com.onen,1 All 1N%" .rograms are cons,ruc,ed rom
,3ese Assem*lies1 Assem*lies are made o ,wo .ar,s manies,: con,ains inorma,ion
a*ou, w3a, is con,ained wi,3in ,3e assem*l/ and modules: in,ernal iles o $ code w3ic3are read/ ,o run1 W3en .rogramming: we don
-
8/14/2019 Visual Programming.pdf
10/96
Advanced Visual and Windows Programming(BCA-205)
Access s.eciiers le,
-
8/14/2019 Visual Programming.pdf
11/96
Advanced Visual and Windows Programming(BCA-205)
W3en ,/.es canno, *e im.lici,l/ conver,ed /ou s3ould conver, ,3em e;.lici,l/1 "3is
conversion is also called as cas,1 %;.lici, conversions are accom.lis3ed using C"/.e
unc,ion1C"/.e unc,ion or conversion
we are no, sure o ,3e name o a .ar,icular conversion unc,ion ,3en we can use ,3e
C"/.e unc,ion1 "3e a*ove e;am.le wi,3 a C"/.e unc,ion loo9s li9e ,3ism.or,s /s,em1Console
'odule 'odule4
u* 'ain()=im d As =ou*le
d F 472174227
=im i As n,eger
i F C"/.e(d: i)
-
8/14/2019 Visual Programming.pdf
12/96
Advanced Visual and Windows Programming(BCA-205)
K 'ul,i.lica,ion
L =ivision
M n,eger =ivision'od 'odulus Ari,3me,ic
I Addi,ion
- u*,rac,ion
Conca,ena,ion #.era,orsConca,ena,ion o.era,ors +oin mul,i.le s,rings in,o a single s,ring1 "3ere are ,wo
conca,ena,ion o.era,ors: I and H as summariDed *elow
#.era,or Use
I ,ring Conca,ena,ionH ,ring Conca,ena,ion
Com.arison #.era,ors
A com.arison o.era,or com.ares o.erands and re,urns a logical value *ased on w3e,3er,3e com.arison is ,rue or no,1 "3e ,a*le *elow summariDes ,3em
#.era,or UseF %uali,/
O neuali,/
$ess ,3anO Grea,er ,3an
OF Grea,er ,3an or eual ,o
F $ess ,3an or eual ,o
$ogical L Bi,wise #.era,ors
"3e logical o.era,ors com.are Boolean e;.ressions and re,urn a Boolean resul,1 n s3or,:
logical o.era,ors are e;.ressions w3ic3 re,urn a ,rue or alse resul, over a condi,ionale;.ression1 "3e ,a*le *elow summariDes ,3em
#.era,or Use
No, Nega,ion
And Con+unc,ion
AndAlso Con+unc,ion
#r =is+unc,ion
#r%lse =is+unc,ion
@or =is+unc,ion
#rraysArra/s are .rogramming cons,ruc,s ,3a, s,ore da,a and allow us ,o access ,3em */numeric inde; or su*scri.,1 Arra/s 3el.s us crea,e s3or,er and sim.ler code in man/
si,ua,ions1 Arra/s in Visual Basic 1N%" in3eri, rom ,3e Arra/ class in ,3e /s,emnames.ace1 All arra/s in VB as Dero *ased: meaning: ,3e inde; o ,3e irs, elemen, is Dero
and ,3e/ are num*ered seuen,iall/1 Eou mus, s.eci/ ,3e num*er o arra/ elemen,s */
indica,ing ,3e u..er *ound o ,3e arra/1 "3e u..er *ound is ,3e numder ,3a, s.eciies ,3e
inde; o ,3e las, elemen, o ,3e arra/1 Arra/s are declared using =im: !e=im: ,a,ic:
Navgu+ara, BCA Page 42 o 6
-
8/14/2019 Visual Programming.pdf
13/96
Advanced Visual and Windows Programming(BCA-205)
Priva,e: Pu*lic and Pro,ec,ed 9e/words1 An arra/ can 3ave one dimension (liinear arra/s)
or more ,3an one (mul,idimensional arra/s)1 "3e dimensionali,/ o an arra/ reers ,o ,3e
num*er o su*scri.,s used ,o iden,i/ an individual elemen,1 n Visual Basic we cans.eci/ u. ,o 72 dimensions1 Arra/s do no, 3ave i;ed siDe in Visual Basic1
"3e ollowing code demons,ra,es arra/s1
'odule 'odule4u* 'ain()
=im s.or,(5) As ,ring
oc9e/
-
8/14/2019 Visual Programming.pdf
14/96
Advanced Visual and Windows Programming(BCA-205)
Para*eters1
str Name o ,3e ,ring varia*le ,o modi/1
Start n,eger da,a ,/.e1 C3arac,er .osi,ion in ,arge, w3ere ,3e re.lacemen, o ,e;, *egins1,ar, uses a one *ased inde;1
Pu*lic &unc,ion Stro*p(B/Val String1As Strin(2 B/Val String2As Strin(2#.,ional B/Val CompareAs 'icrosoft.Vis)a+Basic.o*pare'ethod F 0) As Inte(er 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns -4: 0: or 4: *ased on ,3e resul, o a s,ring com.arison1 "3e s,rings are com.ared*/ al.3anumeric sor, values *egining wi,3 ,3e irs, c3arac,er1
Para*eters1
String1 An/ valid ,ring e;.ression1String2 An/ valid ,ring e;.ression1
Compare .eciies ,3e ,/.e o s,ring com.arison1 com.are is omi,,ed: ,3e #.,ionCom.are se,,ing de,ermines ,3e ,/.e o com.arison1
Pu*lic &unc,ion /ethar(B/ValstrAs Strin(2 B/ValIndexAs Inte(er) As
har
'em*er o 'icrosoft.Vis)a+Basic 1Strin(sS)**ary1
!e,urns ,3e c3arac,er a, a s.eciied .osi,ion in a s,ring
Para*eters1
str ,ring ,o use as a source
Index 4 *ased inde; o ,3e c3arac,er ,o re,urn Pu*lic &unc,ion InStr(B/Val StartAs Inte(er2 B/Val String1As Strin(2 B/Val
String2As Strin(2 #.,ional B/Val CompareAs
'icrosoft.Vis)a+Basic.o*pare'ethod F 0) As Inte(er 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns an n,eger s.eci/ing ,3e s,ar, .osi,ion o ,3e irs, occurrence o one s,ring wi,3in
ano,3er1
Para*eters1
Start Numeric e;.ression ,3a, se,s ,3e s,ar,ing .osi,ion or eac3 searc31 omi,,ed:
searc3 *egins a, ,3e irs, c3arac,er .osi,ion1 "3e s,ar, inde; is 4 *ased1String1 ,ring e;.ression *eing searc3ed1
String2 ,ring e;.ression soug3,1
Pu*lic &unc,ion InStr%ev(B/Val StringCheckAs Strin(2 B/Val StringMatchAs
Strin(2 #.,ional B/Val StartAs Inte(erF -42 #.,ional B/Val CompareAs
'icrosoft.Vis)a+Basic.o*pare'ethod F 0) As Inte(er
'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
Navgu+ara, BCA Page 48 o 6
-
8/14/2019 Visual Programming.pdf
15/96
Advanced Visual and Windows Programming(BCA-205)
S)**ary1
!e,urns ,3e .osi,ion o ,3e irs, occurrence o one s,ring wi,3in ano,3er: s,ar,ing rom ,3e
rig3, side o ,3e s,ring1
Para*eters1
StringCheck ,ring e;.ression *eing searc3ed1
StringMatch ,ring e;.ression *eing searc3ed or1Start Numeric e;.ression ,3a, se,s ,3e one-*ased s,ar,ing .osi,ion or eac3 searc3:
s,ar,ing rom ,3e le, side o ,3e s,ring1 ,ar, is omi,,ed: 4 is used: w3ic3 means ,3a,
,3e searc3 *egins a, ,3e las, c3arac,er .osi,ion1 earc3 ,3en .roceeds rom rig3, ,o le,1 Pu*lic &unc,ion 3oin(B/Val SourceArray() As Obect2 #.,ional B/ValDelimiter
As Strin(F ) As Strin( 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns a s,ring crea,ed */ +oining a num*er o su*s,rings con,ained in an arra/1
Para*eters1
SourceArray #ne-dimensional arra/ con,aining su*s,rings ,o *e +oined1
Delimiter ,ring used ,o se.ara,e ,3e su*s,rings in ,3e re,urned s,ring1 omi,,ed: ,3es.ace c3arac,er ( ) is used1 =elimi,er is a Dero-leng,3 s,ring (): all i,ems in ,3e lis,
are conca,ena,ed wi,3 no delimi,ers1
Pu*lic &unc,ion "ase(B/Val ValueAs Strin() As Strin( 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns a ,ring or C3ar ,3a, 3as *een conver,ed ,o lowercase1
Para*eters1
Value An/ valid ,ring or C3ar e;.ression1 Pu*lic &unc,ion "eft(B/ValstrAs Strin(2 B/ValLengthAs Inte(er) As Strin( 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns a ,ring con,aining a s.eciied num*er o c3arac,ers rom ,3e le, side o a s,ring1
Para*eters1
Str ,ring e;.ression rom w3ic3 ,3e le,mos, c3arac,ers are re,urned1Length n,eger e;.ression1 Numeric e;.ression indica,ing 3ow man/ c3arac,ers ,o
re,urn1 0: a Dero-leng,3 s,ring () is re,urned1 grea,er ,3an or eual ,o ,3e num*er o
c3arac,ers in ,r: ,3e en,ire s,ring is re,urned1
Pu*lic &unc,ion "en(B/ValExpressionAs Byte) As Inte(er 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s S)**ary1
!e,urns an n,eger con,aining ei,3er ,3e num*er o c3arac,ers in a s,ring or ,3enum*er o */,es reuired ,o s,ore a varia*le1
Para*eters1
Expression valid ,ring e;.ression or varia*le name1 %;.ression is o ,/.e#*+ec,: ,3e $en unc,ion re,urns ,3e siDe as i, will *e wri,,en ,o ,3e ile1
Pu*lic &unc,ion 'id(B/ValstrAs Strin(2 B/Val StartAs Inte(er) As Strin( 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
Navgu+ara, BCA Page 45 o 6
-
8/14/2019 Visual Programming.pdf
16/96
Advanced Visual and Windows Programming(BCA-205)
!e.laces a s.eciied num*er o c3arac,ers in a ,ring varia*le wi,3 c3arac,ers rom
ano,3er s,ring1
Para*eters1
str Name o ,3e ,ring varia*le ,o modi/1
Start n,eger da,a ,/.e1 C3arac,er .osi,ion in ,arge, w3ere ,3e re.lacemen, o ,e;, *egins1
,ar, uses a one *ased inde;1
Pu*lic &unc,ion %ep+ace(B/ValExpressionAs Strin(2 B/ValindAs Strin(2B/Val!eplacementAs Strin(2 #.,ional B/Val StartAs Inte(erF 42 #.,ional B/ValCountAs Inte(erF -42 #.,ional B/Val CompareAs
'icrosoft.Vis)a+Basic.o*pare'ethod F 0) As Strin( 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns a s,ring in w3ic3 a s.eciied su*s,ring 3as *een re.laced wi,3 ano,3er su*s,ring a
s.eciied num*er o ,imes1
Para*eters1
Expression ,ring e;.ression con,aining su*s,ring ,o re.lace1ind u*s,ring *eing searc3ed or1
!eplacement !e.lacemen, su*s,ring1Start Posi,ion wi,3in %;.ression w3ere su*s,ring searc3 is ,o *egin1 omi,,ed: 4 is
assumed1
Count Num*er o su*s,ring su*s,i,u,ions ,o .erorm1 omi,,ed: ,3e deaul, value is 4:w3ic3 means ma9e all .ossi*le su*s,i,u,ions1
Compare Numeric value indica,ing ,3e 9ind o com.arison ,o use w3en evalua,ing
su*s,rings1 ee e,,ings or values1
Pu*lic &unc,ion Sp+it(B/ValExpressionAs Strin(2 #.,ional B/ValDelimiterAs
Strin(F 2 #.,ional B/ValLimitAs Inte(erF -42 #.,ional B/Val CompareAs
'icrosoft.Vis)a+Basic.o*pare'ethod F 0) As Strin(() 'em*er o 'icrosoft.Vis)a+Basic 1Strin(s
S)**ary1
!e,urns a Dero-*ased: one-dimensional arra/ con,aining a s.eciied num*er o su*s,rings1
Para*eters1
Expression ,ring e;.ression con,aining su*s,rings and delimi,ers1 %;.ression is a
Dero-leng,3 s,ring (): ,3e .li, unc,ion re,urns an arra/ wi,3 no elemen,s and no da,a1
Delimiter ingle c3arac,er used ,o iden,i/ su*s,ring limi,s1 =elimi,er is omi,,ed: ,3es.ace c3arac,er ( ) is assumed ,o *e ,3e delimi,er1 =elimi,er is a Dero-leng,3 s,ring: a
single-elemen, arra/ con,aining ,3e en,ire %;.ression s,ring is re,urned1
Limit Num*er o su*s,rings ,o *e re,urnedQ ,3e deaul,: 4: indica,es ,3a, all su*s,ringsare re,urned1
Compare Numeric value indica,ing ,3e com.arison ,o use w3en evalua,ing su*s,rings1
ee e,,ings or values1
C#N"!#$ "A"%'%N" & condi,ion ">%N
%$%& condi,ion ">%N
Navgu+ara, BCA Page 46 o 6
-
8/14/2019 Visual Programming.pdf
17/96
Advanced Visual and Windows Programming(BCA-205)
%$%
%N= &
%$%C" CA% e;.r
CA% e;.rls,4
CA% e;.rls,2R1
R1
CA% e;.rls,N
%N= %$%C"
W"C>(e;.r-4:value-4:e;.r-2: value-2:11e;.r-N: value-N)
C>##%(inde;:c3ice-4: c3ice-2: c3ice-7R1 c3ice-N)$##PNG C#N"UC"
=# w3ileLun,il condi,ion
,m,
%;i, do $##P or inde;Fs,ar, ,o end s,e.
,a,emen,s
%;i, or
N%@"
W>$% condi,ion
,a,emen,sW%N=
W"> o*+ec,,a,emen,s
%N= W">
'essa(ebo- F)nction
'essa(eBo-.Sho45#r()*ents6
everal c3oices or argumen, lis, n,roduces conce., o #verloaded unc,ions
'ul,i.le signa,ures ,o c3oose rom
'essa(eBo-.Sho45TextMessage6
'essa(eBo-.Sho45TextMessage2 TitlebarText6
'essa(eBo-.Sho45TextMessage2 TitlebarText2 7
MessageBoxButtons6
Navgu+ara, BCA Page 4 o 6
-
8/14/2019 Visual Programming.pdf
18/96
Advanced Visual and Windows Programming(BCA-205)
'essa(eBo-.Sho45TextMessage2 TitlebarText2 7
MessageBoxButtons, MessageBoxIcon6
'essageBo; cons and *u,,ons
%numera,ion o cons,an,s
'en)s2S)b Proced)res2S)b F)nctions
Crea,ing 'enus and 'enu ,ems
Crea,ing Con,e;,'enus
=is.la/ing Common =ialog Bo;es
Wri,ing General Procedures
'enus
Crea,e a menu */ adding a 'ain'enu con,rol ,o ,3e com.onen, ,ra/
Grea, new 'enu =esigner re.laces ,3e 'enu %di,or
'enus
&or Con,e;, menus: add a Con,e;,'enu con,rol
A Con,e;,'enu uses ,3e same 'enu =esigner as a 'ain'enu
A,,ac3 a con,e;, menu */ se,,ing ,3e Con,e;,'enu .ro.er,/ o a con,rol or ,3e
orm
u* &unc,ion
Argumen,s are .assed B/Val (*/ deaul,) "3e %di,or adds B/Val i /ou leave i, ou,
New !e,urn s,a,emen, Can s,ill se, unc,ion name ,o value Be,,er ,o use ,3e !e,urn s,a,emen,
Private F)nction a+c)+ateS)*5 7
ByVa+ intN)*8 #s Inte(er2 7
ByVa+ intN)*9 #s Inte(er6 #s Inte(er
:a+c)+ate the s)* of the n)*bers
%et)rn intN)*8 ; intN)*9End F)nction
ONT%O"S
B)tton ontro+
Navgu+ara, BCA Page 4 o 6
-
8/14/2019 Visual Programming.pdf
19/96
Advanced Visual and Windows Programming(BCA-205)
#ne o ,3e mos, .o.ular con,rol in Visual Basic is ,3e Bu,,on Con,rol (.reviousl/Command Con,rol)1 "3e/ are ,3e con,rols w3ic3 we clic9 and release ,o .erorm some
ac,ion1 Bu,,ons are used mos,l/ or 3andling even,s in code: sa/: or sending da,a en,ered
in ,3e orm ,o ,3e da,a*ase and so on1 "3e deaul, even, o ,3e Bu,,on is ,3e Clic9 even,and ,3e Bu,,on class is *ased on ,3e Bu,,onBase class w3ic3 is *ased on ,3e Con,rol class1
B)tton Event "3e deaul, even, o ,3e Bu,,on is ,3e Clic9 even,1 W3en a Bu,,on is clic9ed i,
res.onds wi,3 ,3e Clic9 %ven,1 "3e Clic9 even, o Bu,,on loo9s li9e ,3is in code
Priva,e u* Bu,,on4SClic9(B/Val sender As /s,em1#*+ec,: B/Val e AsS
/s,em1%ven,Args) >andles Bu,,on41Clic9
-
8/14/2019 Visual Programming.pdf
20/96
Advanced Visual and Windows Programming(BCA-205)
Bu,,on41$oca,ionFNew Poin,(400:50)
-
8/14/2019 Visual Programming.pdf
21/96
Advanced Visual and Windows Programming(BCA-205)
"e;,Align Allows ,o align ,3e ,e;, rom ,3ree .ossi*le o.,ions1 "3e deaul, valueis le, and /ou can se, ,3e alignmen, o ,e;, ,o rig3, or cen,er1
croll*ars Allows ,o add a scroll*ar ,o a "e;,*o;1 Ver/ useul w3en ,3e "e;,Bo;is mul,iline1 Eou 3ave our o.,ions wi,3 ,3is .ro.er,/1 #.,ions are are None: >oriDon,al:
Ver,ical and Bo,31 =e.ending on ,3e siDe o ,3e "e;,Bo; an/one o ,3ose can *e used1
Code ,o Valida,e User n.u,We can ma9e sure ,3a, a "e;,Bo; can acce., onl/ c3arac,ers or num*ers w3ic3 can
res,ric, acciden,al o.era,ions1 &or e;am.le: adding ,wo num*ers o ,3e orm 2I2
canno, re,urn an/,3ing1 "o avoid suc3 9ind o o.era,ions we use ,3e e/Press even, o
,3e "e;,Bo;1
Code ,3a, allows /ou ,o en,er onl/ dou*le digi,s in a "e;,Bo; loo9s li9e ,3is Priva,e u* "e;,Bo;4Se/Press(B/Val sender As #*+ec,:B/Val e AsS/s,em1Windows1&orms1e/Press%ven,Args) >andles "e;,Bo;41e/Press
(e1e/C3ar 40 #r e1e/C3ar O 400) "3en
'essageBo;13ow(%n,er =ou*le =igi,s)
%nd %nd u*
reatin( a Te-tBo- in ode
Pu*lic Class &orm4 n3eri,s /s,em1Windows1&orms1&orm
Priva,e u* &orm4S$oad(B/Val sender As /s,em1#*+ec,: B/Val e AsS/s,em1%ven,Args) >andles '/Base1$oad
=im "e;,Bo;4 as New "e;,Bo;()
"e;,Bo;41"e;,F>ello 'a,e"e;,Bo;41$oca,ionFNew Poin,(400:50)
"e;,Bo;41iDeFNew iDe(5:27)
'e1Con,rols1Add("e;,Bo;4)
%nd u*%nd Class
hec
-
8/14/2019 Visual Programming.pdf
22/96
Advanced Visual and Windows Programming(BCA-205)
as c3ec9ed1
C3ec9,a,e =eaul, value is Unc3ec9ed1 e, i, ,o "rue i /ou wan, a c3ec9 ,o a..ear1
W3en se, ,o nde,ermina,e i, dis.la/s a c3ec9 in gra/ *ac9ground1&la,,/le =eaul, value is ,andard1 elec, ,3e value rom a .redeined lis, ,o se, ,3e s,/le
o ,3e c3ec9*o;1
m.or,an, .ro.er,/ in ,3e Be3avior sec,ion o ,3e .ro.er,ies window is ,3e
"3ree,a,e .ro.er,/ w3ic3 is se, ,o &alse */ deaul,1 e, i, ,o "rue ,o s.eci/ i ,3eC3ec9*o; can allow ,3ree c3ec9 s,a,es ,3an ,wo1
Code ,o c3ec9 a C3ec9Bo;andles Bu,,on41Clic9
C3ec9Bo;41C3ec9ed F "rue "3en
"e;,Bo;41"e;, F C3ec9ed%lse
"e;,Bo;41"e;, F UnC3ec9ed%nd %nd u*
Crea,ing a C3ec9Bo; in Code
Priva,e u* &orm4S$oad(B/Val sender As /s,em1#*+ec,: B/Val e AsS
/s,em1%ven,Args) >andlesS '/Base1$oad
=im C3ec9Bo;4 As New C3ec9Bo;()
C3ec9Bo;41"e;, F C3ec9*o;4C3ec9Bo;41$oca,ion F New Poin,(400: 50)
C3ec9Bo;41iDe F New iDe(5: 85)
'e1Con,rols1Add(C3ec9Bo;4)%nd u*
o*boBo-
Com*oBo; is a com*ina,ion o a "e;,Bo; and a $is,Bo;1 "3e Com*oBo;
dis.la/s an edi,ing ield ("e;,Bo;) com*ined wi,3 a $is,Bo; allowing us ,o selec, rom,3e lis, or ,o en,er new ,e;,1 Com*oBo; dis.la/s da,a in a dro.-down s,/le orma,1 "3e
Com*oBo; class is derived rom ,3e $is,Bo; class1 Below is ,3e mage o a Com*oBo;1
Notab+e properties of the o*boBo-
"3e =ro.=own,/le .ro.er,/ in ,3e A..earance sec,ion o ,3e .ro.er,ies window
allows us ,o se, ,3e loo9 o ,3e Com*oBo;1 "3e deaul, value is se, ,o =ro.=own w3ic3means ,3a, ,3e Com*oBo; dis.la/s ,3e "e;, se, */ i,
-
8/14/2019 Visual Programming.pdf
23/96
Advanced Visual and Windows Programming(BCA-205)
We can add i,ems ,o ,3e Com*oBo; wi,3 i,
-
8/14/2019 Visual Programming.pdf
24/96
Advanced Visual and Windows Programming(BCA-205)
dis.la/s a $is,Bo;1
Notab+e Properties of the "istBo-
n ,3e Be3avior ec,ion
>oriDon,alcroll*ar =is.la/s a 3oriDon,al scroll*ar ,o ,3e $is,Bo;1 Wor9s w3en,3e $is,Bo; 3as 'ul,i.leColumns1
'ul,iColumn "3e deaul, value is se, ,o &alse1 e, i, ,o "rue i /ou wan, ,3e lis, *o; ,o
dis.la/ mul,i.le columns1crollAlwa/sVisi*le =eaul, value is se, ,o &alse1 e,,ing i, ,o "rue will dis.la/ *o,3
Ver,ical and >oriDon,al scroll*ar alwa/s1
elec,ion'ode =eaul, value is se, ,o one1 elec, o.,ion None i /ou do no, an/ i,em ,o
*e selec,ed1 elec, i, ,o 'ul,iim.le i /ou wan, mul,i.le i,ems ,o *e selec,ed1 e,,ing i,,o 'ul,i%;,ended allows /ou ,o selec, mul,i.le i,ems wi,3 ,3e 3el. o 3i,: Con,rol and
arrow 9e/s on ,3e 9e/*oard1
or,ed =eaul, value is se, ,o &alse1 e, i, ,o "rue i /ou wan, ,3e i,ems dis.la/ed in ,3e
$is,Bo; ,o *e sor,ed */ al.3a*e,ical order1
Coun,ing ,3e num*er o ,ems in a $is,Bo;
Add a Bu,,on ,o ,3e orm and .lace ,3e ollowing code in i,andles Bu,,on41Clic9
"e;,Bo;41"e;, F $is,Bo;41,ems1Coun,
-
8/14/2019 Visual Programming.pdf
25/96
Advanced Visual and Windows Programming(BCA-205)
%;am.le
Code ,o add and remove da,a
Code ,o 3i, single selec,ed i,em rom one lis,*o; ,o ano,3er lis,*o;Code ,o s3i, mul,i.le i,ems
%;am.le-c3ec9*o; and o.,ion *u,,on
%;am.le-Calcula,or
Code or num*er *u,,ons
Code or #.era,ors *u,,onsCode or euals *u,,ons
o**on Dia+o(s
Visual Basic 1N%" comes wi,3 *uil,-in dialog *o;es w3ic3 allow us ,o crea,e our own
&ile #.en: &ile ave: &on,: Color dialogs muc3 li9e w3a, we see in all o,3er windows
a..lica,ions1 "o ma9e a dialog *o; visi*le a, run ,ime we use ,3e dialog *o;
-
8/14/2019 Visual Programming.pdf
26/96
Advanced Visual and Windows Programming(BCA-205)
SaveFi+eDia+o(
ave &ile =ialog
-
8/14/2019 Visual Programming.pdf
27/96
Advanced Visual and Windows Programming(BCA-205)
"3e Windows &orms TreeVie4con,rol dis.la/s a 3ierarc3/ o nodes: li9e ,3e wa/ iles
and olders are dis.la/ed in ,3e le, .ane o Windows %;.lorer1
"3e Windows &orms TreeVie4con,rol dis.la/s a 3ierarc3/ o nodes: li9e ,3e wa/ ilesand olders are dis.la/ed in ,3e le, .ane o Windows %;.lorer1 %ac3 node mig3, con,ain
o,3er nodes: called c3ild nodes1 Paren, nodes: or nodes ,3a, con,ain c3ild nodes: can *edis.la/ed as e;.anded or colla.sed1 A ,ree view can also *e dis.la/ed wi,3 c3ec9 *o;es
ne;, ,o ,3e nodes: i ,3e ,ree view
-
8/14/2019 Visual Programming.pdf
28/96
Advanced Visual and Windows Programming(BCA-205)
Use ,3e %ven,Args o*+ec, ,o re,urn a reerence ,o ,3e clic9ed node o*+ec,1
=e,ermine w3ic3 node was clic9ed */ c3ec9ing ,3e "reeView%ven,Args class: w3ic3
con,ains da,a rela,ed ,o ,3e even,1
Priva,e u* "reeView4SA,erelec,(B/Val sender As /s,em1#*+ec,: S
B/Val e As /s,em1Windows1&orms1"reeView%ven,Args) >andles"reeView41A,erelec,
1
'essageBo;13ow(e1Node1"e;,)%nd u*
"ISTVIEW ONT%O"
"3e Windows &orms "istVie4con,rol dis.la/s a lis, o i,ems wi,3 icons1 Eou can use a
lis, view ,o crea,e a user in,erace li9e ,3e rig3, .ane o Windows %;.lorer1
"3e Windows &orms "istVie4con,rol dis.la/s a lis, o i,ems wi,3 icons1 Eou can use a
lis, view ,o crea,e a user in,erace li9e ,3e rig3, .ane o Windows %;.lorer1 "3e con,rol
3as our view modes $argecon: mallcon: $is,: and =e,ails1 "3e $argecon modedis.la/s large icons ne;, ,o ,3e i,em ,e;,Q ,3e i,ems a..ear in mul,i.le columns i ,3e
con,rol is large enoug31 "3e mallcon mode is ,3e same e;ce., ,3a, i, dis.la/s small
icons1 "3e $is, mode dis.la/s small icons *u, is alwa/s in a single column1 "3e =e,ails
mode dis.la/s i,ems in mul,i.le columns1
"3e 9e/ .ro.er,/ o ,3e "istVie4con,rol is Ite*s: w3ic3 con,ains ,3e i,ems dis.la/ed */
,3e con,rol1 "3e Se+ectedIte*s.ro.er,/ con,ains a collec,ion o ,3e i,ems curren,l/
selec,ed in ,3e con,rol1 "3e user can selec, mul,i.le i,ems: or e;am.le ,o drag and dro.several i,ems a, a ,ime ,o ano,3er con,rol: i ,3e ')+tiSe+ect.ro.er,/ is se, ,o tr)e1 "3e
"istVie4con,rol can dis.la/ c3ec9 *o;es ne;, ,o ,3e i,ems: i ,3e hec
-
8/14/2019 Visual Programming.pdf
29/96
Advanced Visual and Windows Programming(BCA-205)
41 n ,3e Pro.er,ies window: clic9 ,3e elli.sis *u,,on ( ) ne;, ,o ,3e Ite*s.ro.er,/1
"3e "istVie4Ite* o++ection Editora..ears1
21 "o add an i,em: clic9 ,3e #dd*u,,on1 Eou can ,3en se, .ro.er,ies o ,3e new
i,em: suc3 as ,3e Te-tand I*a(eInde-.ro.er,ies1 "o remove an i,em: selec, i,and clic9 ,3e %e*ove*u,,on1
To add ite*s pro(ra**atica++y
%istView1.&tems.A#'%ist item te(t') $
To add co+)*ns in the desi(ner
41 e, ,3e con,rol
-
8/14/2019 Visual Programming.pdf
30/96
Advanced Visual and Windows Programming(BCA-205)
21 e, ,3e I*a(eInde-or StateI*a(eInde-.ro.er,/ or eac3 lis, i,em ,3a, 3as an
associa,ed icon1
"3ese .ro.er,ies can *e se, in code: or wi,3in ,3e "istVie4Ite* o++ection
Editor1 "o o.en ,3e "istVie4Ite* o++ection Editor: clic9 ,3e elli.sis *u,,on (
) ne;, ,o ,3e Ite*s.ro.er,/ on ,3e Pro.er,ies window1
6 Visal 7asic6 Sets t8e irst list item to isla t8e 9t8 ima4e%istView1.&tems#$.&ma4e&,e( =
OOP=oncept
Obects
Visual *asic allows /ou ,o crea,e o*+ec, */ deining class1Class ma/ 3ave .ro.er,iesand me,3ods1 #*+ec, is a ,3ing w3ic3 is .ro.er,ies and me,3ods1
User deined class can *e crea,ed in v*1and ,3a, classes can *e incor.ora,ed ,o
.ro+ec,s as a reerences1Pro.er,ies are ,3e c3arac,eris,ic and me,3ods are ,3e o.era,ion ,3a, can *e .erormed
on an o*+ec,1
OOP=Ter*ino+o(y
%nca.sula,ion
n3eri,ancePol/mor.3ism
"#SSES
ns,an,ia,ing an o*+ec,
New class name
i1e=im c F new on,(Tarial:42)
$*ln,1on,Fc
reatin( yo)r o4n c+asses
Crea,e a new a..lica,ion o ,/.e class li*rar/Crea,e .ro.er,ies o ,3e class1
Pro.er,/ .rocedure
,3e wa/ ,3a, /our class allows i,s .ro.er,ies is ,o *e accessed is ,3roug3 a .ro.er,/.rocedure1 i, ma/ con,ain a ge, ,o re,rieve a .ro.er,/ value and a se, ,o assign a value
,o ,3e .ro.er,/1
Navgu+ara, BCA Page 70 o 6
-
8/14/2019 Visual Programming.pdf
31/96
Advanced Visual and Windows Programming(BCA-205)
&ollowing is ,3e e;am.le
Pro.er,/ o.4() As n,eger
Ge,o.4 F no4
%nd Ge,
e,(B/Val Value As n,eger)no4 F Value
%nd e,
%nd Pro.er,/
reatin( yo)r o4n c+asses
Crea,e a new a..lica,ion o ,/.e class li*rar/
Crea,e .ro.er,ies o ,3e class1Pro.er,/ .rocedure
,3e wa/ ,3a, /our class allows i,s .ro.er,ies is ,o *e accessed is ,3roug3 a .ro.er,/.rocedure1 i, ma/ con,ain a ge, ,o re,rieve a .ro.er,/ value and a se, ,o assign a value
,o ,3e .ro.er,/1
&ollowing is ,3e e;am.lePro.er,/ o.4() As n,eger
Ge,
o.4 F no4
%nd Ge,e,(B/Val Value As n,eger)
no4 F Value
%nd e,%nd Pro.er,/
reatin( ne4 obect )sin( c+asses
Crea,e new o*+ec, using ollowing s,a,emen, in windows a..lica,ion
=im c as new class name
"3is class name mus, *e add as a reerence in a .ro+ec,1
!ata Access Tec"nologies'os, a..lica,ions reuire some orm o da,a access1 /ou are crea,ing a new a..lica,ion:
/ou 3ave ,3ree e;cellen, da,a access c3oices A=#1N%": A=#: and #$% =B1 /ouneed ,o modi/ ,3e da,a access or an e;is,ing a..lica,ion: /ou mig3, con,inue using ,3e
a..lica,ionowever: i
/ou e;.ec, ,3e a..lica,ion ,o 3ave a long liec/cle: /ou s3ould consider reengineering ,ouse ei,3er A=#1N%" or managed a..lica,ions or A=# or na,ive a..lica,ions1 n ,3e
Navgu+ara, BCA Page 74 o 6
-
8/14/2019 Visual Programming.pdf
32/96
Advanced Visual and Windows Programming(BCA-205)
long run: ,3e newer da,a access ,ec3nologies ,/.icall/ reduce develo.men, ,ime: sim.li/
code: and .rovide e;cellen, .erormance1
A!#$%&T
A=#1N%" is ,3e s,ra,egic a..lica,ion-level in,erace or .roviding da,a access services in,3e 'icroso, 1N%" Pla,orm1 Eou can use A=#1N%" ,o access da,a sources using ,3e
new 1N%" &ramewor9 da,a .roviders1 "3ese da,a .roviders include
1N%" &ramewor9 =a,a Provider or $ erver1
1N%" &ramewor9 =a,a Provider or #$% =B1
1N%" &ramewor9 =a,a Provider or #=BC1
1N%" &ramewor9 =a,a Provider or #racle1
"3ese da,a .roviders su..or, a varie,/ o develo.men, needs: including middle-,ier*usiness o*+ec,s using live connec,ions ,o da,a in rela,ional da,a*ases and o,3er s,ores1
A=#1N%" is designed s.eciicall/ or message-*ased We* a..lica,ions w3ile s,ill
.roviding .reera*le unc,ionali,/ or o,3er a..lica,ion arc3i,ec,ures1 B/ su..or,ing
loosel/ cou.led access ,o da,a: A=#1N%" ma;imiDes da,a s3aring */ reducing ,3enum*er o ac,ive connec,ions ,o ,3e da,a*ase reducing ,3e .ossi*ili,/ o mul,i.le users
con,ending or limi,ed resources on ,3e da,a*ase server1
A=#1N%" .rovides several wa/s ,o access da,a1 /our We* a..lica,ion or @'$ We*
service reuires da,a access rom mul,i.le sources: needs ,o in,ero.era,e wi,3 o,3era..lica,ions (*o,3 local and remo,e): or can *enei, rom .ersis,ing and ,ransmi,,ing
cac3ed resul,s: ,3e da,ase, is an e;cellen, c3oice1 As an al,erna,ive: A=#1N%" .rovides
da,a commands and da,a readers ,o communica,e direc,l/ wi,3 ,3e da,a source1 =irec,da,a*ase o.era,ions using da,a commands and da,a readers include running ueries and
s,ored .rocedures: crea,ing
#dvanta(es of #DO.NET over #DO
Interoperabi+ity
A=#1N%" a..lica,ions can ,a9e advan,age o ,3e le;i*ili,/ and *road acce.,ance o
@'$1 Because @'$ is ,3e orma, or ,ransmi,,ing da,ase,s across ,3e ne,wor9: an/
com.onen, ,3a, can read ,3e @'$ orma, can .rocess da,a1 n ac,: ,3e receiving
com.onen, need no, *e an A=#1N%" com.onen, a, all "3e ,ransmi,,ing com.onen, cansim.l/ ,ransmi, ,3e da,ase, ,o i,s des,ina,ion wi,3ou, regard ,o 3ow ,3e receiving
com.onen, is im.lemen,ed1 "3e des,ina,ion com.onen, mig3, *e a Visual ,udio
a..lica,ion or an/ o,3er a..lica,ion im.lemen,ed wi,3 an/ ,ool w3a,soever1 "3e onl/reuiremen, is ,3a, ,3e receiving com.onen, *e a*le ,o read @'$1 As an indus,r/
s,andard: @'$ was designed wi,3 e;ac,l/ ,3is 9ind o in,ero.era*ili,/ in mind1
Navgu+ara, BCA Page 72 o 6
-
8/14/2019 Visual Programming.pdf
33/96
Advanced Visual and Windows Programming(BCA-205)
'aintainabi+ity
n ,3e lie o a de.lo/ed s/s,em: modes, c3anges are .ossi*le: *u, su*s,an,ial:
arc3i,ec,ural c3anges are rarel/ a,,em.,ed *ecause ,3e/ are so diicul,1 "3a, isunor,una,e: *ecause in a na,ural course o even,s: suc3 su*s,an,ial c3anges can *ecome
necessar/1 &or e;am.le: as a de.lo/ed a..lica,ion *ecomes .o.ular wi,3 users: ,3eincreased .erormance load mig3, reuire arc3i,ec,ural c3anges1 As ,3e .erormance loadon a de.lo/ed a..lica,ion server grows: s/s,em resources can *ecome scarce and
res.onse ,ime or ,3roug3.u, can suer1 &aced wi,3 ,3is .ro*lem: so,ware arc3i,ec,s can
c3oose ,o divide ,3e server
-
8/14/2019 Visual Programming.pdf
34/96
Advanced Visual and Windows Programming(BCA-205)
a..lica,ion mig3, serve a doDen users well: i, mig3, no, serve 3undreds or 3undreds o
,3ousands euall/ well1 An a..lica,ion ,3a, consumes resources suc3 as da,a*ase
loc9s and da,a*ase connec,ions will no, serve 3ig3 num*ers o users well: *ecause ,3euser demand or ,3ose limi,ed resources will even,uall/ e;ceed ,3eir su..l/1
In=*e*ory %epresentations of Data
n A=#: ,3e in-memor/ re.resen,a,ion o da,a is ,3e recordse,1 n A=#1N%": i, is ,3e
da,ase,1 "3ere are im.or,an, dierences *e,ween ,3em1
!ata %a'igation and Cursors
n A=# /ou scan seuen,iall/ ,3roug3 ,3e rows o ,3e recordse, using ,3e A=#
'oveNe-tme,3od1 n A=#1N%": rows are re.resen,ed as collec,ions: so /ou can loo.
,3roug3 a ,a*le as /ou would ,3roug3 an/ collec,ion: or access .ar,icular rows via ordinalor .rimar/ 9e/ inde;1 Data%e+ationo*+ec,s main,ain inorma,ion a*ou, mas,er and de,ail
records and .rovide a me,3od ,3a, allows /ou ,o ge, records rela,ed ,o ,3e one /ou arewor9ing wi,31 &or e;am.le: s,ar,ing rom ,3e row o ,3e &,"estor,a*le or Na,e un:
/ou can naviga,e ,o ,3e se, o rows o ,3e :rc8ase,a*le descri*ing 3is .urc3ases1
A cursoris a da,a*ase elemen, ,3a, con,rols record naviga,ion: ,3e a*ili,/ ,o u.da,e da,a:
and ,3e visi*ili,/ o c3anges made ,o ,3e da,a*ase */ o,3er users1 A=#1N%" does no,3ave an in3eren, cursor o*+ec,: *u, ins,ead includes da,a classes ,3a, .rovide ,3e
unc,ionali,/ o a ,radi,ional cursor1 &or e;am.le: ,3e unc,ionali,/ o a orward-onl/:
read-onl/ cursor is availa*le in ,3e A=#1N%" Data%eadero*+ec,1 &or more inorma,ion
a*ou, cursor unc,ionali,/: see =a,a Access "ec3nologies1
C"oosing A!#$%&T or A!#
Bo,3 A=#1N%" and A=# are eas/ ,o .rogram: language-inde.enden,: im.lemen,ed wi,3
a small oo,.rin,: use minimal ne,wor9 ,raic: and reuire ew la/ers *e,ween ,3e
a..lica,ion
-
8/14/2019 Visual Programming.pdf
35/96
Advanced Visual and Windows Programming(BCA-205)
"3e A=# recordse, is a single ,a*le: accessi*le onl/ as a recordse,: and does no,
con,ain rela,ions3i.s1 An A=# recordse, can *e ,3e resul, o a mul,i.le ,a*le
#N uer/: *u, i, is s,ill onl/ a single resul, ,a*le1 /ou wan, mul,i.le ,a*leswi,3 A=#: /ou mus, 3ave mul,i.le !ecordse, o*+ec,s1 "3e A=#1N%" da,ase,
.rovides *e,,er unc,ionali,/ due ,o i,s in,egra,ed rela,ional s,ruc,ure1
Data sharin( A=#1N%" .rovides ,3e *asis or da,a in,erc3ange *e,ween
com.onen,s and across ,iers da,ase,s can *e .assed over ,3e n,erne, and ,3roug3irewalls as @'$1 Eou can view ,3e same se, o da,a as rela,ional ,a*les wi,3in
/our a..lica,ion and as an @'$ da,a s,ruc,ure in some o,3er a..lica,ion1 "3e
da,ase, .rovides convenien, ,wo-wa/ ,ransorma,ion rom da,ase, ,a*les ,o an@'$ documen,: and rom an @'$ documen, in,o da,ase, ,a*les1
/ou use C#' mars3aling ,o ,ransmi, an A=# recordse,: ,3e ,arge, a..lica,ion
mus, *e .rogrammed ,o use ,3e recordse, da,a s,ruc,ure1 "3is reuires more
diicul, .rogramming ,3an sim.l/ reading @'$ da,a1 Al,erna,ivel/: /ou can
.ersis, ,3e A=# recordse, as @'$ and more easil/ s3are ,3e da,a wi,3 o,3era..lica,ions and services1
Sca+abi+ity A=#1N%" is ,3e mos, scala*le solu,ion1 A=#1N%" is designed rom
,3e ground u. ,o *e ,3e *es, da,a access arc3i,ec,ure or *uilding scala*le We*a..lica,ions wi,3 a low ,o,al cos, o owners3i.1 /ou do no, need ,3e scala*ili,/:
and are no, wri,ing in managed code: /ou can con,inue ,o use A=#1
)rsor +ocation An a..lica,ion can es,a*lis3 resul, se,s in ei,3er o ,wo .laceswi,3in ,3e a..lica,ion .rocess (clien,-side cursor) or wi,3in ,3e da,a s,ore .rocess
(server-side cursor)1 Clien,-side cursors are generall/ a good c3oice or an/ ,/.e
o im.rom.,u user in,erac,ion wi,3 ,3e da,a1 Clien,-side cursors are su..or,ed in
A=#1N%" */ ,3e =a,ae, o*+ec, and in A=# */ ,3e Clien,Cursor !ecordse,o*+ec,1
Introduction to !ata Access it" A!#$%&T
As /ou develo. a..lica,ions using A=#1N%": /ou will 3ave dieren, reuiremen,s or
wor9ing wi,3 da,a1 n some cases: /ou mig3, sim.l/ wan, ,o dis.la/ da,a on a orm1 n
o,3er cases: /ou mig3, need ,o devise a wa/ ,o s3are inorma,ion wi,3 ano,3er com.an/1
No ma,,er w3a, /ou do wi,3 da,a: ,3ere are cer,ain undamen,al conce.,s ,3a, /ou s3ouldunders,and a*ou, ,3e da,a a..roac3 in A=#1N%"1 Eou mig3, never need ,o 9now some
o ,3e de,ails o da,a 3andling or e;am.le: /ou mig3, never need ,o direc,l/ edi, an@'$ ile con,aining da,a *u, i, is ver/ useul ,o unders,and ,3e da,a arc3i,ec,ure in
A=#1N%": w3a, ,3e ma+or da,a com.onen,s are: and 3ow ,3e .ieces i, ,oge,3er1
"3is in,roduc,ion .resen,s a 3ig3-level overview o ,3ese mos, im.or,an, conce.,s1 "3e
,o.ic deli*era,el/ s9i.s over man/ de,ails or e;am.le: ,3ere is muc3 more ,o da,ase,s
,3an w3a, is men,ioned 3ere in avor o sim.l/ in,roducing /ou ,o ideas *e3ind da,ain,egra,ion in A=#1N%"1
Navgu+ara, BCA Page 75 o 6
-
8/14/2019 Visual Programming.pdf
36/96
Advanced Visual and Windows Programming(BCA-205)
A!#$%&T !oes %ot !epend #n Continuously Li'e Connections
n ,radi,ional clien,Lserver a..lica,ions: com.onen,s es,a*lis3 a connec,ion ,o a da,a*ase
and 9ee. i, o.en w3ile ,3e a..lica,ion is running1 &or a varie,/ o reasons: ,3is a..roac3is im.rac,ical in man/ a..lica,ions
#.en da,a*ase connec,ions ,a9e u. valua*le s/s,em resources1 n mos, cases:
da,a*ases can main,ain onl/ a small num*er o concurren, connec,ions1 "3e
over3ead o main,aining ,3ese connec,ions de,rac,s rom overall a..lica,ion.erormance1
imilarl/: a..lica,ions ,3a, reuire an o.en da,a*ase connec,ion are e;,remel/
diicul, ,o scale u.1 An a..lica,ion ,3a, does no, scale u. well mig3, .erormacce.,a*l/ wi,3 our users *u, will li9el/ no, do so wi,3 3undreds1 AP1N%" We*
a..lica,ions in .ar,icular need ,o *e easil/ scala*le: *ecause ,raic ,o a We* si,e
can go u. */ orders o magni,ude in a ver/ s3or, .eriod1
n AP1N%" We* a..lica,ions: ,3e com.onen,s are in3eren,l/ disconnec,ed rom
eac3 o,3er1 "3e *rowser reues,s a .age rom ,3e serverQ w3en ,3e server 3asinis3ed .rocessing and sending ,3e .age: i, 3as no ur,3er connec,ion wi,3 ,3e
*rowser un,il ,3e ne;, reues,1 Under ,3ese circums,ances: main,aining o.enconnec,ions ,o a da,a*ase is no, via*le: *ecause ,3ere is no wa/ ,o 9now w3e,3er
,3e da,a consumer (,3e clien,) reuires ur,3er da,a access1
A model *ased on alwa/s-connec,ed da,a can ma9e i, diicul, and im.rac,ical ,oe;c3ange da,a across a..lica,ion and organiDa,ional *oundaries using a connec,ed
arc3i,ec,ure1 ,wo com.onen,s need ,o s3are ,3e same da,a: *o,3 3ave ,o *e
connec,ed: or a wa/ mus, *e devised or ,3e com.onen,s ,o .ass da,a *ac9 andor,31
!atabase Interactions Are erformed *sing !ata Commands
"o .erorm o.era,ions in a da,a*ase: /ou e;ecu,e $ s,a,emen,s or s,ored .rocedures
(w3ic3 include $ s,a,emen,s)1 Eou use $ s,a,emen,s or s,ored .rocedures ,o readand wri,e rows and .erorm aggrega,e unc,ions: suc3 as adding or averaging1 Eou also
use $ s,a,emen,s or s,ored .rocedures ,o crea,e or modi/ ,a*les or columns: ,o
.erorm ,ransac,ions: and so on1
n A=#1N%" /ou use da,a commands ,o .ac9age a $ s,a,emen, or s,ored .rocedure1&or e;am.le: i /ou wan, ,o read a se, o rows rom ,3e da,a*ase: /ou crea,e a da,a
command and conigure i, wi,3 ,3e ,e;, o a $ elec, s,a,emen, or ,3e name o a s,ored
.rocedure ,3a, e,c3es records1
W3en /ou wan, ,o ge, ,3e rows: /ou do ,3e ollowing
41 #.en a connec,ion1
21 Call an e;ecu,e me,3od o ,3e command: w3ic3 in ,urn
a1 %;ecu,es ,3e $ s,a,emen, or s,ored .rocedure reerenced */ ,3e
command1
Navgu+ara, BCA Page 76 o 6
-
8/14/2019 Visual Programming.pdf
37/96
Advanced Visual and Windows Programming(BCA-205)
*1 "3en closes ,3e connec,ion1
"3e connec,ion s,a/s o.en onl/ long enoug3 ,o e;ecu,e ,3e s,a,emen, or
s,ored .rocedure1
W3en /ou call a command
-
8/14/2019 Visual Programming.pdf
38/96
Advanced Visual and Windows Programming(BCA-205)
lConnec,ion - an o*+ec, ,3a, manages a connec,ion ,o a $ erver version 10
or la,er1 , is o.,imiDed or use wi,3 $ erver 10 or la,er */ (among o,3er
,3ings) */.assing ,3e #$% =B la/er1
#le=*Connec,ion - an o*+ec, ,3a, manages a connec,ion ,o an/ da,a s,ore
accessi*le via #$% =B1
#d*cConnec,ion - an o*+ec, ,3a, manages a connec,ion ,o a da,a source crea,ed */using a connec,ion s,ring or #=BC da,a source name (=N)1
#racleConnec,ion - an o*+ec, ,3a, manages a connec,ion ,o #racle da,a*ases1
onnection Strin(s
All connec,ion o*+ec,s e;.ose roug3l/ ,3e same mem*ers1 >owever: ,3e s.eciicmem*ers availa*le wi,3 a given O+eDbonnectiono*+ec, de.end on w3a, da,a source i,
is connec,ed ,oQ no, all da,a sources su..or, all mem*ers o ,3e O+eDbonnectionclass1
"3e .rimar/ .ro.er,/ associa,ed wi,3 a connec,ion o*+ec, is ,3e onnectionStrin(
.ro.er,/: w3ic3 consis,s o a s,ring wi,3 a,,ri*u,eLvalue .airs or inorma,ion reuired ,olog on ,o a da,a*ase and .oin, ,o a s.eciic da,a*ase1 A ,/.ical onnectionStrin(.ro.er,/ mig3, loo9 li9e ,3e ollowing
:ro"ier=S;%O%
-
8/14/2019 Visual Programming.pdf
39/96
Advanced Visual and Windows Programming(BCA-205)
Desi(n=Ti*e onnections in Server E-p+orer
erver %;.lorer .rovides a wa/ or /ou ,o crea,e design-,ime connec,ions ,o da,a sources1
"3is .ermi,s /ou ,o *rowse availa*le da,a sourcesQ dis.la/ inorma,ion a*ou, ,3e ,a*les:columns: and o,3er elemen,s ,3e/ con,ainQ and edi, and crea,e da,a*ase elemen,s1
Eour a..lica,ion does no, direc,l/ use ,3e connec,ions /ou crea,e ,3is wa/1 Generall/: ,3e
inorma,ion .rovided */ a design-,ime connec,ion is used ,o se, .ro.er,ies or a new
connec,ion o*+ec, ,3a, /ou add ,o /our a..lica,ion1
onnection Desi(n Too+s in Vis)a+ St)dio
Eou usuall/ do no, need ,o direc,l/ crea,e and manage connec,ion o*+ec,s in Visual
,udio1 W3en /ou use ,ools suc3 as ,3e =a,a Ada.,er WiDard: ,3e ,ools ,/.icall/ .rom.,
/ou or connec,ion inorma,ion (,3a, is: connec,ion-s,ring inorma,ion) and au,oma,icall/
crea,e connec,ion o*+ec,s or /ou on ,3e orm or com.onen, /ou are wor9ing wi,31
>owever: i /ou wan,: /ou can add connec,ion o*+ec,s /oursel ,o a orm or com.onen,
and se, ,3eir .ro.er,ies1 "3is is useul i /ou are no, wor9ing wi,3 da,ase,s (and ,3ereoreno, wi,3 da,a ada.,ers): *u, ins,ead sim.l/ reading da,a1 Eou mig3, crea,e connec,ion
o*+ec,s /oursel i /ou will *e using ,ransac,ions1
Introduction to !ata Adapters
=a,a ada.,ers are an in,egral .ar, o A=#1N%" managed .roviders: w3ic3 are ,3e se, oo*+ec,s used ,o communica,e *e,ween a da,a source and a da,ase,1 (n addi,ion ,o
ada.,ers: managed .roviders include connec,ion o*+ec,s: da,a reader o*+ec,s: andcommand o*+ec,s1) Ada.,ers are used ,o e;c3ange da,a *e,ween a da,a source and ada,ase,1 n man/ a..lica,ions: ,3is means reading da,a rom a da,a*ase in,o a da,ase,: and
,3en wri,ing c3anged da,a rom ,3e da,ase, *ac9 ,o ,3e da,a*ase1 >owever: a da,a ada.,er
can move da,a *e,ween an/ source and a da,ase,1 &or e;am.le: ,3ere could *e an ada.,er,3a, moves da,a *e,ween a 'icroso, %;c3ange server and a da,ase,1
Generall/: ada.,ers are conigura*le ,o allow /ou ,o s.eci/ w3a, da,a ,o move in,o and
ou, o ,3e da,ase,1 #,en ,3is ,a9es ,3e orm o reerences ,o $ s,a,emen,s or s,ored
.rocedures ,3a, are invo9ed ,o read or wri,e ,o a da,a*ase1
Visual ,udio ma9es ,3ese da,a ada.,ers availa*le or use wi,3 da,a*ases
"3e #le=*=a,aAda.,er o*+ec, is sui,a*le or use wi,3 an/ da,a source e;.osed */
an #$% =B .rovider1
"3e l=a,aAda.,er o*+ec, is s.eciic ,o $ erver1 Because i, does no, 3ave ,ogo ,3roug3 an #$% =B la/er: i, is as,er ,3an ,3e O+eDbData#dapter1 >owever:
i, can onl/ *e used wi,3 $ erver 10 or la,er1
"3e #d*c=a,aAda.,er o*+ec, is o.,imiDed or accessing #=BC da,a sources1
Navgu+ara, BCA Page 7 o 6
-
8/14/2019 Visual Programming.pdf
40/96
Advanced Visual and Windows Programming(BCA-205)
"3e #racle=a,aAda.,er o*+ec, is o.,imiDed or accessing #racle da,a*ases1
Data #dapters and %e+ated Tab+es
An im.lica,ion o 3aving se.ara,e ,a*les in ,3e da,ase, is ,3a, a da,a ada.,er ,/.icall/
does no, reerence $ commands or s,ored .rocedures ,3a, +oin ,a*les1 ns,ead:
inorma,ion rom ,3e rela,ed ,a*les is read se.ara,el/ in,o ,3e da,ase, */ dieren,ada.,ers1 "3en a Data%e+ationo*+ec, is used ,o manage cons,rain,s *e,ween ,3e da,ase,
,a*les (suc3 as cascading u.da,es) and ,o allow /ou ,o naviga,e *e,ween rela,ed mas,er
and c3ild records1
&or e;am.le: imagine ,3a, /ou are wor9ing wi,3 ,wo rela,ed ,a*les in ,3e Nor,3windda,a*ase: Cus,omers and #rders1 !a,3er ,3an s.eci/ing a +oin ,o com*ine *o,3 ,a*les
in,o a single resul, se,: /ou would mos, commonl/ deine ,wo ada.,ers: one ,o .o.ula,e a
Cus,omers ,a*le in ,3e da,ase, and a second ada.,er ,o read #rder records in,o a dieren,da,ase, ,a*le1 "3e individual ada.,ers would .ro*a*l/ include selec,ion cri,eria ,o limi,
,3e num*er o records in ,3e da,a ,a*les1
n ,3e da,ase, /ou would also deine a Data%e+ationo*+ec, s.eci/ing ,3a, order records
are rela,ed ,o cus,omer records */ ,3e Cus,omer= ield1 Eou can s,ill manage ,3e ,a*lesindividuall/: w3ic3 would no, *e .ossi*le i /ou 3ad +oined ,a*les *eore e,c3ing records
rom ,3e da,a source1 &or si,ua,ions w3ere /ou wan,ed ,o wor9 wi,3 rela,ed records: /ou
can invo9e .ro.er,ies and me,3ods o ,3e Data%e+ationo*+ec,1
#DO.NET o**and Obects
Using an ada.,er: /ou can read: add: u.da,e: and dele,e records in a da,a source1 "o allow
/ou ,o s.eci/ 3ow eac3 o ,3ese o.era,ions s3ould occur: an ada.,er su..or,s ,3e
ollowing our .ro.er,ies
Se+ecto**and reerence ,o a command ($ s,a,emen, or s,ored .rocedurename) ,3a, re,rieves rows rom ,3e da,a s,ore1
Inserto**and reerence ,o a command or inser,ing rows in,o ,3e da,a s,ore1 0pdateo**and reerence ,o a command or modi/ing rows in ,3e da,a
s,ore1
De+eteo**and reerence ,o a command or dele,ing rows rom ,3e da,a s,ore1
"3e .ro.er,ies are ,3emselves o*+ec,s ,3e/ are ins,ances o ,3e lCommand:
#le=*Command: #d*cCommand: or #racleCommand class1 "3e o*+ec,s su..or, a
o**andTe-t.ro.er,/ con,aining a reerence ,o an $ s,a,emen, or s,ored .rocedure1
Navgu+ara, BCA Page 80 o 6
-
8/14/2019 Visual Programming.pdf
41/96
Advanced Visual and Windows Programming(BCA-205)
Note "3e command class mus, ma,c3 ,3e connec,ion class1 &or e;am.le: i /ou are
using a S>+onnectiono*+ec, ,o communica,e wi,3 a $ erver: /ou mus, also use
commands ,3a, derive rom ,3e S>+o**andclass1
Al,3oug3 /ou can e;.lici,l/ se, ,3e ,e;, o a command o*+ec,: /ou do no, alwa/s need ,oQ
in man/ si,ua,ions: Visual ,udio will genera,e ,3e $ s,a,emen,s needed1 n addi,ion:,3e ada.,er can au,oma,icall/ genera,e a..ro.ria,e $ s,a,emen,s a, run ,ime i ,3e
0pdateo**and: Inserto**and: or De+eteo**ando*+ec,s are no, s.eciied1 &orde,ails: see Au,oma,icall/ Genera,ed Commands1
>owever: /ou can mani.ula,e command o*+ec,s a, design ,ime and run ,ime in order ,o
3ave more direc, con,rol over 3ow ,3e commands are e;ecu,ed1 &or e;am.le: /ou cancrea,e or modi/ ,3e command associa,ed wi,3 a Se+ecto**ando*+ec, +us, *eore i, is
e;ecu,ed1
Eou can also e;ecu,e commands /oursel: inde.enden,l/ o ,3e da,a ada.,er1 "3is allows
/ou ,o .ass ar*i,rar/ $ commands ,3roug3 ,3e da,a ada.,er: suc3 as ,3ose used ,odeine or modi/ da,a*ase deini,ions1 Eou can also call s,ored .rocedures direc,l/ ,3a, do
no, re,urn record se,s or e;am.le: a s,ored .rocedure ,3a, valida,es a user en,r/
o**and Para*eters
"3e commands in a da,a ada.,er are usuall/ .arame,er-driven1 "3e command or ,3e
Se+ecto**and.ro.er,/: or e;am.le: o,en 3as a .arame,er in i,s W>%!% clause so
/ou can s.eci/ a, run ,ime w3a, records ,o ge, rom ,3e da,a*ase1 "3e o,3er commands
use .arame,ers ,3a, allow /ou ,o .ass a, run ,ime ,3e da,a ,o wri,e in,o a record and w3a,record in ,3e da,a*ase ,o u.da,e1 &or more inorma,ion a*ou, 3ow .arame,ers are used in
da,a ada.,ers: see Parame,ers in =a,a-Ada.,er Commands1
%eadin( and 0pdatin( 4ith Data #dapters
"3e .rimar/ .ur.ose o ,3e da,a ada.,er is ,o communica,e da,a *e,ween a da,a s,ore anda da,ase,1 "3e ada.,er su..or,s s.eciic me,3ods ,o move ,3e da,a *ac9 and or,3 *e,ween
,3e ,wo1
Note /ou +us, wan, ,o read da,a (no, u.da,e i,): /ou do no, 3ave ,o s,ore i, in a da,ase,1
ns,ead: /ou can read direc,l/ ou, o ,3e da,a*ase and in,o an a..lica,ion1 &or de,ails: see
!ead-#nl/ =a,a *elow1
Eou can use a da,a ada.,er ,o .erorm ,3e ollowing o.era,ions
!e,rieve rows rom a da,a s,ore in,o corres.onding da,a ,a*les wi,3in ,3e da,ase,1
"o re,rieve rows in,o a da,ase,: use ,3e Fi++me,3od on a da,a ada.,er o*+ec,
(l=a,aAda.,er: #le=*=a,aAda.,er: #d*c=a,aAda.,er: or #racle=a,aAda.,er)1
Navgu+ara, BCA Page 84 o 6
http://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/vbcon/html/vbconparametersindataadaptercommands.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/vbcon/html/vbconparametersindataadaptercommands.htm -
8/14/2019 Visual Programming.pdf
42/96
Advanced Visual and Windows Programming(BCA-205)
W3en /ou invo9e ,3e Fi++me,3od: i, ,ransmi,s an $ %$%C" s,a,emen, ,o ,3e
da,a s,ore1
"ransmi, c3anges made ,o a da,ase, ,a*le ,o ,3e corres.onding da,a s,ore1
A!#$%&T !atasets
=a,ase,s are con,ainers cac3es in w3ic3 /ou can s,ore da,a ,o use in /our
a..lica,ion1 =a,ase,s are a undamen,al .ar, o ,3e A=#1N%" arc3i,ec,ure: .roviding*o,3 3ig3-.erormance da,a access as well as scala*ili,/1
=a,ase,s s,ore da,a in a disconnec,ed cac3e1 "3e s,ruc,ure o a da,ase, is similar ,o ,3a, o
a rela,ional da,a*aseQ i, e;.oses a 3ierarc3ical o*+ec, model o ,a*les: rows: and columns1
n addi,ion: i, con,ains cons,rain,s and rela,ions3i.s deined or ,3e da,ase,1
"3e undamen,al .ar,s o a da,ase, are e;.osed ,o /ou ,3roug3 s,andard .rogramming
cons,ruc,s suc3 as .ro.er,ies and collec,ions1 &or e;am.le
"3e =a,ae, class includes ,3e "a*les collec,ion o da,a ,a*les and ,3e !ela,ions
collec,ion o =a,a!ela,ion o*+ec,s1
"3e =a,a"a*le class includes ,3e !ows collec,ion o ,a*le rows: ,3e Columns
collec,ion o da,a columns: and ,3e C3ild!ela,ions and Paren,!ela,ions
collec,ions o da,a rela,ions1
"3e =a,a!ow class includes ,3e !ow,a,e .ro.er,/: w3ose values indica,ew3e,3er and 3ow ,3e row 3as *een c3anged since ,3e da,a ,a*le was irs, loaded
rom ,3e da,a*ase1 Possi*le values or ,3e !ow,a,e .ro.er,/ include De+eted:'odified: Ne4: and 0nchan(ed1
Typed vers)s 0ntyped Datasets
=a,ase,s can *e ,/.ed or un,/.ed1 A ,/.ed da,ase, is a da,ase, ,3a, is irs, derived rom
,3e *ase DataSetclass and ,3en uses inorma,ion in an @'$ c3ema ile (an 1;sd ile) ,o
genera,e a new class1 norma,ion rom ,3e sc3ema (,a*les: columns: and so on) isgenera,ed and com.iled in,o ,3is new da,ase, class as a se, o irs,-class o*+ec,s and
.ro.er,ies1
Because a ,/.ed DataSetclass in3eri,s rom ,3e *ase DataSetclass: ,3e ,/.ed class
assumes all o ,3e unc,ionali,/ o ,3e DataSetclass and can *e used wi,3 me,3ods ,3a,,a9e an ins,ance o a DataSetclass as a .arame,er
An un,/.ed da,ase,: in con,ras,: 3as no corres.onding *uil,-in sc3ema1 As in a ,/.ed
da,ase,: an un,/.ed da,ase, con,ains ,a*les: columns: and so on *u, ,3ose are e;.osed
onl/ as collec,ions1 (>owever: a,er manuall/ crea,ing ,3e ,a*les and o,3er da,a elemen,s
Navgu+ara, BCA Page 82 o 6
-
8/14/2019 Visual Programming.pdf
43/96
Advanced Visual and Windows Programming(BCA-205)
in an un,/.ed da,ase,: /ou can e;.or, ,3e da,ase,
-
8/14/2019 Visual Programming.pdf
44/96
Advanced Visual and Windows Programming(BCA-205)
=a,a!eader1 Using ,3e =a,a!eader can increase a..lica,ion .erormance *o,3 */
re,rieving da,a as soon as i, is availa*le: ra,3er ,3an wai,ing or ,3e en,ire resul,s o ,3e
uer/ ,o *e re,urned: and (*/ deaul,) s,oring onl/ one row a, a ,ime in memor/: reducings/s,em over3ead1
A,er crea,ing an ins,ance o ,3e Command o*+ec,: /ou crea,e a =a,a!eader */ callingCommand1%;ecu,e!eader ,o re,rieve rows rom a da,a source: as s3own in ,3e ollowing
e;am.le1
XVisual BasicY
=im m/!eader As l=a,a!eader F m/Command1%;ecu,e!eader()
Eou use ,3e %eadme,3od o ,3e Data%eadero*+ec, ,o o*,ain a row rom ,3e resul,s o
,3e uer/1 Eou can access eac3 column o ,3e re,urned row */ .assing ,3e name or
ordinal reerence o ,3e column ,o ,3e Data%eader1 >owever: or *es, .erormance: ,3e
Data%eader.rovides a series o me,3ods ,3a, allow /ou ,o access column values in ,3eirna,ive da,a ,/.es (/etDateTi*e: /etDo)b+e: /et/)id: /etInt9: and so on)1 &or a lis,
o ,/.ed accessor me,3ods
+osin( the Data%eader
Eou s3ould alwa/s call ,3e +oseme,3od w3en /ou 3ave inis3ed using ,3e Data%eadero*+ec,1
/our o**andcon,ains ou,.u, .arame,ers or re,urn values: ,3e/ will no, *e availa*leun,il ,3e Data%eaderis closed1
No,e ,3a, w3ile a Data%eaderis o.en: ,3e onnectionis in use e;clusivel/ */ ,3a,
Data%eader1 Eou will no, *e a*le ,o e;ecu,e an/ commands or ,3e onnection:
including crea,ing ano,3er Data%eader: un,il ,3e original Data%eaderis closed1
Navgu+ara, BCA Page 88 o 6
-
8/14/2019 Visual Programming.pdf
45/96
Advanced Visual and Windows Programming(BCA-205)
E%%O% $#ND"IN/
Types of &rrors
n Visual Basic: errors (also called exceptions) all in,o one o ,3ree ca,egories s/n,a;errors: run-,ime errors: and logic errors1
Synta+ &rrors
Syntax errorsare ,3ose ,3a, a..ear w3ile /ou wri,e /our code1 Visual Basic c3ec9s /ourcode as /ou ,/.e and aler,s /ou i /ou ma9e a mis,a9e: suc3 as miss.elling a word orusing a language elemen, im.ro.erl/1 /n,a; errors are ,3e mos, common ,/.e o errors1
Eou can i; ,3em easil/ in ,3e coding environmen, as soon as ,3e/ occur1
Note "3e Option E-p+icits,a,emen, is one means o avoiding s/n,a; errors1 , orces
,3e .rogrammer ,o declare: in advance: all ,3e varia*les ,o *e used in ,3e a..lica,ion1"3ereore: w3en ,3ose varia*les are used in ,3e code: an/ ,/.ogra.3ic errors are caug3,
immedia,el/ and can *e i;ed1
Run-Time &rrors
!un"time errorsare ,3ose ,3a, a..ear onl/ a,er /ou com.ile and run /our code1 "3ese
involve code ,3a, ma/ a..ear ,o *e correc, in ,3a, i, 3as no s/n,a; errors: *u, ,3a, will no,e;ecu,e1 &or e;am.le: /ou mig3, correc,l/ wri,e a line o code ,o o.en a ile1 Bu, i ,3e
ile is corru.,ed: ,3e a..lica,ion canno, carr/ ou, ,3e Openunc,ion: and i, s,o.s running1
Eou can i; mos, run-,ime errors */ rewri,ing ,3e aul,/ code: and ,3en recom.iling andrerunning i,1
Logic &rrors
Logic errorsare ,3ose ,3a, a..ear once ,3e a..lica,ion is in use1 "3e/ mos, o,en ,a9e ,3e
orm o unwan,ed or une;.ec,ed resul,s in res.onse ,o user ac,ions1 &or e;am.le: amis,/.ed 9e/ or o,3er ou,side inluence mig3, cause /our a..lica,ion ,o s,o. wor9ing
wi,3in e;.ec,ed .arame,ers: or al,oge,3er1 $ogic errors are generall/ ,3e 3ardes, ,/.e ,o
i;: since i, is no, alwa/s clear w3ere ,3e/ origina,e1
%rror messages can occur w3ile an a..lica,ion is running: ei,3er wi,3in ,3e VisualBasic 1N%" environmen, or as a s,and-alone e;ecu,a*le1 ome o ,3ese can also occur
during design ,ime or com.ile ,ime1 Eou can ,es, and res.ond ,o ,ra..a*le errors using
Navgu+ara, BCA Page 85 o 6
-
8/14/2019 Visual Programming.pdf
46/96
Advanced Visual and Windows Programming(BCA-205)
,3e On Error s,a,emen, and ,3e Erro*+ec,
-
8/14/2019 Visual Programming.pdf
47/96
Advanced Visual and Windows Programming(BCA-205)
Str)ct)red E-ception $and+in(
n s,ruc,ured e;ce.,ion 3andling: *loc9s o code are enca.sula,ed: wi,3 eac3 *loc9 3aving
one or more associa,ed 3andlers1 %ac3 3andler s.eciies some orm o il,er condi,ion on,3e ,/.e o e;ce.,ion i, 3andles1 W3en an e;ce.,ion is raised */ code in a .ro,ec,ed
*loc9: ,3e se, o corres.onding 3andlers is searc3ed in order: and ,3e irs, one wi,3 ama,c3ing il,er condi,ion is e;ecu,ed1 A single me,3od can 3ave mul,i.le s,ruc,urede;ce.,ion 3andling *loc9s: and ,3e *loc9s can also *e nes,ed wi,3in eac3 o,3er1
"3e Try...atch...Fina++ys,a,emen, is used s.eciicall/ or s,ruc,ured e;ce.,ion
3andling1 &or more inorma,io1
0nstr)ct)red E-ception $and+in(
"3e OnErrors,a,emen, is used s.eciicall/ or uns,ruc,ured e;ce.,ion 3andling1 n
uns,ruc,ured e;ce.,ion 3andling: On Erroris .laced a, ,3e *eginning o a *loc9 o code1, ,3en 3as sco.e over ,3a, *loc9Q i, 3andles an/ errors occurring wi,3in ,3e *loc91 ,3e
.rogram encoun,ers ano,3er On Errors,a,emen,: ,3a, s,a,emen, *ecomes valid and ,3eirs, s,a,emen, *ecomes
Try$$$Catc"$$$,inally Statements
Provides a wa/ ,o 3andle some or all .ossi*le errors ,3a, ma/ occur in a given *loc9 o
code: w3ile s,ill running code1
Try
? tryStatements@? Catch? exception?Astype@ @ ?Whenexpression@
? catchStatements@ @? Exit Try@...? Finally ? finallyStatements@ @End Try
Parts
tryStatements#.,ional1 ,a,emen,(s) w3ere an error can occur1 Can *e a com.ound s,a,emen,1
atch
#.,ional1 'ul,i.le atch*loc9s .ermi,,ed1 an e;ce.,ion occurs w3ile
.rocessing ,3e Try*loc9: eac3 atchs,a,emen, is e;amined in ,e;,ual orderexception
#.,ional1 An/ varia*le name1 "3e ini,ial value o exceptionis ,3e value o ,3e
,3rown error1 Used wi,3 atch,o s.eci/ ,3e error caug3,1
Navgu+ara, BCA Page 8 o 6
-
8/14/2019 Visual Programming.pdf
48/96
Advanced Visual and Windows Programming(BCA-205)
When
#.,ional1 A atchs,a,emen, wi,3 a Whenclause will onl/ ca,c3 e;ce.,ions
w3en expressionevalua,es ,o Tr)e1 A When clause is onl/ a..lied a,er c3ec9ing,3e ,/.e o ,3e e;ce.,ion: and expressionma/ reer ,o ,3e iden,iier re.resen,ing
,3e e;ce.,ion1
expression#.,ional1 'us, *e im.lici,l/ conver,i*le ,o Boo+ean1 An/ e;.ression ,3a,
descri*es a generic il,er1 "/.icall/ used ,o il,er */ error num*er1 Used wi,3
When9e/word ,o s.eci/ circums,ances under w3ic3 ,3e error is caug3,1catchStatements
#.,ional1 ,a,emen,(s) ,o 3andle errors occurring in ,3e associa,ed Try*loc91 Can
*e a com.ound s,a,emen,1
E-it Try#.,ional1 e/word ,3a, *rea9s ou, o ,3e Try...atch...Fina++y s,ruc,ure1
%;ecu,ion resumes wi,3 ,3e Fina++y*loc9 i .resen,: o,3erwise wi,3 ,3e code
immedia,el/ ollowing ,3e End Trys,a,emen,1 No, allowed in Fina++y*loc9s1
Fina++y#.,ional1 A Fina++y*loc9 is alwa/s e;ecu,ed w3en e;ecu,ion leaves an/ .ar, o
,3e Trys,a,emen,1#inallyStatements
#.,ional1 ,a,emen,(s) ,3a, are e;ecu,ed a,er all o,3er error .rocessing 3as
occurred1
End Try
"ermina,es ,3e Try...atch...Fina++ys,ruc,ure1
"3e Try*loc9 con,ains code w3ere an error can occur: w3ile ,3e atch*loc9 con,ains
code ,o 3andle an/ error ,3a, does occur1 an error occurs in ,3e Try*loc9: .rogram
con,rol is .assed ,o ,3e a..ro.ria,e atchs,a,emen, or dis.osi,ion1 "3e exceptionargumen, is an ins,ance o ,3e E-ceptionclass or an ins,ance o a class ,3a, derives rom
,3e E-ceptionclass corres.onding ,o ,3e error ,3a, occurred in ,3e Try*loc91 "3e
E-ceptionclass ins,ance con,ains inorma,ion a*ou, ,3e error including: among o,3er,3ings: i,s num*er and message1
:ri"ate Sb 7tto,1ClicB#7Val se,er As Sstem.Object) 7Val e As Sstem.
-
8/14/2019 Visual Programming.pdf
49/96
Advanced Visual and Windows Programming(BCA-205)
:blic Sb Tr
-
8/14/2019 Visual Programming.pdf
50/96
Advanced Visual and Windows Programming(BCA-205)
An #rraycan 3ave mul,i.le dimensions: w3ile an #rray"istalwa/s 3as e;ac,l/
one dimension1
An #rrayo a s.eciic ,/.e (o,3er ,3an Obect) 3as *e,,er .erormance ,3an an
#rray"ist*ecause ,3e elemen,s o #rray"istare o ,/.e Obectand: ,3ereore:
*o;ing and un*o;ing ,/.icall/ occur i s,oring or re,rieving a value ,/.e1
'os, si,ua,ions ,3a, call or an arra/ can use #rray"istins,ead1 , is easier ,o use and: in
general: 3as .erormance similar ,o an arra/ o ,/.e Obect1
#rrayis in ,3e Syste*names.aceQ #rray"istis in ,3e Syste*.o++ectionsnames.ace1
P)b+ic Properties
Ca.aci,/ Ge,s or se,s ,3e num*er o elemen,s ,3a, ,3e #rray"istcan con,ain1
Coun,
Ge,s ,3e num*er o elemen,s ac,uall/ con,ained in ,3e #rray"ist1
s&i;ediDe Ge,s a value indica,ing w3e,3er ,3e #rray"ist3as a i;ed siDe1
s!ead#nl/
Ge,s a value indica,ing w3e,3er ,3e #rray"istis read-onl/1
s/nc3roniDedGe,s a value indica,ing w3e,3er access ,o ,3e #rray"istis s/nc3roniDed (,3read-sa
P)b+ic 'ethodsAda.,er
Crea,es an #rray"istwra..er or a s.eciic $is,1
AddAdds an o*+ec, ,o ,3e end o ,3e #rray"ist1
Add!ange
Adds ,3e elemen,s o an Collec,ion,o ,3e end o ,3e #rray"ist1
Binar/earc3#verloaded1 Uses a *inar/ searc3 algori,3m ,o loca,e a s.eciic elemen, in ,3e
sor,ed #rray"istor a .or,ion o i,1
Clear !emoves all elemen,s rom ,3e #rray"ist1
Clone
Crea,es a s3allow co./ o ,3e #rray"ist1
Con,ains=e,ermines w3e,3er an elemen, is in ,3e #rray"ist1
Co./"o
#verloaded1 Co.ies ,3e #rray"istor a .or,ion o i, ,o a one-dimensional arra/1
Navgu+ara, BCA Page 50 o 6
http://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscapacitytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscounttopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassisfixedsizetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassisreadonlytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassissynchronizedtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassadaptertopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsilistclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassaddrangetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassbinarysearchtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscopytotopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscapacitytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscounttopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassisfixedsizetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassisreadonlytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassissynchronizedtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassadaptertopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsilistclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassaddrangetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassbinarysearchtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsarraylistclasscopytotopic.htm -
8/14/2019 Visual Programming.pdf
51/96
Advanced Visual and Windows Programming(BCA-205)
%uals
#verloaded1 =e,ermines w3e,3er ,wo #*+ec,ins,ances are eual1
nser,nser,s an elemen, in,o ,3e #rray"ista, ,3e s.eciied inde;1
nser,!ange
nser,s ,3e elemen,s o a collec,ion in,o ,3e #rray"ista, ,3e s.eciied inde;1!emove
!emoves ,3e irs, occurrence o a s.eciic o*+ec, rom ,3e #rray"ist1
!e.ea,
!e,urns an #rray"istw3ose elemen,s are co.ies o ,3e s.eciied value1
!everse
#verloaded1 !everses ,3e order o ,3e elemen,s in ,3e #rray"istor a .or,ion o i,
>as3,a*le Class
A $ashtab+econsis,s o *uc9e,s ,3a, con,ain ,3e elemen,s o ,3e collec,ion1 A *uc9e, is a
vir,ual su*grou. o elemen,s wi,3in ,3e $ashtab+e: w3ic3 ma9es searc3ing and re,rievingeasier and as,er ,3an in mos, collec,ions1 %ac3 *uc9e, is associa,ed wi,3 a 3as3 code:
genera,ed using a 3as3 unc,ion and *ased on ,3e 9e/ o ,3e elemen,1
A 3as3 unc,ion is an algori,3m ,3a, re,urns a numeric 3as3 code *ased on a 9e/1 "3e 9e/is ,3e value o some .ro.er,/ o ,3e o*+ec, *eing s,ored1 A 3as3 unc,ion mus, alwa/s
re,urn ,3e same 3as3 code or ,3e same 9e/1 , is .ossi*le or a 3as3 unc,ion ,o genera,e
,3e same 3as3 code or ,wo dieren, 9e/s: *u, a 3as3 unc,ion ,3a, genera,es a uniue
3as3 code or eac3 uniue 9e/ resul,s in *e,,er .erormance w3en re,rieving elemen,srom ,3e 3as3 ,a*le1
W3en an o*+ec, is added ,o a $ashtab+e: i, is s,ored in ,3e *uc9e, ,3a, is associa,ed wi,3
,3e 3as3 code ,3a, ma,c3es ,3e o*+ec,
-
8/14/2019 Visual Programming.pdf
52/96
Advanced Visual and Windows Programming(BCA-205)
,em Ge,s or se,s ,3e value associa,ed wi,3 ,3e
s.eciied 9e/1
e/s Ge,s an Collec,ioncon,aining ,3e 9e/s in,3e $ashtab+e1
/nc!oo, Ge,s an o*+ec, ,3a, can *e used ,o
s/nc3roniDe access ,o ,3e $ashtab+e1
Values Ge,s an Collec,ioncon,aining ,3e values in
,3e $ashtab+e1
P)b+ic 'ethods
AddAdds an elemen, wi,3 ,3e s.eciied 9e/ and
value in,o ,3e $ashtab+e1
Clear !emoves all elemen,s rom ,3e $ashtab+e1
Clone Crea,es a s3allow co./ o ,3e $ashtab+e1
Con,ains =e,ermines w3e,3er ,3e $ashtab+econ,ains
a s.eciic 9e/1
!emove !emoves ,3e elemen, wi,3 ,3e s.eciied 9e/
rom ,3e $ashtab+e1
"o,ring !e,urns a,ring,3a, re.resen,s ,3e curren,
#*+ec,1
SortedList Class
"3e or,ed$is, class is li9e a 3/*rid *e,ween >as3,a*le and Arra/$is,1
As wi,3 $ashtab+e: Sorted"istis *ased on ,3e =ic,ionar/ in,eraceQ ,3ereore: eac3
elemen, o a Sorted"istis a 9e/-and-value .air1 Sorted"ist.rovides me,3ods ,3a, re,urn
onl/ ,3e lis, o 9e/s or onl/ ,3e lis, o values1
As wi,3 #rray"ist: a Sorted"istis a seuence o elemen,s1 , is inde;ed: and is sor,ed
according ,o a s.eciied com.arer1
Sorted"istis uniue among all Collec,ions classes in ,3a, eac3 elemen, can *e accessed,3ree wa/s using ,3e 9e/: ,3e value: or ,3e inde;1
Navgu+ara, BCA Page 52 o 6
http://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassitemtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasskeystopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasssyncroottopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasssyncroottopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassvaluestopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassvaluestopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassremovetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemobjectclasstostringtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemstringclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemstringclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemobjectclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassitemtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasskeystopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasssyncroottopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassvaluestopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionsicollectionclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionshashtableclassremovetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemobjectclasstostringtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemstringclasstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemobjectclasstopic.htm -
8/14/2019 Visual Programming.pdf
53/96
Advanced Visual and Windows Programming(BCA-205)
P)b+ic Properties
Ca.aci,/Ge,s or se,s ,3e ca.aci,/ o ,3e Sorted"ist1
Coun,Ge,s ,3e num*er o elemen,s con,ained in
,3e Sorted"ist1
s&i;ediDe Ge,s a value indica,ing w3e,3er ,3e
Sorted"ist3as a i;ed siDe1
s!ead#nl/ Ge,s a value indica,ing w3e,3er ,3e
Sorted"istis read-onl/1
s/nc3roniDed Ge,s a value indica,ing w3e,3er access ,o
,3e Sorted"istis s/nc3roniDed (,3read-
sae)1
,em Ge,s and se,s ,3e value associa,ed wi,3 as.eciic 9e/ in ,3e Sorted"ist1
e/s Ge,s ,3e 9e/s in ,3e Sorted"ist1
/nc!oo, Ge,s an o*+ec, ,3a, can *e used ,o
s/nc3roniDe access ,o ,3e Sorted"ist1
ValuesGe,s ,3e values in ,3e Sorted"ist1
P)b+ic 'ethods
AddAdds an elemen, wi,3 ,3e s.eciied 9e/ and
value ,o ,3e Sorted"ist1
Clear!emoves all elemen,s rom ,3e Sorted"ist1
CloneCrea,es a s3allow co./ o ,3e Sorted"ist1
Con,ains=e,ermines w3e,3er ,3e Sorted"istcon,ains
a s.eciic 9e/1
Serialiation.inder Class
Allows users ,o con,rol class loading and manda,e w3a, class ,o load1
P)b+ic 'ethods
Bind"o"/.eW3en overridden in a derived class: con,rols
,3e *inding o a serialiDed o*+ec, ,o a ,/.e1
Navgu+ara, BCA Page 57 o 6
http://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscapacitytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscounttopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassisfixedsizetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassisreadonlytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassissynchronizedtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassitemtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasskeystopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasssyncroottopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassvaluestopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemruntimeserializationserializationbinderclassbindtotypetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscapacitytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscounttopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassisfixedsizetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassisreadonlytopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassissynchronizedtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassitemtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasskeystopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasssyncroottopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassvaluestopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassaddtopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscleartopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclassclonetopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcollectionssortedlistclasscontainstopic.htmhttp://ms-help//MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemruntimeserializationserializationbinderclassbindtotypetopic.htm -
8/14/2019 Visual Programming.pdf
54/96
Advanced Visual and Windows Programming(BCA-205)
%uals(in3eri,ed rom Obect)#verloaded1 =e,ermines w3e,3er ,wo #*+ec,
ins,ances are eual1
Ge,>as3Code(in3eri,ed rom Obect)e