Download as pdf or txt
Download as pdf or txt
You are on page 1of 96

Advanced Visual and Windows Programming(BCA-205)

NAVGU A!A" C#$$%G% #& C#'PU"%! APP$(CA"(#N)


)u*+ec,-Advance visual and windows .rogramming(BCA-205) )u*+ec, Code -BCA-205 &acul,/-Pro012aus3ar G3anc3i

Navgu+ara, BCA

Page 4 o0 56

Advanced Visual and Windows Programming(BCA-205)

The .NET Framework


The .NET Framework is the next iteration of Microsoft's platform for developing component-based software. It provides f ndamental advances in r ntime services for application software. It also s pports development of applications that can be free of dependencies on hardware! operating s"stem! and lang age compiler. This chapter provides an overview of the architect re of the .NET Framework and describes the base feat res fo nd in the core of its class librar".

Common Language Infrastructure (CLI) and Common Language Runtime (CLR)


At the heart of the .NET Framework is a new mechanism for loading and running programs and managing their interactions. This mechanism is described in the Common Language Infrastructure (CLI ! a specification for a runtime en"ironment that allows software components to# $%ass data between each other without regard to the programming language in which each component is on paper $E&ecute on different operating s'stems and on different hardware platforms without ha"ing to recompile the high(le"el source code (a low(le"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 to the 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/s CL. 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 of this writing! the CLI has not been implemented on non( 0indows platforms! but )icrosoft and others ha"e announced intentions to do so. The CLI specifies how e&ecutable code is loaded! run! and managed. The portion of the CL. that performs the tasks of loading! running! and managing .NET applications is called 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 Object Model (C3) . As its core feature! C3) specifies how ob,ect interfaces are laid out in memor'. 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 was introduced (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 called the Common Type ystem (CT2 . The CT2 defines at the runtime le"el how t'pes are declared and used.

Navgu+ara, BCA

Page 2 o0 56

Advanced Visual and Windows Programming(BCA-205)


%re"iousl'! language compilers controlled the creation and usage of t'pes! including their la'out in memor'. This led to problems when a component written in one language tried to pass data to a component written in a different language. An'one who has written 1isual 7asic 8 code to call 0indows A%I functions! for instance! or who has tried to pass a 9a"a2cript arra' to a component written either in 1isual 7asic 8 or C::! is aware of this problem. It was up to the de"eloper to translate the data to be understandable to the recei"ing component. The CT2 obliterates this problem b' pro"iding the following features# %rimiti"e t'pes (Integer! 2tring! etc. are defined at the runtime le"el. Components can easil' pass instances of primiti"e t'pes between each other because the' all agree on how that data is formatted. Comple& t'pes (structures! classes! enumerations! etc. are constructed in a wa' that is defined at the runtime le"el. Components can easil' pass instances of comple& t'pes between each other because the' all agree on how comple& t'pes are constructed from primiti"e t'pes. All t'pes carr' rich t'pe information with them! meaning that a component that is handed an ob,ect can find out the definition of the t'pe of which the ob,ect is an instance. This is analogous to t'pe libraries in C3)! but the CT2 is different because the t'pe information is much richer and is guaranteed to be present.

Common Language Specification (CLS)


The CLI defines a runtime that is capable of supporting most! if not all! of the features found in modern programming languages. It is not intended that all languages that target the CL. will support all CL. features. This could cause problems when components written in different languages attempt to interoperate. The CLI therefore defines a subset of features that are considered compatible across language boundaries. This subset is called the Common Language pecification (CL2 . 1endors creating components for use b' others need to ensure that all e&ternall' "isible constructs (e.g.! public t'pes! public and protected methods! parameters on public and protected methods! etc. are CL2(compliant. This ensures that their components will be usable within a broad arra' of languages! including 1isual 7asic .NET. ;e"elopers authoring components in 1isual 7asic .NET ha"e an eas' ,ob because all 1isual 7asic .NET code is CL2(compliant (unless the de"eloper e&plicitl' e&poses a public or protected t'pe member or method parameter that is of a non(CL2(compliant t'pe . 7ecause 1isual 7asic .NET automaticall' generates CL2(compliant components! this book does not describe the CL2 rules. <owe"er! to gi"e 'ou a sense of the kind of thing that the CL2 specifies! consider that some languages support a feature called operator overloading . This allows the de"eloper to specif' actions that should be taken if the standard operator s'mbols ( +! -! *! /! =! etc. are used on user(defined classes. 7ecause it is not reasonable to e&pect that all languages should implement such a feature! the CL2 has a rule about it. The rule states that if a CL2(compliant component has public t'pes that pro"ide o"erloaded operators! those t'pes must pro"ide access to that functionalit' in another wa' as well (usuall' b' pro"iding a public method that performs the same operation .

Intermediate Language (IL) and Just-In-Time (JIT) Compilation


All compilers that target the CL. compile source code to Intermediate Language (IL ! also known as Common Intermediate Language (CIL . IL is a machine language that is not tied to an' specific machine. )icrosoft designed it from scratch to support the CLI/s programming concepts. The CLI specifies that all CL. implementations can compile or interpret IL on the machine on which the CL. is running. If the IL is compiled ("ersus interpreted ! compilation can occur at either of two times# Immediatel' prior to a method in the application being e&ecuted At deplo'ment time In the first case! each method is compiled onl' when it is actuall' needed. After the method is

Navgu+ara, BCA

Page 7 o0 56

Advanced Visual and Windows Programming(BCA-205)


compiled! subse=uent calls b'pass the compilation mechanism and call the compiled code directl'. The compiled code is not sa"ed to disk! so if the application is stopped and restarted! the compilation must occur again. This is known as just!in!time (9IT compilation and is the most common scenario. In the second case! the application is compiled in its entiret' at deplo'ment time. IL is sa"ed to .exe and .dll files. 0hen such a file containing IL is e&ecuted! the CL. knows how to in"oke the 9IT compiler and e&ecute the resulting code. Note that on the )icrosoft 0indows platforms! IL is alwa's compiled-ne"er interpreted.

Metadata
2ource code consists of some constructs that are procedural in nature and others that are declarative in nature. An e&ample 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 compile directl' into the e&ecutable. In the CL.! howe"er! declarati"e information is e"er'thing> The CL. uses 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 appropriate target code at 9IT compile time. The onl' wa' for this to work is for this declarati"e information to be included alongside its associated procedural information. Compilers that target the CL. therefore store both procedural and declarati"e information in the resulting .exe or .dll file. The procedural 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 one(module assembl'. If the "exe is alwa's deplo'ed with two "dll files and one thinks of all three files as comprising an inseparable unit! then the three modules together form an assembl'! but none of them does so b' itself. If the product is a class librar' that e&ists in a "dll file! then that single "dll file 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 an assembl' is deplo'ed! one (and onl' one of the modules in the assembl' must contain the assembly manifest! which contains information about the assembl' as a whole! including the list of modules contained in the assembl'! the "ersion of the assembl'! its culture! etc.

Memory Management and

arbage Collection

In an' ob,ect(oriented 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 no longer being used is called lifetime management! which is not a tri"ial problem. The solution the CL. uses has implications for the design and use of the components 'ou write! so it is worth understanding. In the C3) world! the client of an ob,ect notified the ob,ect whene"er a new ob,ect reference was passed to another client. Con"ersel'! when an' client of an ob,ect was finished with it! the client notified 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' back to 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 o0 56

Advanced Visual and Windows Programming(BCA-205)


7asic compiler automaticall' generated the low(le"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 another and e"er' time an ob,ect reference is o"erwritten. ;ifficult(to(track bugs can be introduced if the reference(counting rules are not precisel' followed. Care must be taken to ensure that circular references are speciall' treated (because circular references 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 as the #eap starts. To satisf' a memor' re=uest! it ,ust hands back a cop' of the pointer and then increments the pointer b' the si*e of the re=uest! lea"ing it in a position to satisf' the ne&t memor' re=uest. This makes memor' allocation "er' fast. No action is taken at all when an ob,ect is no longer being used. As long as the heap doesn/t run out! memor' is not reclaimed until the application e&its. If the heap is large enough to satisf' all memor' re=uests during program e&ecution! this method of memor' allocation is as fast as is theoreticall' possible! because the onl' 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 the heap is e&hausted! the memor' manager looks for an' pre"iousl' allocated memor' that can be reclaimed. It does this b' e&amining the application "ariables that hold ob,ect references. The ob,ects that these "ariables reference (and therefore the associated memor' are considered in use because the' can be reached through the program/s "ariables. Furthermore! because the runtime has complete access to the application/s t'pe information! the memor' manager knows whether the ob,ects contain members that reference other ob,ects! and so on. In this wa'! the memor' manager can find all of the memor' that is in use. ;uring this process! it consolidates the contents of all this memor' into one contiguous block at the start of the heap! lea"ing the remainder 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 applies to this o"erall method of lifetime management. The portion of the memor' manager that performs garbage 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 second when it occurs ! )icrosoft claims that the total o"erhead of garbage collection is on a"erage much less than the total o"erhead of reference counting (as shown b' their benchmarks . This! of course! is highl' dependent on the e&act pattern of ob,ect allocation and deallocation that occurs in an' gi"en program.

.NET Defined
Be0ore ge,,ing dee.l/ in,o ,3e su*+ec, we will 0irs, 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 0rom a Business .ers.ec,ive: ,3ere are ,3ree .3ases o0 ,3e (n,erne,1 "3e &irs, .3ase ge,s *ac9 ,o ,3e earl/ 4550<s w3en (n,erne, 0irs, came in,o general use and w3ic3 *roug3, a *ig revolu,ion 0or Businesses1 (n ,3e &irs, .3ase o0 ,3e (n,erne, Businesses designed and launc3ed ,3eir We*si,e<s and 0ocused on ,3e num*er o0 3i,s ,o 9now 3ow man/ cus,omers were visi,ing ,3eir si,e and in,eres,ed in ,3eir .roduc,s: e,c1 "3e )econd .3ase is w3a, we are in rig3, now and in ,3is .3ase Businesses are genera,ing revenue ,3roug3 #nline "ransac,ions1 We are now moving in,o ,3e "3ird .3ase o0 ,3e (n,erne, w3ere .ro0i, is ,3e main .riori,/1 "3e 0ocus 3ere is ,o Businesses Navgu+ara, BCA Page 5 o0 56

Advanced Visual and Windows Programming(BCA-205) e00ec,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 o0 services1 >ow can ,3a, *e .ossi*le? "3e answer: wi,3 1N%"1

What is .NET ?
'an/ .eo.le rec9on ,3a, i,<s 'icroso0,<s wa/ o0 con,rolling ,3e (n,erne,: w3ic3 is 0alse1 1N%" is 'icroso0,<s s,ra,eg/ o0 so0,ware ,3a, .rovides services ,o .eo.le an/ ,ime: an/ .lace: on an/ device1 An accura,e de0ini,ion o0 1N%" is: i,<s an @'$ We* )ervices .la,0orm w3ic3 allows us ,o *uild ric3 1N%" a..lica,ions: w3ic3 allows users ,o in,erac, wi,3 ,3e (n,erne, using wide range o0 smar, devices (,a*le, devices: .oc9e, PC<s: we* .3ones e,c): w3ic3 allows ,o *uild and in,egra,e We* )ervices and w3ic3 comes wi,3 man/ ric3 se, o0 ,ools li9e Visual ),udio ,o 0ull/ develo. and *uild ,3ose a..lica,ions1

What are Web Services?


We* )ervices are ,3e a..lica,ions ,3a, run on a We* )erver and communica,e wi,3 o,3er a..lica,ions1 (, uses a series o0 .ro,ocols ,o res.ond ,o di00eren, reAues,s1 "3e .ro,ocols on w3ic3 We* )ervices are *uil, are lis,ed *elow U==(- ),ands 0or Universal =iscover/ and =escri.,ion (n,egra,ion W)=$- ),ands 0or We* )ervices =escri.,ion $anguage )#AP- ),ands 0or )im.le #*+ec, Access Pro,ocol @'$: >""P and )'"P

EDITIONS OF VB .NET
Academic %di,ion Pro0essional %di,ion %n,er.rise =evelo.er %di,ion %n,er.rise Arc3i,ec, %di,ion

Types Of Pro ects


Windows A..lica,ions Class $i*raries Windows Con,rol $i*raries )mar, =evice A..lica,ions As. 1Ne, We* A..lica,ions As. 1Ne, We* )ervices As. 1Ne, 'o*ile We* A..lica,ion We* Con,rol $i*rar/ Consol A..lica,ion Windows )ervices

Navgu+ara, BCA

Page 6 o0 56

Advanced Visual and Windows Programming(BCA-205)

T!PES OF FI"ES #ND T$EI% E&TENSIONS


1)uo 1V* )olu,ion User #.,ion &ile 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/ (n0o &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 1Ws0 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 Con0igura,ion &ile 1Asa; A Glo*al A..lica,ion Class 1!e; A !esource &ile "o ),ore !esource (n0orma,ion 1)ln )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 B o0 56

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 0eel ,3a, i, is some,3ing s.ecial1 (n ,3e >is,or/ o0 Com.u,ing world no o,3er .roduc, sold more co.ies ,3an Visual Basic did1 )uc3 is ,3e im.or,ance o0 ,3a, language w3ic3 clearl/ s,a,es 3ow widel/ i, is used 0or develo.ing a..lica,ions1 Visual Basic is ver/ .o.ular 0or i,<s 0riendl/ wor9ing (gra.3ical) environmen,1 Visual Basic1 N%" is an e;,ension o0 Visual Basic .rogramming language wi,3 man/ new 0ea,ures in i,1 "3e c3anges 0rom VB ,o VB 1N%" are 3uge: ranging 0rom ,3e c3ange in s/n,a; o0 ,3e language ,o ,3e ,/.es o0 .ro+ec,s we can crea,e now and ,3e wa/ we design a..lica,ions1 Visual Basic 1N%" was designed ,o ,a9e advan,age o0 ,3e 1N%" &ramewor9 *ase classes and run,ime environmen,1 (, comes wi,3 .ower .ac9ed 0ea,ures ,3a, sim.li0/ a..lica,ion develo.men,1

Na*espaces
A names.ace is a collec,ion o0 di00eren, classes1 All VB a..lica,ions are develo.ed using classes 0rom ,3e 1N%" )/s,em names.ace1 "3e names.ace wi,3 all ,3e *uil,-in VB 0unc,ionali,/ is ,3e )/s,em names.ace1 All o,3er names.aces are *ased on ,3is )/s,em names.ace )ome Names.aces and ,3eir use)/s,em- (ncludes essen,ial classes and *ase classes 0or commonl/ used da,a ,/.es: even,s: e;ce.,ions and so on

Navgu+ara, BCA

Page C o0 56

Advanced Visual and Windows Programming(BCA-205) )/s,em1 Collec,ions- (ncludes classes and in,er0aces ,3a, de0ine various collec,ion o0 o*+ec,s suc3 as lis,: Aueues: 3as3 ,a*les: arra/s: e,c )/s,em1 =a,a- (ncludes classes w3ic3 le,s us 3andle da,a 0rom 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 0or da,a access wi,3 &iles )/s,em1 "3reading- (ncludes classes and in,er0aces ,o su..or, mul,i,3readed )/s,em1 We*- (ncludes classes and in,er0aces ,3a, su..or, *rowser-server )/s,em1Windows1&orms- (ncludes classes 0or crea,ing Windows *ased 0orms

#sse*b+ies
An assem*l/ is ,3e *uilding *loc9 o0 a 1N%" a..lica,ion1 (, is a sel0 descri*ing collec,ion o0 code: resources: and me,ada,a (da,a a*ou, da,a: e;am.le: name: siDe: version o0 a 0ile is me,ada,a a*ou, ,3a, 0ile)1 An Assem*l/ is a com.lied and versioned collec,ion o0 code and me,ada,a ,3a, 0orms an a,omic 0unc,ional uni,1 Assem*lies ,a9e ,3e 0orm o0 a d/namic lin9 li*rar/ (1dll) 0ile or e;ecu,a*le .rogram 0ile (1e;e) *u, ,3e/ di00er as ,3e/ con,ain ,3e in0orma,ion 0ound in a ,/.e li*rar/ and ,3e in0orma,ion a*ou, ever/,3ing else needed ,o use an a..lica,ion or com.onen,1 All 1N%" .rograms are cons,ruc,ed 0rom ,3ese Assem*lies1 Assem*lies are made o0 ,wo .ar,s- mani0es,: con,ains in0orma,ion a*ou, w3a, is con,ained wi,3in ,3e assem*l/ and modules: in,ernal 0iles o0 ($ code w3ic3 are read/ ,o run1 W3en .rogramming: we don<, direc,l/ deal wi,3 assem*lies as ,3e C$! and ,3e 1N%" 0ramewor9 ,a9es care o0 ,3a, *e3ind ,3e scenes1 "3e assem*l/ 0ile is visi*le in ,3e )olu,ion %;.lorer window o0 ,3e .ro+ec,1

Data
B/,e C3ar (n,eger =ou*le $ong )3or, )ingle ),ring =a,e Boolean #*+ec, =ecimal

Type

Si,e
)/s,em1B/,e )/s,em1C3ar )/s,em1(n,72 )/s,em1=ou*le )/s,em1(n,68 )/s,em1(n,46 )/s,em1)ingle )/s,em1),ring )/s,em1=a,e )/s,em1Boolean )/s,em1#*+ec, )/s,em1=ecimal

4 C-*i, 2 46-*i, 8 72-*i, C 68-*i, C 68-*i, 2 46-*i, 8 72-*i, Varies Non-Numeric "/.e C 2 Non-Numeric "/.e 8 Non-Numeric "/.e 46 42C-*i,

#ccess Specifiers

Navgu+ara, BCA

Page 5 o0 56

Advanced Visual and Windows Programming(BCA-205) Access s.eci0iers le,<s us s.eci0/ 3ow a varia*le: me,3od or a class can *e used1 "3e 0ollowing are ,3e mos, commonl/ used one<s

Pu*lic- Gives varia*le .u*lic access w3ic3 means ,3a, ,3ere is no res,ric,ion on ,3eir accessi*ili,/ Priva,e- Gives varia*le .riva,e access w3ic3 means ,3a, ,3e/ are accessi*le onl/ wi,3in ,3eir declara,ion con,en, Pro,ec,ed- Pro,ec,ed access gives a varia*le accessi*ili,/ wi,3in ,3eir own class or a class derived 0rom ,3a, class &riend- Gives varia*le 0riend access w3ic3 means ,3a, ,3e/ are accessi*le wi,3in ,3e .rogram ,3a, con,ains ,3eir declara,ion Pro,ec,ed &riend- Gives a varia*le *o,3 .ro,ec,ed and 0riend access ),a,ic- 'a9es a varia*le s,a,ic w3ic3 means ,3a, ,3e varia*le will 3old ,3e value even ,3e .rocedure in w3ic3 ,3e/ are declared ends )3ared- =eclares a varia*le ,3a, can *e s3ared across man/ ins,ances and w3ic3 is no, associa,ed wi,3 a s.eci0ic ins,ance o0 a class or s,ruc,ure

Variab+es
Varia*les are used ,o s,ore da,a1 A varia*le 3as a name ,o w3ic3 we re0er and ,3e da,a ,/.e: ,3e ,/.e o0 da,a ,3e varia*le 3olds1 VB 1N%" now needs varia*les ,o *e declared *e0ore using ,3em1 Varia*les are declared wi,3 ,3e =im 9e/word1 =im s,ands 0or =imension1

State*ents
A s,a,emen, is a com.le,e ins,ruc,ion1 (, can con,ain 9e/words: o.era,ors: varia*les: li,erals: e;.ressions and cons,an,s1 %ac3 s,a,emen, in Visual Basic s3ould *e ei,3er a declara,ion s,a,emen, or a e;ecu,a*le s,a,emen,1 A declara,ion s,a,emen, is a s,a,emen, ,3a, can crea,e a varia*le: cons,an,: da,a ,/.e1 "3e/ are ,3e one<s we generall/ use ,o declare our varia*les1 #n ,3e o,3er 3and: e;ecu,a*le s,a,emen,s are ,3e s,a,emen,s ,3a, .er0orm an ac,ion1 "3e/ e;ecu,e a series o0 s,a,emen,s1 "3e/ can e;ecu,e a 0unc,ion: me,3od: loo.: e,c1

Option State*ent
"3e #.,ion s,a,emen, is used ,o se, a num*er o0 o.,ions 0or ,3e code ,o .reven, s/n,a; and logical errors1 "3is s,a,emen, is normall/ ,3e 0irs, line o0 ,3e code1 "3e #.,ion values in Visual Basic are as 0ollows1 #.,ion Com.are- Eou can se, i,<s value ,o "e;, or Binar/1 "3is s.eci0ies i0 ,3e s,rings are com.ared using *inar/ or ,e;, com.arison o.era,ors1 #.,ion %;.lici,- =e0aul, is #n1 Eou can se, i, ,o #00 as well1 "3is reAuires ,o declare all ,3e varia*les *e0ore ,3e/ are used1 #.,ion ),ric,- =e0aul, is #001 Eou can se, i, ,o #n as well1 Used normall/ w3en wor9ing wi,3 conversions in code1 (0 /ou wan, ,o assign a value o0 one ,/.e ,o ano,3er ,3en /ou s3ould se, i, ,o #n and use ,3e conversion 0unc,ions else Visual Basic will consider ,3a, as an error1

E-p+icit .onversions

Navgu+ara, BCA

Page 40 o0 56

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 0unc,ion1 C"/.e 0unc,ion 0or conversion (0 we are no, sure o0 ,3e name o0 a .ar,icular conversion 0unc,ion ,3en we can use ,3e C"/.e 0unc,ion1 "3e a*ove e;am.le wi,3 a C"/.e 0unc,ion loo9s li9e ,3is(m.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) <,wo argumen,s: ,/.e we are conver,ing 0rom: ,o ,/.e desired Wri,e$ine(G(n,eger value isG H i) %nd )u* %nd 'odule

E-p+icit .onversions

CBool - use ,3is 0unc,ion ,o conver, ,o Bool da,a ,/.e CB/,e - use ,3is 0unc,ion ,o conver, ,o B/,e da,a ,/.e CC3ar - use ,3is 0unc,ion ,o conver, ,o C3ar da,a ,/.e C=a,e - use ,3is 0unc,ion ,o conver, ,o =a,e ,/.e C=*l - use ,3is 0unc,ion ,o conver, ,o =ou*le da,a ,/.e C=ec - use ,3is 0unc,ion ,o conver, ,o =ecimal da,a ,/.e C(n, - use ,3is 0unc,ion ,o conver, ,o (n,eger da,a ,/.e C$ng - use ,3is 0unc,ion ,o conver, ,o $ong da,a ,/.e C#*+ - use ,3is 0unc,ion ,o conver, ,o #*+ec, ,/.e C)3or, - use ,3is 0unc,ion ,o conver, ,o )3or, da,a ,/.e C)ng - use ,3is 0unc,ion ,o conver, ,o )ingle da,a ,/.e C),ring - use ,3is 0unc,ion ,o conver, ,o ),ring da,a ,/.e

Operators
Visual Basic comes wi,3 man/ *uil,-in o.era,ors ,3a, allow us ,o mani.ula,e da,a1 An o.era,or .er0orms a 0unc,ion on one or more o.erands1 &or e;am.le: we add ,wo varia*les wi,3 ,3e GIG addi,ion o.era,or and s,ore ,3e resul, in a ,3ird varia*le wi,3 ,3e GFG assignmen, o.era,or li9e ,3is- in, ; I in, / F in, D1 "3e ,wo varia*les (; :/) are called o.erands1 "3ere are di00eren, ,/.es o0 o.era,ors in Visual Basic and ,3e/ are descri*ed *elow in ,3e order o0 ,3eir .recedence Ari,3me,ic #.era,ors Ari,3me,ic o.era,ors are used ,o .er0orm ari,3me,ic o.era,ions ,3a, involve calcula,ion o0 numeric values1 "3e ,a*le *elow summariDes ,3em#.era,or Use J %;.onen,ia,ion Nega,ion (used ,o reverse ,3e sign o0 ,3e given value: e;. -in,Value)

Navgu+ara, BCA

Page 44 o0 56

Advanced Visual and Windows Programming(BCA-205) K L M 'od I 'ul,i.lica,ion =ivision (n,eger =ivision 'odulus Ari,3me,ic Addi,ion )u*,rac,ion

Conca,ena,ion #.era,ors Conca,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,ion H ),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 Use F %Auali,/ NO (neAuali,/ N $ess ,3an O Grea,er ,3an OF Grea,er ,3an or eAual ,o NF $ess ,3an or eAual ,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 0alse resul, over a condi,ional e;.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

#rrays
Arra/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, 0rom ,3e Arra/ class in ,3e )/s,em names.ace1 All arra/s in VB as Dero *ased: meaning: ,3e inde; o0 ,3e 0irs, elemen, is Dero and ,3e/ are num*ered seAuen,iall/1 Eou mus, s.eci0/ ,3e num*er o0 arra/ elemen,s */ indica,ing ,3e u..er *ound o0 ,3e arra/1 "3e u..er *ound is ,3e numder ,3a, s.eci0ies ,3e inde; o0 ,3e las, elemen, o0 ,3e arra/1 Arra/s are declared using =im: !e=im: ),a,ic:

Navgu+ara, BCA

Page 42 o0 56

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,/ o0 an arra/ re0ers ,o ,3e num*er o0 su*scri.,s used ,o iden,i0/ an individual elemen,1 (n Visual Basic we can s.eci0/ u. ,o 72 dimensions1 Arra/s do no, 3ave 0i;ed siDe in Visual Basic1 "3e 0ollowing code demons,ra,es arra/s1 'odule 'odule4 )u* 'ain() =im s.or,(5) As ),ring <declaring an arra/ s.or,(0) F G)occerG s.or,(4) F GCric9e,G s.or,(2) F G!ug*/G s.or,(7) F GAussie !ulesG s.or,(8) F GBas9e,BallG s.or,(5) F G>oc9e/G <s,oring values in ,3e arra/ Wri,e$ine(GName o0 ,3e ).or, in ,3e ,3ird loca,ionG H G G H s.or,(2)) <dis.la/ing value 0rom arra/ %nd )u* %nd 'odule

ST%IN/ F0N.TIONS
Pu*lic &unc,ion #sc(B/Val String As .har) As Inte(er 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns an (n,eger re.resen,ing ,3e c3arac,er code corres.onding ,o ,3e 0irs, le,,er in a s,ring1 Pu*lic &unc,ion .hr(B/Val CharCode As Inte(er) As .har 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns ,3e c3arac,er associa,ed wi,3 ,3e s.eci0ied c3arac,er code as a C3ar da,a ,/.e1 Pu*lic &unc,ion For*at(B/Val Expression As Ob ect2 #.,ional B/Val Style As Strin( F GG) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns a ),ring e;.ression 0orma,,ed according ,o ins,ruc,ions con,ained in a 0orma, ),ring e;.ression1 )"!(NG &UNC"(#N) Pu*lic &unc,ion 'id(B/Val str As Strin(2 B/Val Start As Inte(er) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s

S)**ary1 !e.laces a s.eci0ied num*er o0 c3arac,ers in a ),ring varia*le wi,3 c3arac,ers 0rom ano,3er s,ring1

Navgu+ara, BCA

Page 47 o0 56

Advanced Visual and Windows Programming(BCA-205) Para*eters1 str- Name o0 ,3e ),ring varia*le ,o modi0/1 Start- (n,eger da,a ,/.e1 C3arac,er .osi,ion in ,arge, w3ere ,3e re.lacemen, o0 ,e;, *egins1 ),ar, uses a one *ased inde;1

Pu*lic &unc,ion Str.o*p(B/Val String1 As Strin(2 B/Val String2 As Strin(2 #.,ional B/Val Compare As 'icrosoft.Vis)a+Basic..o*pare'ethod F 0) As Inte(er 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s

S)**ary1 !e,urns -4: 0: or 4: *ased on ,3e resul, o0 a s,ring com.arison1 "3e s,rings are com.ared */ al.3anumeric sor, values *egining wi,3 ,3e 0irs, c3arac,er1 Para*eters1 String1- An/ valid ),ring e;.ression1 String2- An/ valid ),ring e;.ression1 Compare- ).eci0ies ,3e ,/.e o0 s,ring com.arison1 (0 com.are is omi,,ed: ,3e #.,ion Com.are se,,ing de,ermines ,3e ,/.e o0 com.arison1 Pu*lic &unc,ion /et.har(B/Val str As Strin(2 B/Val Index As Inte(er) As .har 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns ,3e c3arac,er a, a s.eci0ied .osi,ion in a s,ring Para*eters1 str- ),ring ,o use as a source Index- 4 *ased inde; o0 ,3e c3arac,er ,o re,urn Pu*lic &unc,ion InStr(B/Val Start As Inte(er2 B/Val String1 As Strin(2 B/Val String2 As Strin(2 #.,ional B/Val Compare As 'icrosoft.Vis)a+Basic..o*pare'ethod F 0) As Inte(er 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns an (n,eger s.eci0/ing ,3e s,ar, .osi,ion o0 ,3e 0irs, occurrence o0 one s,ring wi,3in ano,3er1 Para*eters1 Start- Numeric e;.ression ,3a, se,s ,3e s,ar,ing .osi,ion 0or eac3 searc31 (0 omi,,ed: searc3 *egins a, ,3e 0irs, c3arac,er .osi,ion1 "3e s,ar, inde; is 4 *ased1 String1- ),ring e;.ression *eing searc3ed1 String2- ),ring e;.ression soug3,1

Pu*lic &unc,ion InStr%ev(B/Val StringCheck As Strin(2 B/Val StringMatch As Strin(2 #.,ional B/Val Start As Inte(er F -42 #.,ional B/Val Compare As 'icrosoft.Vis)a+Basic..o*pare'ethod F 0) As Inte(er 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s

Navgu+ara, BCA

Page 48 o0 56

Advanced Visual and Windows Programming(BCA-205) S)**ary1 !e,urns ,3e .osi,ion o0 ,3e 0irs, occurrence o0 one s,ring wi,3in ano,3er: s,ar,ing 0rom ,3e rig3, side o0 ,3e s,ring1 Para*eters1 StringCheck- ),ring e;.ression *eing searc3ed1 StringMatch- ),ring e;.ression *eing searc3ed 0or1 Start- Numeric e;.ression ,3a, se,s ,3e one-*ased s,ar,ing .osi,ion 0or eac3 searc3: s,ar,ing 0rom ,3e le0, side o0 ,3e s,ring1 (0 ),ar, is omi,,ed: P4 is used: w3ic3 means ,3a, ,3e searc3 *egins a, ,3e las, c3arac,er .osi,ion1 )earc3 ,3en .roceeds 0rom rig3, ,o le0,1 Pu*lic &unc,ion 3oin(B/Val SourceArray() As Ob ect2 #.,ional B/Val Delimiter As Strin( F G G) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns a s,ring crea,ed */ +oining a num*er o0 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 (0 omi,,ed: ,3e s.ace c3arac,er (G G) is used1 (0 =elimi,er is a Dero-leng,3 s,ring (GG): all i,ems in ,3e lis, are conca,ena,ed wi,3 no delimi,ers1 Pu*lic &unc,ion ".ase(B/Val Value As Strin() As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(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/Val str As Strin(2 B/Val Length As Inte(er) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns a ),ring con,aining a s.eci0ied num*er o0 c3arac,ers 0rom ,3e le0, side o0 a s,ring1 Para*eters1 Str- ),ring e;.ression 0rom w3ic3 ,3e le0,mos, c3arac,ers are re,urned1 Length- (n,eger e;.ression1 Numeric e;.ression indica,ing 3ow man/ c3arac,ers ,o re,urn1 (0 0: a Dero-leng,3 s,ring (GG) is re,urned1 (0 grea,er ,3an or eAual ,o ,3e num*er o0 c3arac,ers in ),r: ,3e en,ire s,ring is re,urned1 Pu*lic &unc,ion "en(B/Val Expression As Byte) As Inte(er 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns an (n,eger con,aining ei,3er ,3e num*er o0 c3arac,ers in a s,ring or ,3e num*er o0 */,es reAuired ,o s,ore a varia*le1 Para*eters1 Expression- valid ),ring e;.ression or varia*le name1 (0 %;.ression is o0 ,/.e #*+ec,: ,3e $en 0unc,ion re,urns ,3e siDe as i, will *e wri,,en ,o ,3e 0ile1 Pu*lic &unc,ion 'id(B/Val str As Strin(2 B/Val Start As Inte(er) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1

Navgu+ara, BCA

Page 45 o0 56

Advanced Visual and Windows Programming(BCA-205) !e.laces a s.eci0ied num*er o0 c3arac,ers in a ),ring varia*le wi,3 c3arac,ers 0rom ano,3er s,ring1 Para*eters1 str- Name o0 ,3e ),ring varia*le ,o modi0/1 Start- (n,eger da,a ,/.e1 C3arac,er .osi,ion in ,arge, w3ere ,3e re.lacemen, o0 ,e;, *egins1 ),ar, uses a one *ased inde;1 Pu*lic &unc,ion %ep+ace(B/Val Expression As Strin(2 B/Val ind As Strin(2 B/Val !eplacement As Strin(2 #.,ional B/Val Start As Inte(er F 42 #.,ional B/Val Count As Inte(er F -42 #.,ional B/Val Compare As 'icrosoft.Vis)a+Basic..o*pare'ethod F 0) As Strin( 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns a s,ring in w3ic3 a s.eci0ied su*s,ring 3as *een re.laced wi,3 ano,3er su*s,ring a s.eci0ied num*er o0 ,imes1 Para*eters1 Expression- ),ring e;.ression con,aining su*s,ring ,o re.lace1 ind- )u*s,ring *eing searc3ed 0or1 !eplacement- !e.lacemen, su*s,ring1 Start- Posi,ion wi,3in %;.ression w3ere su*s,ring searc3 is ,o *egin1 (0 omi,,ed: 4 is assumed1 Count- Num*er o0 su*s,ring su*s,i,u,ions ,o .er0orm1 (0 omi,,ed: ,3e de0aul, value is P4: w3ic3 means ma9e all .ossi*le su*s,i,u,ions1 Compare- Numeric value indica,ing ,3e 9ind o0 com.arison ,o use w3en evalua,ing su*s,rings1 )ee )e,,ings 0or values1

Pu*lic &unc,ion Sp+it(B/Val Expression As Strin(2 #.,ional B/Val Delimiter As Strin( F G G2 #.,ional B/Val Limit As Inte(er F -42 #.,ional B/Val Compare As 'icrosoft.Vis)a+Basic..o*pare'ethod F 0) As Strin(() 'em*er o0- 'icrosoft.Vis)a+Basic1Strin(s S)**ary1 !e,urns a Dero-*ased: one-dimensional arra/ con,aining a s.eci0ied num*er o0 su*s,rings1 Para*eters1 Expression- ),ring e;.ression con,aining su*s,rings and delimi,ers1 (0 %;.ression is a Dero-leng,3 s,ring (GG): ,3e ).li, 0unc,ion re,urns an arra/ wi,3 no elemen,s and no da,a1 Delimiter- )ingle c3arac,er used ,o iden,i0/ su*s,ring limi,s1 (0 =elimi,er is omi,,ed: ,3e s.ace c3arac,er (G G) is assumed ,o *e ,3e delimi,er1 (0 =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 o0 su*s,rings ,o *e re,urnedQ ,3e de0aul,: P4: indica,es ,3a, all su*s,rings are re,urned1 Compare- Numeric value indica,ing ,3e com.arison ,o use w3en evalua,ing su*s,rings1 )ee )e,,ings 0or values1

C#N"!#$ )"A"%'%N") (& condi,ion ">%N %$)%(& condi,ion ">%N

Navgu+ara, BCA

Page 46 o0 56

Advanced Visual and Windows Programming(BCA-205) %$)% %N= (&

)%$%C" CA)% e;.r CA)% e;.rls,4 CA)% e;.rls,2 R1 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) $##P(NG C#N)"UC")

=# w3ileLun,il condi,ion

),m, %;i, do

$##P 0or inde;Fs,ar, ,o end s,e. ),a,emen,s %;i, 0or N%@" W>($% ),a,emen,s W%N=

condi,ion

W("> o*+ec, ),a,emen,s %N= W(">

'essa(ebo- F)nction
'essa(eBo-.Sho45#r()*ents6 )everal c3oices 0or argumen, lis, (n,roduces conce., o0 #verloaded 0unc,ions 'ul,i.le signa,ures ,o c3oose 0rom 'essa(eBo-.Sho45TextMessage6 'essa(eBo-.Sho45TextMessage2 TitlebarText6 'essa(eBo-.Sho45TextMessage2 TitlebarText2 7 MessageBoxButtons6

Navgu+ara, BCA

Page 4B o0 56

Advanced Visual and Windows Programming(BCA-205) 'essa(eBo-.Sho45TextMessage2 TitlebarText2 7 MessageBoxButtons, MessageBoxIcon6

'essageBo; (cons and *u,,ons %numera,ion o0 cons,an,s

'en)s2S)b Proced)res2S)b F)nctions



'enus

Crea,ing 'enus and 'enu (,ems Crea,ing Con,e;,'enus =is.la/ing Common =ialog Bo;es Wri,ing General Procedures 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,/ o0 a con,rol or ,3e 0orm )u* &unc,ion

Argumen,s are .assed B/Val (*/ de0aul,) "3e %di,or adds B/Val i0 /ou leave i, ou, New !e,urn s,a,emen, Can s,ill se, 0unc,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)*9 End F)nction

.ONT%O"S B)tton .ontro+

Navgu+ara, BCA

Page 4C o0 56

Advanced Visual and Windows Programming(BCA-205)

#ne o0 ,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 .er0orm some ac,ion1 Bu,,ons are used mos,l/ 0or 3andling even,s in code: sa/: 0or sending da,a en,ered in ,3e 0orm ,o ,3e da,a*ase and so on1 "3e de0aul, even, o0 ,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 de0aul, even, o0 ,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, o0 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 <Eou .lace ,3e code 3ere ,o .er0orm ac,ion w3en Bu,,on is clic9ed %nd )u* (m.or,an, Pro.er,ies o0 Bu,,on4 #ppearance Bac9Color and Bac9ground (mage .ro.er,ies we can se, a *ac9ground color and a *ac9ground image ,o ,3e *u,,on1 We se, ,3e 0on, color and 0on, s,/le 0or ,3e ,e;, ,3a, a..ears on *u,,on wi,3 &oreColor and ,3e &on, .ro.er,/1 We c3ange ,3e a..earance s,/le o0 ,3e *u,,on wi,3 ,3e &la,),/le .ro.er,/1 We can c3ange ,3e ,e;, ,3a, a..ears on *u,,on wi,3 ,3e "e;, .ro.er,/ wi,3 ,3e "e;,Align .ro.er,/ we can se, w3ere on ,3e *u,,on ,3e ,e;, s3ould a..ear 0rom a .rede0ined se, o0 o.,ions1 Behavior No,a*le Be3avior .ro.er,ies o0 ,3e Bu,,on are ,3e %na*led and Visi*le .ro.er,ies1 "3e %na*led .ro.er,/ is se, ,o "rue */ de0aul, w3ic3 ma9es ,3e *u,,on ena*led and se,,ing i,<s .ro.er,/ ,o &alse ma9es ,3e *u,,on =isa*led1 Wi,3 ,3e Visi*le .ro.er,/ we can ma9e ,3e Bu,,on Visi*le or (nvisi*le1 "3e de0aul, value is se, ,o "rue and ,o ma9e ,3e *u,,on (nvisi*le se, i,<s .ro.er,/ ,o &alse1 "ayo)t $a/ou, .ro.er,ies are a*ou, ,3e loo9 o0 ,3e Bu,,on1 No,e ,3e =oc9 .ro.er,/ 3ere1 A con,rol can *e doc9ed ,o one edge o0 i,s .aren, con,ainer or can *e doc9ed ,o all edges and 0ill ,3e .aren, con,ainer1 "3e de0aul, value is se, ,o none1 (0 /ou wan, ,o doc9 ,3e con,rol ,owards ,3e le0,: rig3,: ,o.: *o,,om and cen,er /ou can do ,3a, */ selec,ing 0rom ,3e *u,,on li9e image ,3is .ro.er,/ dis.la/s1 Wi,3 ,3e $oca,ion .ro.er,/ /ou can c3ange ,3e loca,ion o0 ,3e *u,,on1 Wi,3 ,3e )iDe .ro.er,/ /ou can se, ,3e siDe o0 ,3e *u,,on1 A.ar, 0rom ,3e =oc9 .ro.er,/ /ou can se, i,<s siDe and loca,ion */ moving and s,re,c3ing ,3e Bu,,on on ,3e 0orm i,sel01 .reatin( a B)tton 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 eS As )/s,em1%ven,Args) >andlesS '/Base1$oad =im Bu,,on4 as New Bu,,on() <declaring ,3e *u,,on: Bu,,on4 Bu,,on41"e;,FGCrea,ing a Bu,,onG <se,,ing ,3e ,e;, ,o *e dis.la/ed on ,3e Bu,,on
Navgu+ara, BCA Page 45 o0 56

Advanced Visual and Windows Programming(BCA-205) Bu,,on41$oca,ionFNew Poin,(400:50) <se,,ing ,3e loca,ion 0or ,3e Bu,,on w3ere i, s3ould *e crea,ed Bu,,on41)iDeFNew )iDe(B5:27) <se,,ing ,3e siDe o0 ,3e Bu,,on 'e1Con,rols1Add(Bu,,on4) <adding ,3e Bu,,on ,3a, is crea,ed ,o ,3e 0orm <,3e 'e 9e/word is used ,o re0er ,o ,3e curren, o*+ec,: in ,3is case ,3e &orm %nd )u* %nd Class

"abe+
$a*els are ,3ose con,rols ,3a, are used ,o dis.la/ ,e;, in o,3er .ar,s o0 ,3e a..lica,ion1 "3e/ are *ased on ,3e Con,rol class1 No,a*le .ro.er,/ o0 ,3e la*el con,rol is ,3e ,e;, .ro.er,/ w3ic3 is used ,o se, ,3e ,e;, 0or ,3e la*el1 .reatin( a "abe+ in .ode Priva,e )u* &orm4S$oad(B/Val sender As )/s,em1#*+ec,: B/Val e As )/s,em1%ven,Args)S >andles '/Base1$oad =im $a*el4 As New $a*el() $a*el41"e;, F G$a*elG $a*el41$oca,ion F New Poin,(475: B0) $a*el41)iDe F New )iDe(70: 70) 'e1Con,rols1Add($a*el4) %nd )u*

Te-tBo- .ontro+
Windows users s3ould *e 0amiliar wi,3 ,e;,*o;es1 "3is con,rol loo9s li9e a *o; and acce.,s in.u, 0rom ,3e user1 "3e "e;,Bo; is *ased on ,3e "e;,Bo;Base class w3ic3 is *ased on ,3e Con,rol class1 "e;,Bo;es are used ,o acce., in.u, 0rom ,3e user or used ,o dis.la/ ,e;,1 B/ de0aul, we can en,er u. ,o 208C c3arac,ers in a "e;,Bo; *u, i0 ,3e 'ul,iline .ro.er,/ is se, ,o "rue we can en,er u. ,o 722B o0 ,e;,1 "3e image *elow dis.la/s a "e;,*o; So*e Notab+e Properties1 Be3avior %na*led- =e0aul, value is "rue1 "o disa*le: se, ,3e .ro.er,/ ,o &alse1 'ul,iline- )e,,ing ,3is .ro.er,/ ,o "rue ma9es ,3e "e;,Bo; mul,iline w3ic3 allows ,o acce., mul,i.le lines o0 ,e;,1 =e0aul, value is &alse1 PasswordC3ar- Used ,o se, ,3e .assword c3arac,er1 "3e ,e;, dis.la/ed in ,3e "e;,Bo; will *e ,3e c3arac,er se, */ ,3e user1 )a/: i0 /ou en,er K: ,3e ,e;, ,3a, is en,ered in ,3e "e;,Bo; is dis.la/ed as K1 !ead #nl/- 'a9es ,3is "e;,Bo; readonl/1 (, doesn<, allow ,o en,er an/ ,e;,1 Visi*le- =e0aul, value is "rue1 "o 3ide i, se, ,3e .ro.er,/ ,o &alse

A..earance sec,ion

Navgu+ara, BCA

Page 20 o0 56

Advanced Visual and Windows Programming(BCA-205)

"e;,Align- Allows ,o align ,3e ,e;, 0rom ,3ree .ossi*le o.,ions1 "3e de0aul, value is le0, and /ou can se, ,3e alignmen, o0 ,e;, ,o rig3, or cen,er1 )croll*ars- Allows ,o add a scroll*ar ,o a "e;,*o;1 Ver/ use0ul w3en ,3e "e;,Bo; is mul,iline1 Eou 3ave 0our o.,ions wi,3 ,3is .ro.er,/1 #.,ions are are None: >oriDon,al: Ver,ical and Bo,31 =e.ending on ,3e siDe o0 ,3e "e;,Bo; an/one o0 ,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 o0 ,3e 0orm 2BI2 canno, re,urn an/,3ing1 "o avoid suc3 9ind o0 o.era,ions we use ,3e 2e/Press even, o0 ,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;4S2e/Press(B/Val sender As #*+ec,:B/Val e AsS )/s,em1Windows1&orms12e/Press%ven,Args) >andles "e;,Bo;412e/Press (0(e12e/C3ar N G40G #r e12e/C3ar O G400G) "3en 'essageBo;1)3ow(G%n,er =ou*le =igi,sG) %nd (0 %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;,FG>ello 'a,eG "e;,Bo;41$oca,ionFNew Poin,(400:50) "e;,Bo;41)iDeFNew )iDe(B5:27) 'e1Con,rols1Add("e;,Bo;4) %nd )u* %nd Class

.hec<BoC3ec9Bo;es are ,3ose con,rols w3ic3 gives us an o.,ion ,o selec,: sa/: EesLNo or "rueL&alse1 A c3ec9*o; is clic9ed ,o selec, and clic9ed again ,o deselec, some o.,ion1 W3en a c3ec9*o; is selec,ed a c3ec9 (a ,ic9 mar9) a..ears indica,ing a selec,ion1 "3e C3ec9Bo; con,rol is *ased on ,3e "e;,Bo;Base class w3ic3 is *ased on ,3e Con,rol class1 Below is ,3e image o0 a C3ec9*o;1

Notab+e Properties (m.or,an, .ro.er,ies o0 ,3e C3ec9Bo; in ,3e A..earance sec,ion o0 ,3e .ro.er,ies window are A..earance- =e0aul, value is Normal1 )e, ,3e value ,o Bu,,on i0 /ou wan, ,3e C3ec9Bo; ,o *e dis.la/ed as a Bu,,on1 Bac9ground(mage- Used ,o se, a *ac9ground image 0or ,3e c3ec9*o;1 C3ec9Align- Used ,o se, ,3e alignmen, 0or ,3e C3ec9Bo; 0rom a .rede0ined lis,1 C3ec9ed- =e0aul, value is &alse: se, i, ,o "rue i0 /ou wan, ,3e C3ec9Bo; ,o *e dis.la/ed Navgu+ara, BCA Page 24 o0 56

Advanced Visual and Windows Programming(BCA-205) as c3ec9ed1 C3ec9),a,e- =e0aul, value is Unc3ec9ed1 )e, i, ,o "rue i0 /ou wan, a c3ec9 ,o a..ear1 W3en se, ,o (nde,ermina,e i, dis.la/s a c3ec9 in gra/ *ac9ground1 &la,),/le- =e0aul, value is ),andard1 )elec, ,3e value 0rom a .rede0ined lis, ,o se, ,3e s,/le o0 ,3e c3ec9*o;1

(m.or,an, .ro.er,/ in ,3e Be3avior sec,ion o0 ,3e .ro.er,ies window is ,3e "3ree),a,e .ro.er,/ w3ic3 is se, ,o &alse */ de0aul,1 )e, i, ,o "rue ,o s.eci0/ i0 ,3e C3ec9*o; can allow ,3ree c3ec9 s,a,es ,3an ,wo1 Code ,o c3ec9 a C3ec9Bo;<s s,a,e Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: B/Val e AsS )/s,em1%ven,Args) >andles Bu,,on41Clic9 (0 C3ec9Bo;41C3ec9ed F "rue "3en "e;,Bo;41"e;, F GC3ec9edG %lse "e;,Bo;41"e;, F GUnC3ec9edG %nd (0 %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 GC3ec9*o;4G C3ec9Bo;41$oca,ion F New Poin,(400: 50) C3ec9Bo;41)iDe F New )iDe(55: 85) 'e1Con,rols1Add(C3ec9Bo;4) %nd )u*

.o*boBo Com*oBo; is a com*ina,ion o0 a "e;,Bo; and a $is,Bo;1 "3e Com*oBo; dis.la/s an edi,ing 0ield ("e;,Bo;) com*ined wi,3 a $is,Bo; allowing us ,o selec, 0rom ,3e lis, or ,o en,er new ,e;,1 Com*oBo; dis.la/s da,a in a dro.-down s,/le 0orma,1 "3e Com*oBo; class is derived 0rom ,3e $is,Bo; class1 Below is ,3e (mage o0 a Com*oBo;1
Notab+e properties of the .o*boBo "3e =ro.=own),/le .ro.er,/ in ,3e A..earance sec,ion o0 ,3e .ro.er,ies window allows us ,o se, ,3e loo9 o0 ,3e Com*oBo;1 "3e de0aul, value is se, ,o =ro.=own w3ic3 means ,3a, ,3e Com*oBo; dis.la/s ,3e "e;, se, */ i,<s "e;, .ro.er,/ in ,3e "e;,*o; and dis.la/s i,<s i,ems in ,3e =ro.=own$is,Bo; *elow1 )e,,ing i, ,o sim.le ma9es ,3e Com*oBo; ,o *e dis.la/ed wi,3 a "e;,Bo; and ,3e lis, *o; w3ic3 doesn<, dro. down1 )e,,ing i, ,o =ro.=own$is, ma9es ,3e Com*oBo; ,o ma9e selec,ion onl/ 0rom ,3e dro. down lis, and res,ric,s /ou 0rom en,ering an/ ,e;, in ,3e ,e;,*o;1 We can sor, ,3e Com*oBo; wi,3 i,<s )or,ed .ro.er,/ w3ic3 is se, ,o &alse */ =e0aul,1 Navgu+ara, BCA Page 22 o0 56

Advanced Visual and Windows Programming(BCA-205)

We can add i,ems ,o ,3e Com*oBo; wi,3 i,<s (,ems .ro.er,/1

!emoving i,ems 0rom a Com*oBo; Eou can remove all i,ems or one .ar,icular i,em 0rom ,3e lis, *o; .ar, o0 ,3e Com*o;Bo;1 Code ,o remove a .ar,icular i,em */ i,<s (nde; num*er loo9s li9e ,3is Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: B/Val e AsS )/s,em1%ven,Args) >andles Bu,,on41Clic9 Com*oBo;41(,ems1!emoveA,(8) <removing an i,em */ s.eci0/ing i,<s inde; %nd )u* Code ,o remove all i,ems 0rom ,3e Com*oBo; Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: B/Val e AsS )/s,em1%ven,Args) >andles Bu,,on41Clic9 Com*oBo;41(,ems1Clear() <using ,3e clear me,3od ,o clear ,3e lis, *o; %nd )u*

$and+in( 'o)se Events in For*s


We can 3andle mouse even,s suc3 as mouse .oin,er movemen,s in &orms1 "3e mouse even,s su..or,ed */ VB 1N%" are as 0ollows 'o)seDo4n- "3is even, 3a..ens w3en ,3e mouse .oin,er is over ,3e 0ormLcon,rol and is .ressed 'o)seEnter- "3is even, 3a..ens w3en ,3e mouse .oin,er en,ers ,3e 0ormLcon,rol 'o)se0p- "3is even, 3a..ens w3en ,3e mouse .oin,er is over ,3e 0ormLcon,rol and ,3e mouse *u,,on is released 'o)se"eave- "3is even, 3a..ens w3en ,3e mouse .oin,er leaves ,3e 0ormLcon,rol 'o)se'ove- "3is even, 3a..ens w3en ,3e mouse .oin,er is moved over ,3e 0ormLcon,rol 'o)seWhee+- "3is even, 3a..ens w3en ,3e mouse w3eel moves w3ile ,3e 0ormLcon,rol 3as 0ocus 'o)se$over- "3is even, 3a..ens w3en ,3e mouse .oin,er 3overs over ,3e 0ormLcon,rol "3e .ro.er,ies o0 ,3e 'ouse%ven,Args o*+ec,s ,3a, can *e .assed ,o ,3e mouse even, 3andler are as 0ollows B)tton- ).eci0ies ,3a, ,3e mouse *u,,on was .ressed .+ic<s- ).eci0ies num*er o0 ,imes ,3e mouse *u,,on is .ressed and released &- "3e @-coordina,e o0 ,3e mouse clic9 !- "3e E-coordina,e o0 ,3e mouse clic9 De+ta- ).eci0ies a coun, o0 ,3e num*er o0 de,en,s (ro,a,ion o0 mouse w3eel) ,3e mouse w3eel 3as ro,a,ed

"istBo "3e $is,Bo; con,rol dis.la/s a lis, o0 i,ems 0rom w3ic3 we can ma9e a selec,ion1 We can selec, one or more ,3an one o0 ,3e i,ems 0rom ,3e lis,1 "3e $is,Bo; con,rol is *ased on ,3e $is,Con,rol class w3ic3 is *ased on ,3e Con,rol class1 "3e image *elow

Navgu+ara, BCA

Page 27 o0 56

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,al)croll*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 de0aul, value is se, ,o &alse1 )e, i, ,o "rue i0 /ou wan, ,3e lis, *o; ,o dis.la/ mul,i.le columns1 )crollAlwa/sVisi*le- =e0aul, 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- =e0aul, value is se, ,o one1 )elec, o.,ion None i0 /ou do no, an/ i,em ,o *e selec,ed1 )elec, i, ,o 'ul,i)im.le i0 /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. o0 )3i0,: Con,rol and arrow 9e/s on ,3e 9e/*oard1 )or,ed- =e0aul, value is se, ,o &alse1 )e, i, ,o "rue i0 /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 o0 (,ems in a $is,Bo; Add a Bu,,on ,o ,3e 0orm and .lace ,3e 0ollowing code in i,<s clic9 even,1 Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: B/Val e S As )/s,em1%ven,Args) >andles Bu,,on41Clic9 "e;,Bo;41"e;, F $is,Bo;41(,ems1Coun, <coun,ing ,3e num*er o0 i,ems in ,3e $is,Bo; wi,3 ,3e (,ems1Coun, %nd )u* W3en /ou run ,3e code and clic9 ,3e Bu,,on i, will dis.la/ ,3e num*er o0 i,ems availa*le in ,3e $is,Bo;1 Code ,o dis.la/ ,3e i,em selec,ed 0rom $is,Bo; in a "e;,Bo; Priva,e )u* $is,Bo;4S)elec,ed(nde;C3anged(B/Val sender As )/s,em1#*+ec,:S B/Val e As )/s,em1%ven,Args) >andles $is,Bo;41)elec,ed(nde;C3anged "e;,Bo;41"e;, F $is,Bo;41)elec,ed(,em <using ,3e selec,ed i,em .ro.er,/ %nd )u* W3en /ou run ,3e code and clic9 an i,em in ,3e

Code ,o remove a .ar,icular i,em Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: B/Val e S As )/s,em1%ven,Args) >andles Bu,,on41Clic9 $is,Bo;41(,ems1!emoveA,(8) <removing an i,em */ s.eci0/ing i,<s inde; %nd )u* Code ,o !emove all i,ems Priva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,: S B/Val e As )/s,em1%ven,Args) >andles Bu,,on41Clic9 $is,Bo;41(,ems1Clear() <using ,3e clear me,3od ,o clear ,3e lis, *o; %nd )u*

Navgu+ara, BCA

Page 28 o0 56

Advanced Visual and Windows Programming(BCA-205) %;am.le Code ,o add and remove da,a Code ,o )3i0, single selec,ed i,em 0rom one lis,*o; ,o ano,3er lis,*o; Code ,o s3i0, mul,i.le i,ems %;am.le-c3ec9*o; and o.,ion *u,,on %;am.le-Calcula,or Code 0or num*er *u,,ons Code 0or #.era,ors *u,,ons Code 0or eAuals *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;<s )3ow=ialog me,3od1 "3e =ialog Bo;es w3ic3 come wi,3 Visual Basic 1N%" are#.en&ile=ialog: )ave&ile=ialog &on,=ialog Color=ialog Prin,=ialog Prin,Preview=ialog and Page)e,u.=ialog1 We will *e wor9ing wi,3 #.en&ile: )ave&ile: &on, and Color =ialog<s in ,3is sec,ion1 "3e re,urn values o0 all ,3e a*ove said dialog *o;es w3ic3 will de,ermine w3ic3 selec,ion a user ma9es are- A*or,: Cancel: (gnore: No: None: #2: !e,urn: !e,r/ and Ees1 OpenFi+eDia+o( Pro.er,ies o0 ,3e #.en&ile=ialog are as 0ollowsAdd%;,ension- Ge,sL)e,s i0 ,3e dialog *o; adds e;,ension ,o 0ile names i0 ,3e user doesn<, su..l/ ,3e e;,ension1 C3ec9&ile%i;s,s- C3ec9s w3e,3er ,3e s.eci0ied 0ile e;is,s *e0ore re,urning 0rom ,3e dialog1 C3ec9Pa,3%;is,s- C3ec9s w3e,3er ,3e s.eci0ied .a,3 e;is,s *e0ore re,urning 0rom ,3e dialog1 =e0aul,%;,- Allows /ou ,o se, ,3e de0aul, 0ile e;,ension1 &ileName- Ge,sL)e,s 0ile name selec,ed in ,3e 0ile dialog *o;1 &ileNames- Ge,s ,3e 0ile names o0 all selec,ed 0iles1 &il,er- Ge,sL)e,s ,3e curren, 0ile name 0il,er s,ring: w3ic3 se,s ,3e c3oices ,3a, a..ear in ,3e G&iles o0 "/.eG *o;1 &il,er(nde;- Ge,sL)e,s ,3e inde; o0 ,3e 0il,er selec,ed in ,3e 0ile dialog *o;1 (ni,ial=irec,or/- "3is .ro.er,/ allows ,o se, ,3e ini,ial direc,or/ w3ic3 s3ould o.en w3en /ou use ,3e #.en&ile=ialog1

Navgu+ara, BCA

Page 25 o0 56

Advanced Visual and Windows Programming(BCA-205)

SaveFi+eDia+o( )ave &ile =ialog<s are su..or,ed */ ,3e )ave&ile=ialog class and ,3e/ allow us ,o save ,3e 0ile in a s.eci0ied loca,ion1 Pro.er,ies o0 ,3e )ave &ile =ialog are ,3e same as ,3a, o0 ,3e #.en &ile =ialog1 Please re0er a*ove1 No,a*le .ro.er,/ o0 )ave &ile dialog is ,3e #verwri,ePromo., .ro.er,/ w3ic3 dis.la/s a warning i0 we c3oose ,o save ,o a name ,3a, alread/ e;is,s1

FontDia+o( Pro.er,ies o0 ,3e &on,=ialog are as 0ollowsAllow)imula,ions- Ge,sL)e,s w3e,3er ,3e dialog *o; allows gra.3ics device in,er0ace 0on, simula,ions1 Color- Ge,sL)e,s selec,ed 0on, color1 &on,- Ge,sL)e,s ,3e selec,ed 0on,1 &on,'us,%;is,- Ge,sL)e,s w3e,3er ,3e dialog *o; s.eci0ies an error condi,ion i0 ,3e user a,,em.,s ,o selec, a 0on, or siDe ,3a, doesn<, e;is,1 'a;)iDe- Ge,sL)e,s ,3e ma;imum .oin, siDe ,3e user can selec,1 'in)iDe- Ge,sL)e,s ,3e mainimum .oin, siDe ,3e user can selec,1 )3owA..l/- Ge,sL)e,s w3e,3er ,3e dialog *o; con,ains an a..l/ *u,,on1 )3owColors- Ge,sL)e,s w3e,3er ,3e dialog *o; dis.la/s ,3e color c3oice1 )3ow%00ec,s- Ge,sL)e,s w3e,3er ,3e dialog *o; con,ains con,rols ,3a, allow ,3e user ,o s.eci0/ ,o s.eci0/ s,ri9e,3roug3: underline and ,e;, color o.,ions1 )3ow>el.- Ge,sL)e,s w3e,3er ,3e dialog *o; dis.la/s a 3el. *u,,on1 .o+orDia+o(s Pro.er,ies o0 Color=ialog are as 0ollowsAllow&ull#.en- Ge,sL)e,s w3e,3er ,3e user can use ,3e dialog *o; ,o de0ine cus,om colors1 An/Color- Ge,sL)e,s w3e,3er ,3e dialog *o; dis.la/s all ,3e availa*le colors in ,3e se, o0 *asic colons1 Color- Ge,sL)e,s ,3e color selec,ed */ ,3e user1 Cus,omColors- Ge,sL)e,s ,3e se, o0 cus,om colors s3own in ,3e dialog *o;1 &ull#.en- Ge,sL)e,s w3e,3er ,3e con,rols used ,o crea,e cus,om colors are visi*le w3en ,3e dialog *o; is o.ened1 )3ow>el.- Ge,sL)e,s w3e,3er ,3e dialog *o; dis.la/s a 3el. *u,,on1 )olidColor#nl/- Ge,sL)e,s w3e,3er ,3e dialog *o; will res,ric, users ,o selec,ing solid colors onl/1 T%EEVIEW .ONT%O"

Navgu+ara, BCA

Page 26 o0 56

Advanced Visual and Windows Programming(BCA-205) "3e Windows &orms TreeVie4 con,rol dis.la/s a 3ierarc3/ o0 nodes: li9e ,3e wa/ 0iles and 0olders are dis.la/ed in ,3e le0, .ane o0 Windows %;.lorer1 "3e Windows &orms TreeVie4 con,rol dis.la/s a 3ierarc3/ o0 nodes: li9e ,3e wa/ 0iles and 0olders are dis.la/ed in ,3e le0, .ane o0 Windows %;.lorer1 %ac3 node mig3, con,ain o,3er nodes: called c3ild nodes1 Paren, nodes: or nodes ,3a, con,ain c3ild nodes: can *e dis.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: i0 ,3e ,ree view<s .hec<Bo-es .ro.er,/ is se, ,o tr)e1 Eou can ,3en .rogramma,icall/ selec, or clear nodes */ se,,ing ,3e node<s .hec<ed .ro.er,/ ,o tr)e or fa+se1 "3e 9e/ .ro.er,ies o0 ,3e TreeVie4 con,rol are Nodes and Se+ectedNode1 "3e Nodes .ro.er,/ con,ains ,3e lis, o0 ,o.-level nodes in ,3e ,ree view1 "3e Se+ectedNode .ro.er,/ se,s ,3e curren,l/ selec,ed node1 (cons can *e dis.la/ed ne;, ,o ,3e nodesQ ,3e images are ,a9en 0rom ,3e I*a(e"ist con,rol named in ,3e ,ree view<s I*a(e"ist .ro.er,/1 "3e I*a(eInde- .ro.er,/ se,s ,3e de0aul, image 0or nodes in ,3e ,ree view1 &or more in0orma,ion on dis.la/ing images To add or re*ove nodes in the desi(ner 41 )elec, ,3e TreeVie4 con,rol or add one ,o ,3e 0orm1 21 (n ,3e Pro.er,ies window: clic9 ,3e elli.sis ( .ro.er,/1 "3e TreeNode Editor a..ears1 71 "o add nodes: a roo, node mus, e;is,Q i0 one does no, e;is,: /ou mus, 0irs, add a roo, */ clic9ing ,3e #dd %oot *u,,on1 Eou can ,3en add c3ild nodes */ selec,ing ,3e roo, or an/ o,3er node and clic9ing ,3e #dd .hi+d *u,,on1 "o dele,e nodes: selec, ,3e node ,o dele,e and ,3en clic9 ,3e De+ete *u,,on1 To add nodes pro(ra**atica++y Use ,3e #dd me,3od o0 ,3e ,ree view<s Nodes .ro.er,/1 =im newNode As "reeNode F New "reeNode(G"e;, 0or new nodeG) "reeView41)elec,edNode1Nodes1Add(newNode) To re*ove nodes pro(ra**atica++y Use ,3e %e*ove me,3od o0 ,3e ,ree view<s Nodes .ro.er,/ ,o remove a single node: or ,3e .+ear me,3od ,o clear all nodes1
TreeView1.No es.!emo"e#TreeView1.Selecte No e$ TreeView1.No es.Clear#$

) *u,,on ne;, ,o ,3e Nodes

"o de,ermine w3ic3 "reeView node was clic9ed

Navgu+ara, BCA

Page 2B o0 56

Advanced Visual and Windows Programming(BCA-205) Use ,3e %ven,Args o*+ec, ,o re,urn a re0erence ,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* "reeView4SA0,er)elec,(B/Val sender As )/s,em1#*+ec,: S B/Val e As )/s,em1Windows1&orms1"reeView%ven,Args) >andles "reeView41A0,er)elec, 1 'essageBo;1)3ow(e1Node1"e;,) %nd )u*

"ISTVIEW .ONT%O"
"3e Windows &orms "istVie4 con,rol dis.la/s a lis, o0 i,ems wi,3 icons1 Eou can use a lis, view ,o crea,e a user in,er0ace li9e ,3e rig3, .ane o0 Windows %;.lorer1 "3e Windows &orms "istVie4 con,rol dis.la/s a lis, o0 i,ems wi,3 icons1 Eou can use a lis, view ,o crea,e a user in,er0ace li9e ,3e rig3, .ane o0 Windows %;.lorer1 "3e con,rol 3as 0our view modes- $arge(con: )mall(con: $is,: and =e,ails1 "3e $arge(con mode dis.la/s large icons ne;, ,o ,3e i,em ,e;,Q ,3e i,ems a..ear in mul,i.le columns i0 ,3e con,rol is large enoug31 "3e )mall(con 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,/ o0 ,3e "istVie4 con,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 o0 ,3e i,ems curren,l/ selec,ed in ,3e con,rol1 "3e user can selec, mul,i.le i,ems: 0or e;am.le ,o drag and dro. several i,ems a, a ,ime ,o ano,3er con,rol: i0 ,3e ')+tiSe+ect .ro.er,/ is se, ,o tr)e1 "3e "istVie4 con,rol can dis.la/ c3ec9 *o;es ne;, ,o ,3e i,ems: i0 ,3e .hec<Bo-es .ro.er,/ is se, ,o tr)e1 "3e #ctivation .ro.er,/ de,ermines w3a, ,/.e o0 ac,ion ,3e user mus, ,a9e ,o ac,iva,e an i,em in ,3e lis,- ,3e o.,ions are ),andard: #neClic9: and "woClic91 #neClic9 ac,iva,ion reAuires a single clic9 ,o ac,iva,e ,3e i,em1 "woClic9 ac,iva,ion reAuires ,3e user ,o dou*le-clic9 ,o ac,iva,e ,3e i,emQ a single clic9 c3anges ,3e color o0 ,3e i,em ,e;,1 ),andard ac,iva,ion reAuires ,3e user ,o dou*le-clic9 ,o ac,iva,e an i,em: *u, ,3e i,em does no, c3ange a..earance

To add or re*ove ite*s in the desi(ner

Navgu+ara, BCA

Page 2C o0 56

Advanced Visual and Windows Programming(BCA-205)

41 (n ,3e Pro.er,ies window: clic9 ,3e elli.sis *u,,on ( .ro.er,/1 "3e "istVie4Ite* .o++ection Editor a..ears1

) ne;, ,o ,3e Ite*s

21 "o add an i,em: clic9 ,3e #dd *u,,on1 Eou can ,3en se, .ro.er,ies o0 ,3e new i,em: suc3 as ,3e Te-t and 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<s Vie4 .ro.er,/ ,o Detai+s1 21 (n ,3e Pro.er,ies window: clic9 ,3e elli.sis *u,,on ( .ro.er,/1 "3e .o+)*n$eader .o++ection Editor a..ears1 71 Use ,3e #dd *u,,on ,o add new columns1 Eou can ,3en selec, ,3e column 3eader and se, i,s ,e;, (,3e ca.,ion o0 ,3e column): ,e;, alignmen,: and wid,31 To add co+)*ns pro(ra**atica++y )e, ,3e con,rol<s Vie4 .ro.er,/ ,o Detai+s1 Use ,3e #dd me,3od o0 ,3e lis, view<s .o+)*ns .ro.er,/1
%istView1.View = View.Details %istView1.Col+m,s.A #'-ile t./e') 01) 2ori3o,talAli4,me,t.%e5t$

) ne;, ,o ,3e .o+)*ns

To disp+ay i*a(es in a +ist vie4 41 )e, ,3e a..ro.ria,e .ro.er,/: S*a++I*a(e"ist: "ar(eI*a(e"ist: or StateI*a(e"ist: ,o ,3e e;is,ing I*a(e"ist com.onen, /ou wis3 ,o use1 "3ese .ro.er,ies can *e se, in ,3e designer wi,3 ,3e Pro.er,ies window: or in code1
6 Vis+al 7asic %istView1.Small&ma4e%ist = &ma4e%ist1

Navgu+ara, BCA

Page 25 o0 56

Advanced Visual and Windows Programming(BCA-205) 21 )e, ,3e I*a(eInde- or StateI*a(eInde- .ro.er,/ 0or 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 Vis+al 7asic 6 Sets t8e 5irst list item to is/la. t8e 9t8 ima4e %istView1.&tems#1$.&ma4e&, e( = *

OOP=.oncept
Ob ects Visual *asic allows /ou ,o crea,e o*+ec, */ de0ining class1Class ma/ 3ave .ro.er,ies and me,3ods1 #*+ec, is a ,3ing w3ic3 is .ro.er,ies and me,3ods1 User de0ined class can *e crea,ed in v*1and ,3a, classes can *e incor.ora,ed ,o .ro+ec,s as a re0erences1 Pro.er,ies are ,3e c3arac,eris,ic and me,3ods are ,3e o.era,ion ,3a, can *e .er0ormed on an o*+ec,1 OOP=Ter*ino+o(y %nca.sula,ion (n3eri,ance Pol/mor.3ism ."#SSES (ns,an,ia,ing an o*+ec, New class name i1e =im c F new 0on,(TarialU:42) $*l0n,10on,Fc .reatin( yo)r o4n c+asses Crea,e a new a..lica,ion o0 ,/.e class li*rar/ Crea,e .ro.er,ies o0 ,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 o0 56

Advanced Visual and Windows Programming(BCA-205) &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( yo)r o4n c+asses Crea,e a new a..lica,ion o0 ,/.e class li*rar/ Crea,e .ro.er,ies o0 ,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 &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 ob ect )sin( c+asses Crea,e new o*+ec, using 0ollowing s,a,emen, in windows a..lica,ion =im c as new class name "3is class name mus, *e add as a re0erence in a .ro+ec,1

!ata Access Tec"nologies


'os, a..lica,ions reAuire some 0orm o0 da,a access1 (0 /ou are crea,ing a new a..lica,ion: /ou 3ave ,3ree e;cellen, da,a access c3oices- A=#1N%": A=#: and #$% =B1 (0 /ou need ,o modi0/ ,3e da,a access 0or an e;is,ing a..lica,ion: /ou mig3, con,inue using ,3e a..lica,ion<s curren, da,a access ,ec3nolog/ 0or main,enance convenience1 >owever: i0 /ou e;.ec, ,3e a..lica,ion ,o 3ave a long li0ec/cle: /ou s3ould consider reengineering ,o use ei,3er A=#1N%" 0or managed a..lica,ions or A=# 0or na,ive a..lica,ions1 (n ,3e

Navgu+ara, BCA

Page 74 o0 56

Advanced Visual and Windows Programming(BCA-205) long run: ,3e newer da,a access ,ec3nologies ,/.icall/ reduce develo.men, ,ime: sim.li0/ code: and .rovide e;cellen, .er0ormance1

A!#$%&T
A=#1N%" is ,3e s,ra,egic a..lica,ion-level in,er0ace 0or .roviding da,a access services in ,3e 'icroso0, 1N%" Pla,0orm1 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 0or )V$ )erver1 1N%" &ramewor9 =a,a Provider 0or #$% =B1 1N%" &ramewor9 =a,a Provider 0or #=BC1 1N%" &ramewor9 =a,a Provider 0or #racle1

"3ese da,a .roviders su..or, a varie,/ o0 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.eci0icall/ 0or message-*ased We* a..lica,ions w3ile s,ill .roviding .re0era*le 0unc,ionali,/ 0or 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 ,3e num*er o0 ac,ive connec,ions ,o ,3e da,a*ase W reducing ,3e .ossi*ili,/ o0 mul,i.le users con,ending 0or limi,ed resources on ,3e da,a*ase server1 A=#1N%" .rovides several wa/s ,o access da,a1 (0 /our We* a..lica,ion or @'$ We* service reAuires da,a access 0rom mul,i.le sources: needs ,o in,ero.era,e wi,3 o,3er a..lica,ions (*o,3 local and remo,e): or can *ene0i, 0rom .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 Aueries and s,ored .rocedures: crea,ing

#dvanta(es of #DO.NET over #DO

Interoperabi+ity
A=#1N%" a..lica,ions can ,a9e advan,age o0 ,3e 0le;i*ili,/ and *road acce.,ance o0 @'$1 Because @'$ is ,3e 0orma, 0or ,ransmi,,ing da,ase,s across ,3e ne,wor9: an/ com.onen, ,3a, can read ,3e @'$ 0orma, can .rocess da,a1 (n 0ac,: ,3e receiving com.onen, need no, *e an A=#1N%" com.onen, a, all- "3e ,ransmi,,ing com.onen, can sim.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/ reAuiremen, 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 o0 in,ero.era*ili,/ in mind1

Navgu+ara, BCA

Page 72 o0 56

Advanced Visual and Windows Programming(BCA-205)

'aintainabi+ity
(n ,3e li0e o0 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 di00icul,1 "3a, is un0or,una,e: *ecause in a na,ural course o0 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: ,3e increased .er0ormance load mig3, reAuire arc3i,ec,ural c3anges1 As ,3e .er0ormance load on a de.lo/ed a..lica,ion server grows: s/s,em resources can *ecome scarce and res.onse ,ime or ,3roug3.u, can su00er1 &aced wi,3 ,3is .ro*lem: so0,ware arc3i,ec,s can c3oose ,o divide ,3e server<s *usiness-logic .rocessing and user-in,er0ace .rocessing on,o se.ara,e ,iers on se.ara,e mac3ines1 (n e00ec,: ,3e a..lica,ion server ,ier is re.laced wi,3 ,wo ,iers: allevia,ing ,3e s3or,age o0 s/s,em resources1 "3e .ro*lem is no, designing a ,3ree-,iered a..lica,ion1 !a,3er: i, is increasing ,3e num*er o0 ,iers a0,er an a..lica,ion is de.lo/ed1 (0 ,3e original a..lica,ion is im.lemen,ed in A=#1N%" using da,ase,s: ,3is ,rans0orma,ion is made easier1 !emem*er: w3en /ou re.lace a single ,ier wi,3 ,wo ,iers: /ou arrange 0or ,3ose ,wo ,iers ,o ,rade in0orma,ion1 Because ,3e ,iers can ,ransmi, da,a ,3roug3 @'$-0orma,,ed da,ase,s: ,3e communica,ion is rela,ivel/ eas/1

Pro(ra**abi+ity
A=#1N%" da,a com.onen,s in Visual ),udio enca.sula,e da,a access 0unc,ionali,/ in various wa/s ,3a, 3el. /ou .rogram more Auic9l/ and wi,3 0ewer mis,a9es1 &or e;am.le: da,a commands a*s,rac, ,3e ,as9 o0 *uilding and e;ecu,ing )V$ s,a,emen,s or s,ored .rocedures1 )imilarl/: A=#1N%" da,a classes genera,ed */ ,3e ,ools resul, in ,/.ed da,ase,s1 "3is in ,urn allows /ou ,o access da,a ,3roug3 ,/.ed .rogramming1 &or e;am.le: consider ,3e 0ollowing line o0 code ,3a, accesses a da,a mem*er in an un,/.ed da,ase,"3e eAuivalen, line ,o access a da,a mem*er in a ,/.ed da,ase, loo9s li9e ,3e 0ollowing< Visual Basic

Perfor*ance
&or disconnec,ed a..lica,ions: A=#1N%" da,ase,s o00er .er0ormance advan,ages over A=# disconnec,ed recordse,s1 W3en using C#' mars3alling ,o ,ransmi, a disconnec,ed recordse, among ,iers: a signi0ican, .rocessing cos, can resul, 0rom conver,ing ,3e values in ,3e recordse, ,o da,a ,/.es recogniDed */ C#'1 (n A=#1N%": suc3 da,a-,/.e conversion is no, necessar/1

Sca+abi+ity
Because ,3e We* can vas,l/ increase ,3e demands on /our da,a: scala*ili,/ 3as *ecome cri,ical1 (n,erne, a..lica,ions 3ave a limi,less su..l/ o0 .o,en,ial users1 Al,3oug3 an

Navgu+ara, BCA

Page 77 o0 56

Advanced Visual and Windows Programming(BCA-205) a..lica,ion mig3, serve a doDen users well: i, mig3, no, serve 3undreds Wor 3undreds o0 ,3ousands W eAuall/ 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 o0 users well: *ecause ,3e user demand 0or ,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 o0 da,a is ,3e recordse,1 (n A=#1N%": i, is ,3e da,ase,1 "3ere are im.or,an, di00erences *e,ween ,3em1

!ata %a'igation and Cursors


(n A=# /ou scan seAuen,iall/ ,3roug3 ,3e rows o0 ,3e recordse, using ,3e A=# 'oveNe-t me,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 ordinal or .rimar/ 9e/ inde;1 Data%e+ation o*+ec,s main,ain in0orma,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 are wor9ing wi,31 &or e;am.le: s,ar,ing 0rom ,3e row o0 ,3e &,"estor ,a*le 0or GNa,e )un:G /ou can naviga,e ,o ,3e se, o0 rows o0 ,3e :+rc8ase ,a*le descri*ing 3is .urc3ases1 A cursor is a da,a*ase elemen, ,3a, con,rols record naviga,ion: ,3e a*ili,/ ,o u.da,e da,a: and ,3e visi*ili,/ o0 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 0unc,ionali,/ o0 a ,radi,ional cursor1 &or e;am.le: ,3e 0unc,ionali,/ o0 a 0orward-onl/: read-onl/ cursor is availa*le in ,3e A=#1N%" Data%eader o*+ec,1 &or more in0orma,ion a*ou, cursor 0unc,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 0oo,.rin,: use minimal ne,wor9 ,ra00ic: and reAuire 0ew la/ers *e,ween ,3e a..lica,ion<s 0ron,-end and ,3e da,a source1 Bo,3 me,3ods .rovide 3ig3-.er0ormance da,a access1 C3oosing ei,3er o0 ,3ese da,a access ,ec3nologies a00ec,s an a..lica,ion<s design: e;,ensi*ili,/: in,ero.era*ili,/: ease o0 main,enance: and man/ o,3er 0ac,ors1 "3ese include

'ana(ed code (0 /our a..lica,ion is wri,,en in managed code and *uil, u.on ,3e common language run,ime: /ou s3ould use A=#1N%"1 (0 /ou are wri,ing unmanaged code in CII (and es.eciall/ i0 /ou are main,aining an e;is,ing A=# a..lica,ion): A=# is s,ill a good c3oice1 Data str)ct)re "3e A=#1N%" da,ase, can con,ain one or more ,a*les: and .rovides *o,3 a ,a*le-*ased rela,ional view and an @'$-*ased view1 "3e da,ase, uses s,andard common language run,ime ,/.es: w3ic3 sim.li0ies .rogramming1

Navgu+ara, BCA

Page 78 o0 56

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, o0 a mul,i.le ,a*le #(N Auer/: *u, i, is s,ill onl/ a single resul, ,a*le1 (0 /ou wan, mul,i.le ,a*les wi,3 A=#: /ou mus, 3ave mul,i.le !ecordse, o*+ec,s1 "3e A=#1N%" da,ase, .rovides *e,,er 0unc,ionali,/ due ,o i,s in,egra,ed rela,ional s,ruc,ure1

Data sharin( A=#1N%" .rovides ,3e *asis 0or da,a in,erc3ange *e,ween com.onen,s and across ,iers- da,ase,s can *e .assed over ,3e (n,erne, and ,3roug3 0irewalls as @'$1 Eou can view ,3e same se, o0 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/ ,rans0orma,ion- 0rom da,ase, ,a*les ,o an @'$ documen,: and 0rom an @'$ documen, in,o da,ase, ,a*les1 (0 /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 reAuires more di00icul, .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,3er a..lica,ions and services1

Sca+abi+ity A=#1N%" is ,3e mos, scala*le solu,ion1 A=#1N%" is designed 0rom ,3e ground u. ,o *e ,3e *es, da,a access arc3i,ec,ure 0or *uilding scala*le We* a..lica,ions wi,3 a low ,o,al cos, o0 owners3i.1 (0 /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 o0 ,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 0or an/ ,/.e o0 im.rom.,u user in,erac,ion wi,3 ,3e da,a1 Clien,-side cursors are su..or,ed in A=#1N%" */ ,3e =a,a)e, 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 di00eren, reAuiremen,s 0or wor9ing wi,3 da,a1 (n some cases: /ou mig3, sim.l/ wan, ,o dis.la/ da,a on a 0orm1 (n o,3er cases: /ou mig3, need ,o devise a wa/ ,o s3are in0orma,ion wi,3 ano,3er com.an/1 No ma,,er w3a, /ou do wi,3 da,a: ,3ere are cer,ain 0undamen,al conce.,s ,3a, /ou s3ould unders,and a*ou, ,3e da,a a..roac3 in A=#1N%"1 Eou mig3, never need ,o 9now some o0 ,3e de,ails o0 da,a 3andling W 0or e;am.le: /ou mig3, never need ,o direc,l/ edi, an @'$ 0ile con,aining da,a W *u, i, is ver/ use0ul ,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 0i, ,oge,3er1 "3is in,roduc,ion .resen,s a 3ig3-level overview o0 ,3ese mos, im.or,an, conce.,s1 "3e ,o.ic deli*era,el/ s9i.s over man/ de,ails W 0or e;am.le: ,3ere is muc3 more ,o da,ase,s ,3an w3a, is men,ioned 3ere W in 0avor o0 sim.l/ in,roducing /ou ,o ideas *e3ind da,a in,egra,ion in A=#1N%"1 Navgu+ara, BCA Page 75 o0 56

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,/ o0 reasons: ,3is a..roac3 is 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 o0 concurren, connec,ions1 "3e over3ead o0 main,aining ,3ese connec,ions de,rac,s 0rom overall a..lica,ion .er0ormance1 )imilarl/: a..lica,ions ,3a, reAuire an o.en da,a*ase connec,ion are e;,remel/ di00icul, ,o scale u.1 An a..lica,ion ,3a, does no, scale u. well mig3, .er0orm acce.,a*l/ wi,3 0our users *u, will li9el/ no, do so wi,3 3undreds1 A)P1N%" We* a..lica,ions in .ar,icular need ,o *e easil/ scala*le: *ecause ,ra00ic ,o a We* si,e can go u. */ orders o0 magni,ude in a ver/ s3or, .eriod1 (n A)P1N%" We* a..lica,ions: ,3e com.onen,s are in3eren,l/ disconnec,ed 0rom eac3 o,3er1 "3e *rowser reAues,s a .age 0rom ,3e serverQ w3en ,3e server 3as 0inis3ed .rocessing and sending ,3e .age: i, 3as no 0ur,3er connec,ion wi,3 ,3e *rowser un,il ,3e ne;, reAues,1 Under ,3ese circums,ances: main,aining o.en connec,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,) reAuires 0ur,3er da,a access1 A model *ased on alwa/s-connec,ed da,a can ma9e i, di00icul, and im.rac,ical ,o e;c3ange da,a across a..lica,ion and organiDa,ional *oundaries using a connec,ed arc3i,ec,ure1 (0 ,wo com.onen,s need ,o s3are ,3e same da,a: *o,3 3ave ,o *e connec,ed: or a wa/ mus, *e devised 0or ,3e com.onen,s ,o .ass da,a *ac9 and 0or,31

!atabase Interactions Are )erformed *sing !ata Commands


"o .er0orm o.era,ions in a da,a*ase: /ou e;ecu,e )V$ s,a,emen,s or s,ored .rocedures (w3ic3 include )V$ s,a,emen,s)1 Eou use )V$ s,a,emen,s or s,ored .rocedures ,o read and wri,e rows and .er0orm aggrega,e 0unc,ions: suc3 as adding or averaging1 Eou also use )V$ s,a,emen,s or s,ored .rocedures ,o crea,e or modi0/ ,a*les or columns: ,o .er0orm ,ransac,ions: and so on1 (n A=#1N%" /ou use da,a commands ,o .ac9age a )V$ s,a,emen, or s,ored .rocedure1 &or e;am.le: i0 /ou wan, ,o read a se, o0 rows 0rom ,3e da,a*ase: /ou crea,e a da,a command and con0igure i, wi,3 ,3e ,e;, o0 a )V$ )elec, s,a,emen, or ,3e name o0 a s,ored .rocedure ,3a, 0e,c3es records1 W3en /ou wan, ,o ge, ,3e rows: /ou do ,3e 0ollowing41 #.en a connec,ion1 21 Call an e;ecu,e me,3od o0 ,3e command: w3ic3 in ,urna1 %;ecu,es ,3e )V$ s,a,emen, or s,ored .rocedure re0erenced */ ,3e command1

Navgu+ara, BCA

Page 76 o0 56

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<s e;ecu,e me,3od: i, re,urns a value1 Commands ,3a, u.da,e ,3e da,a*ase re,urn ,3e num*er o0 rows a00ec,edQ o,3er ,/.es o0 commands re,urn an error code1 (0 ,3e command Aueries ,3e da,a*ase wi,3 a )%$%C" s,a,emen,: ,3e command can re,urn a se, o0 rows1 Eou can 0e,c3 ,3ese rows using a da,a reader: w3ic3 ac,s as a ver/ 0as, read-onl/: 0orward-onl/ cursor1 &or more in0orma,ion: see !e,rieving =a,a Using ,3e =a,a!eader1

.o*ponents of #DO.NET
"3e 0ollowing illus,ra,ion s3ows ,3e ma+or com.onen,s o0 an A=#1N%" a..lica,ion1 #DO.NET Data .o*ponents "3e 0ollowing ,a*le summariDes ,3e A=#1N%" da,a com.onen,s illus,ra,ed a*ove and .rovides lin9s ,o more in0orma,ion1 .o*ponent or ob ect =a,ase, =a,a ada.,er =a,a connec,ion Windows &orm We* &orms .age BiD"al9

A!#$%&T Connection
"o move da,a *e,ween a da,a s,ore and /our a..lica,ion: /ou mus, 0irs, 3ave a connec,ion ,o ,3e da,a s,ore1 Note =a,a ada.,ers: da,a connec,ions: da,a commands: and da,a readers are ,3e com.onen,s ,3a, ma9e u. a 1N%" &ramewor9 da,a .rovider1 'icroso0, and ,3ird-.ar,/ .roviders can ma9e availa*le o,3er 1N%" &ramewor9 da,a .roviders ,3a, can *e in,egra,ed in,o Visual ),udio1 &or more in0orma,ion: see 1N%" =a,a Providers1 (n A=#1N%" /ou crea,e and manage connec,ions using connec,ion o*+ec,s-

Navgu+ara, BCA

Page 7B o0 56

Advanced Visual and Windows Programming(BCA-205)

)AlConnec,ion - an o*+ec, ,3a, manages a connec,ion ,o a )V$ )erver version B10 or la,er1 (, is o.,imiDed 0or use wi,3 )V$ )erver B10 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.eci0ic mem*ers availa*le wi,3 a given O+eDb.onnection o*+ec, de.end on w3a, da,a source i, is connec,ed ,oQ no, all da,a sources su..or, all mem*ers o0 ,3e O+eDb.onnection class1 "3e .rimar/ .ro.er,/ associa,ed wi,3 a connec,ion o*+ec, is ,3e .onnectionStrin( .ro.er,/: w3ic3 consis,s o0 a s,ring wi,3 a,,ri*u,eLvalue .airs 0or in0orma,ion reAuired ,o log on ,o a da,a*ase and .oin, ,o a s.eci0ic da,a*ase1 A ,/.ical .onnectionStrin( .ro.er,/ mig3, loo9 li9e ,3e 0ollowing:ro"i er=S;%O%<D7.1=Data So+rce=M.S;%Ser"er=&,itial Catalo4=NO!T2>&ND=&,te4rate Sec+rit.=SS:&

"3e mos, common a,,ri*u,eLvalue .airs used */ #$% =B are also re.resen,ed se.ara,el/ */ an individual .ro.er,/: suc3 as DataSo)rce and Database1 W3en wor9ing wi,3 a connec,ion o*+ec,: /ou can ei,3er se, ,3e .onnectionStrin( .ro.er,/ as a single s,ring: or /ou can se, individual connec,ion .ro.er,ies1 ((0 /our da,a source reAuires connec,ions,ring values ,3a, are no, re.resen,ed */ individual .ro.er,ies: ,3en /ou mus, se, ,3e .onnectionStrin( .ro.er,/1) Al,erna,ivel/: /ou can also se, ,3e .onnectionStrin( .ro.er,/ ,o ,3e .a,3 o0 a 'icroso0, =a,a $in9 (1udl) 0ile1 &or more in0orma,ion a*ou, da,a lin9 0iles: see =a,a $in9 AP( #verview1

Openin( and .+osin( .onnections


"3e ,wo .rimar/ me,3ods 0or connec,ions are Open and .+ose1 "3e Open me,3od uses ,3e in0orma,ion in ,3e .onnectionStrin( .ro.er,/ ,o con,ac, ,3e da,a source and es,a*lis3 an o.en connec,ion1 "3e .+ose me,3od s3u,s ,3e connec,ion down1 Closing connec,ions is essen,ial: *ecause mos, da,a sources su..or, onl/ a limi,ed num*er o0 o.en connec,ions: and o.en connec,ions ,a9e u. valua*le s/s,em resources1 (0 /ou are wor9ing wi,3 da,a ada.,ers or da,a commands: /ou do no, 3ave ,o e;.lici,l/ o.en and close a connec,ion1 W3en /ou call a me,3od o0 ,3ese o*+ec,s (0or e;am.le: ,3e da,a ada.,er<s Fi++ or 0pdate me,3od): ,3e me,3od c3ec9s w3e,3er ,3e connec,ion is alread/ o.en1 (0 no,: ,3e ada.,er o.ens ,3e connec,ion: .er0orms i,s logic: and closes ,3e connec,ion again1

Navgu+ara, BCA

Page 7C o0 56

Advanced Visual and Windows Programming(BCA-205)

Desi(n=Ti*e .onnections in Server E-p+orer


)erver %;.lorer .rovides a wa/ 0or /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/ in0orma,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 in0orma,ion .rovided */ a design-,ime connec,ion is used ,o se, .ro.er,ies 0or 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 0or connec,ion in0orma,ion (,3a, is: connec,ion-s,ring in0orma,ion) and au,oma,icall/ crea,e connec,ion o*+ec,s 0or /ou on ,3e 0orm or com.onen, /ou are wor9ing wi,31 >owever: i0 /ou wan,: /ou can add connec,ion o*+ec,s /oursel0 ,o a 0orm or com.onen, and se, ,3eir .ro.er,ies1 "3is is use0ul i0 /ou are no, wor9ing wi,3 da,ase,s (and ,3ere0ore no, wi,3 da,a ada.,ers): *u, ins,ead sim.l/ reading da,a1 Eou mig3, crea,e connec,ion o*+ec,s /oursel0 i0 /ou will *e using ,ransac,ions1

Introduction to !ata Adapters


=a,a ada.,ers are an in,egral .ar, o0 A=#1N%" managed .roviders: w3ic3 are ,3e se, o0 o*+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: and command o*+ec,s1) Ada.,ers are used ,o e;c3ange da,a *e,ween a da,a source and a da,ase,1 (n man/ a..lica,ions: ,3is means reading da,a 0rom a da,a*ase in,o a da,ase,: and ,3en wri,ing c3anged da,a 0rom ,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 'icroso0, %;c3ange server and a da,ase,1 Generall/: ada.,ers are con0igura*le ,o allow /ou ,o s.eci0/ w3a, da,a ,o move in,o and ou, o0 ,3e da,ase,1 #0,en ,3is ,a9es ,3e 0orm o0 re0erences ,o )V$ 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 0or use wi,3 da,a*ases

"3e #le=*=a,aAda.,er o*+ec, is sui,a*le 0or use wi,3 an/ da,a source e;.osed */ an #$% =B .rovider1 "3e )Al=a,aAda.,er o*+ec, is s.eci0ic ,o )V$ )erver1 Because i, does no, 3ave ,o go ,3roug3 an #$% =B la/er: i, is 0as,er ,3an ,3e O+eDbData#dapter1 >owever: i, can onl/ *e used wi,3 )V$ )erver B10 or la,er1 "3e #d*c=a,aAda.,er o*+ec, is o.,imiDed 0or accessing #=BC da,a sources1 Page 75 o0 56

Navgu+ara, BCA

Advanced Visual and Windows Programming(BCA-205)

"3e #racle=a,aAda.,er o*+ec, is o.,imiDed 0or accessing #racle da,a*ases1

Data #dapters and %e+ated Tab+es


An im.lica,ion o0 3aving se.ara,e ,a*les in ,3e da,ase, is ,3a, a da,a ada.,er ,/.icall/ does no, re0erence )V$ commands or s,ored .rocedures ,3a, +oin ,a*les1 (ns,ead: in0orma,ion 0rom ,3e rela,ed ,a*les is read se.ara,el/ in,o ,3e da,ase, */ di00eren, ada.,ers1 "3en a Data%e+ation o*+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,3wind da,a*ase: Cus,omers and #rders1 !a,3er ,3an s.eci0/ing a +oin ,o com*ine *o,3 ,a*les in,o a single resul, se,: /ou would mos, commonl/ de0ine ,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 di00eren, da,ase, ,a*le1 "3e individual ada.,ers would .ro*a*l/ include selec,ion cri,eria ,o limi, ,3e num*er o0 records in ,3e da,a ,a*les1 (n ,3e da,ase, /ou would also de0ine a Data%e+ation o*+ec, s.eci0/ing ,3a, order records are rela,ed ,o cus,omer records */ ,3e Cus,omer(= 0ield1 Eou can s,ill manage ,3e ,a*les individuall/: w3ic3 would no, *e .ossi*le i0 /ou 3ad +oined ,a*les *e0ore 0e,c3ing records 0rom ,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 o0 ,3e Data%e+ation o*+ec,1

#DO.NET .o**and Ob ects


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.eci0/ 3ow eac3 o0 ,3ese o.era,ions s3ould occur: an ada.,er su..or,s ,3e 0ollowing 0our .ro.er,ies

Se+ect.o**and P re0erence ,o a command ()V$ s,a,emen, or s,ored .rocedure name) ,3a, re,rieves rows 0rom ,3e da,a s,ore1 Insert.o**and P re0erence ,o a command 0or inser,ing rows in,o ,3e da,a s,ore1 0pdate.o**and P re0erence ,o a command 0or modi0/ing rows in ,3e da,a s,ore1 De+ete.o**and P re0erence ,o a command 0or dele,ing rows 0rom ,3e da,a s,ore1

"3e .ro.er,ies are ,3emselves o*+ec,s W ,3e/ are ins,ances o0 ,3e )AlCommand: #le=*Command: #d*cCommand: or #racleCommand class1 "3e o*+ec,s su..or, a .o**andTe-t .ro.er,/ con,aining a re0erence ,o an )V$ s,a,emen, or s,ored .rocedure1

Navgu+ara, BCA

Page 80 o0 56

Advanced Visual and Windows Programming(BCA-205) Note "3e command class mus, ma,c3 ,3e connec,ion class1 &or e;am.le: i0 /ou are using a S>+.onnection o*+ec, ,o communica,e wi,3 a )V$ )erver: /ou mus, also use commands ,3a, derive 0rom ,3e S>+.o**and class1 Al,3oug3 /ou can e;.lici,l/ se, ,3e ,e;, o0 a command o*+ec,: /ou do no, alwa/s need ,oQ in man/ si,ua,ions: Visual ),udio will genera,e ,3e )V$ s,a,emen,s needed1 (n addi,ion: ,3e ada.,er can au,oma,icall/ genera,e a..ro.ria,e )V$ s,a,emen,s a, run ,ime i0 ,3e 0pdate.o**and: Insert.o**and: or De+ete.o**and o*+ec,s are no, s.eci0ied1 &or de,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 can crea,e or modi0/ ,3e command associa,ed wi,3 a Se+ect.o**and o*+ec, +us, *e0ore i, is e;ecu,ed1 Eou can also e;ecu,e commands /oursel0: inde.enden,l/ o0 ,3e da,a ada.,er1 "3is allows /ou ,o .ass ar*i,rar/ )V$ commands ,3roug3 ,3e da,a ada.,er: suc3 as ,3ose used ,o de0ine or modi0/ da,a*ase de0ini,ions1 Eou can also call s,ored .rocedures direc,l/ ,3a, do no, re,urn record se,s W 0or 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 0or ,3e Se+ect.o**and .ro.er,/: 0or e;am.le: o0,en 3as a .arame,er in i,s W>%!% clause so /ou can s.eci0/ a, run ,ime w3a, records ,o ge, 0rom ,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 in0orma,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 o0 ,3e da,a ada.,er is ,o communica,e da,a *e,ween a da,a s,ore and a da,ase,1 "3e ada.,er su..or,s s.eci0ic me,3ods ,o move ,3e da,a *ac9 and 0or,3 *e,ween ,3e ,wo1 Note (0 /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, o0 ,3e da,a*ase and in,o an a..lica,ion1 &or de,ails: see G!ead-#nl/ =a,aG *elow1 Eou can use a da,a ada.,er ,o .er0orm ,3e 0ollowing o.era,ions

!e,rieve rows 0rom 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, ()Al=a,aAda.,er: #le=*=a,aAda.,er: #d*c=a,aAda.,er: or #racle=a,aAda.,er)1

Navgu+ara, BCA

Page 84 o0 56

Advanced Visual and Windows Programming(BCA-205) W3en /ou invo9e ,3e Fi++ me,3od: i, ,ransmi,s an )V$ )%$%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 W cac3es W in w3ic3 /ou can s,ore da,a ,o use in /our a..lica,ion1 =a,ase,s are a 0undamen,al .ar, o0 ,3e A=#1N%" arc3i,ec,ure: .roviding *o,3 3ig3-.er0ormance 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 o0 a da,ase, is similar ,o ,3a, o0 a rela,ional da,a*aseQ i, e;.oses a 3ierarc3ical o*+ec, model o0 ,a*les: rows: and columns1 (n addi,ion: i, con,ains cons,rain,s and rela,ions3i.s de0ined 0or ,3e da,ase,1 "3e 0undamen,al .ar,s o0 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,a)e, class includes ,3e "a*les collec,ion o0 da,a ,a*les and ,3e !ela,ions collec,ion o0 =a,a!ela,ion o*+ec,s1 "3e =a,a"a*le class includes ,3e !ows collec,ion o0 ,a*le rows: ,3e Columns collec,ion o0 da,a columns: and ,3e C3ild!ela,ions and Paren,!ela,ions collec,ions o0 da,a rela,ions1 "3e =a,a!ow class includes ,3e !ow),a,e .ro.er,/: w3ose values indica,e w3e,3er and 3ow ,3e row 3as *een c3anged since ,3e da,a ,a*le was 0irs, loaded 0rom ,3e da,a*ase1 Possi*le values 0or ,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 0irs, derived 0rom ,3e *ase DataSet class and ,3en uses in0orma,ion in an @'$ )c3ema 0ile (an 1;sd 0ile) ,o genera,e a new class1 (n0orma,ion 0rom ,3e sc3ema (,a*les: columns: and so on) is genera,ed and com.iled in,o ,3is new da,ase, class as a se, o0 0irs,-class o*+ec,s and .ro.er,ies1 Because a ,/.ed DataSet class in3eri,s 0rom ,3e *ase DataSet class: ,3e ,/.ed class assumes all o0 ,3e 0unc,ionali,/ o0 ,3e DataSet class and can *e used wi,3 me,3ods ,3a, ,a9e an ins,ance o0 a DataSet class 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 W *u, ,3ose are e;.osed onl/ as collec,ions1 (>owever: a0,er manuall/ crea,ing ,3e ,a*les and o,3er da,a elemen,s

Navgu+ara, BCA

Page 82 o0 56

Advanced Visual and Windows Programming(BCA-205) in an un,/.ed da,ase,: /ou can e;.or, ,3e da,ase,<s s,ruc,ure as a sc3ema using ,3e da,ase,<s Wri,e@ml)c3ema me,3od1) Eou can use ei,3er ,/.e o0 da,ase, in /our a..lica,ions1 >owever: Visual ),udio 3as more ,ool su..or, 0or ,/.ed da,ase,s: and ,3e/ ma9e .rogramming wi,3 ,3e da,ase, easier and less error-.rone1

Pop)+atin( Datasets
A da,ase, is a con,ainerQ ,3ere0ore: /ou need ,o 0ill i, wi,3 da,a1 W3en /ou .o.ula,e a da,ase,: various even,s are raised: cons,rain, c3ec9ing a..lies: and so on1 &or more in0orma,ion a*ou, u.da,ing a da,ase, and ,3e issues surrounding u.da,es Eou can .o.ula,e a da,ase, in a varie,/ o0 wa/s

Call ,3e Fi++ me,3od o0 a da,a ada.,er1 "3is causes ,3e ada.,er ,o e;ecu,e an )V$ s,a,emen, or s,ored .rocedure and 0ill ,3e resul,s in,o a ,a*le in ,3e da,ase,1 (0 ,3e da,ase, con,ains mul,i.le ,a*les: /ou .ro*a*l/ 3ave se.ara,e da,a ada.,ers 0or eac3 ,a*le: and mus, ,3ere0ore call eac3 ada.,er<s Fi++ me,3od se.ara,el/1 'anuall/ .o.ula,e ,a*les in ,3e da,ase, */ crea,ing Data%o4 o*+ec,s and adding ,3em ,o ,3e ,a*le<s %o4s collec,ion1 (Eou can onl/ do ,3is a, run ,imeQ /ou canno, se, ,3e %o4s collec,ion a, design ,ime1) &or more in0orma,ion: see Adding =a,a ,o a "a*le1 !ead an @'$ documen, or s,ream in,o ,3e da,ase,1 &or more in0orma,ion: see ,3e !ead@ml me,3od1

0pdatin( Datasets and Data Stores


W3en c3anges are made ,o records in ,3e da,ase,: ,3e c3anges 3ave ,o *e wri,,en *ac9 ,o ,3e da,a*ase1 "o wri,e c3anges 0rom ,3e da,ase, ,o ,3e da,a*ase: /ou call ,3e 0pdate me,3od o0 ,3e da,a ada.,er ,3a, communica,es *e,ween ,3e da,ase, and i,s corres.onding da,a source1 "3e Data%o4 class used ,o mani.ula,e individual records includes ,3e %o4State .ro.er,/: w3ose values indica,e w3e,3er and 3ow ,3e row 3as *een c3anged since ,3e da,a ,a*le was 0irs, loaded 0rom ,3e da,a*ase1 Possi*le values include De+eted: 'odified: Ne4: and 0nchan(ed1 "3e 0pdate me,3od e;amines ,3e value o0 ,3e %o4State .ro.er,/ ,o de,ermine w3ic3 records need ,o *e wri,,en ,o ,3e da,a*ase and w3a, s.eci0ic da,a*ase command (add: edi,: dele,e) s3ould *e invo9ed1

!ataReader
Eou can use ,3e A=#1N%" =a,a!eader ,o re,rieve a read-onl/: 0orward-onl/ s,ream o0 da,a 0rom a da,a*ase1 !esul,s are re,urned as ,3e Auer/ e;ecu,es: and are s,ored in ,3e ne,wor9 *u00er on ,3e clien, un,il /ou reAues, ,3em using ,3e !ead me,3od o0 ,3e Navgu+ara, BCA Page 87 o0 56

Advanced Visual and Windows Programming(BCA-205) =a,a!eader1 Using ,3e =a,a!eader can increase a..lica,ion .er0ormance *o,3 */ re,rieving da,a as soon as i, is availa*le: ra,3er ,3an wai,ing 0or ,3e en,ire resul,s o0 ,3e Auer/ ,o *e re,urned: and (*/ de0aul,) s,oring onl/ one row a, a ,ime in memor/: reducing s/s,em over3ead1 A0,er crea,ing an ins,ance o0 ,3e Command o*+ec,: /ou crea,e a =a,a!eader */ calling Command1%;ecu,e!eader ,o re,rieve rows 0rom a da,a source: as s3own in ,3e 0ollowing e;am.le1 XVisual BasicY =im m/!eader As )Al=a,a!eader F m/Command1%;ecu,e!eader() Eou use ,3e %ead me,3od o0 ,3e Data%eader o*+ec, ,o o*,ain a row 0rom ,3e resul,s o0 ,3e Auer/1 Eou can access eac3 column o0 ,3e re,urned row */ .assing ,3e name or ordinal re0erence o0 ,3e column ,o ,3e Data%eader1 >owever: 0or *es, .er0ormance: ,3e Data%eader .rovides a series o0 me,3ods ,3a, allow /ou ,o access column values in ,3eir na,ive da,a ,/.es (/etDateTi*e: /etDo)b+e: /et/)id: /etInt?9: and so on)1 &or a lis, o0 ,/.ed accessor me,3ods

.+osin( the Data%eader


Eou s3ould alwa/s call ,3e .+ose me,3od w3en /ou 3ave 0inis3ed using ,3e Data%eader o*+ec,1 (0 /our .o**and con,ains ou,.u, .arame,ers or re,urn values: ,3e/ will no, *e availa*le un,il ,3e Data%eader is closed1 No,e ,3a, w3ile a Data%eader is o.en: ,3e .onnection is in use e;clusivel/ */ ,3a, Data%eader1 Eou will no, *e a*le ,o e;ecu,e an/ commands 0or ,3e .onnection: including crea,ing ano,3er Data%eader: un,il ,3e original Data%eader is closed1

Navgu+ara, BCA

Page 88 o0 56

Advanced Visual and Windows Programming(BCA-205)

E%%O% $#ND"IN/

Types of &rrors
(n Visual Basic: errors (also called exceptions) 0all in,o one o0 ,3ree ca,egories- s/n,a; errors: run-,ime errors: and logic errors1

Synta+ &rrors
Syntax errors are ,3ose ,3a, a..ear w3ile /ou wri,e /our code1 Visual Basic c3ec9s /our code as /ou ,/.e and aler,s /ou i0 /ou ma9e a mis,a9e: suc3 as miss.elling a word or using a language elemen, im.ro.erl/1 )/n,a; errors are ,3e mos, common ,/.e o0 errors1 Eou can 0i; ,3em easil/ in ,3e coding environmen, as soon as ,3e/ occur1 Note "3e Option E-p+icit s,a,emen, is one means o0 avoiding s/n,a; errors1 (, 0orces ,3e .rogrammer ,o declare: in advance: all ,3e varia*les ,o *e used in ,3e a..lica,ion1 "3ere0ore: w3en ,3ose varia*les are used in ,3e code: an/ ,/.ogra.3ic errors are caug3, immedia,el/ and can *e 0i;ed1

Run-Time &rrors
!un"time errors are ,3ose ,3a, a..ear onl/ a0,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 o0 code ,o o.en a 0ile1 Bu, i0 ,3e 0ile is corru.,ed: ,3e a..lica,ion canno, carr/ ou, ,3e Open 0unc,ion: and i, s,o.s running1 Eou can 0i; mos, run-,ime errors */ rewri,ing ,3e 0aul,/ code: and ,3en recom.iling and rerunning i,1

Logic &rrors
Logic errors are ,3ose ,3a, a..ear once ,3e a..lica,ion is in use1 "3e/ mos, o0,en ,a9e ,3e 0orm o0 unwan,ed or une;.ec,ed resul,s in res.onse ,o user ac,ions1 &or e;am.le: a mis,/.ed 9e/ or o,3er ou,side in0luence 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 0i;: 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 Visual Basic 1N%" environmen, or as a s,and-alone e;ecu,a*le1 )ome o0 ,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 o0 56

Advanced Visual and Windows Programming(BCA-205) ,3e On Error s,a,emen, and ,3e Err o*+ec,<s N)*ber .ro.er,/1 Unused error num*ers in ,3e range 4 ,o 4000 are reserved 0or 0u,ure use */ Visual Basic1 Visual Basic com.iler errors occur w3en ,3e com.iler encoun,ers .ro*lems in ,3e code1 "3e code causing ,3e errors is mar9ed wi,3 a wav/ line undernea,3 i, in ,3e Code %di,or: and w3en /our mouse .auses over ,3e mar9ed code: ,3e error message a..ears1 "3e messages also a..ear in ,3e "as9 $is,1 Visual Basic run-,ime errors occur w3en an a..lica,ion a,,em.,s ,o .er0orm an ac,ion ,3a, ,3e s/s,em canno, e;ecu,e1 "3e errors ,3a, Visual Basic 1N%" ,3rows are Error o*+ec,s1 Visual Basic 1N%" can genera,e cus,om errors o0 an/ da,a ,/.e: including Error o*+ec,s: */ using ,3e Thro4 s,a,emen,1 A .rogram can dis.la/ ,3e error num*er and message o0 a caug3, Error ,o iden,i0/ ,3e error1 (0 an error is no, caug3,: ,3e .rogram ends1 !un-,ime errors can *e ,ra..ed and e;amined */ ,3e code1 B/ enclosing ,3e code ,3a, .roduces ,3e error in a Try *loc9: an/ ,3rown error can *e caug3, wi,3in a ma,c3ing .atch *loc91 Visual Basic su..or,s *o,3 structured and unstructured e;ce.,ion (error) 3andling1 B/ .lacing s.eci0ic code in /our a..lica,ion: /ou can 3andle mos, o0 ,3e errors users ma/ encoun,er and ena*le ,3e a..lica,ion ,o con,inue running1 ),ruc,ured and uns,ruc,ured error 3andling allow /ou ,o .lan 0or .o,en,ial errors: .reven,ing ,3em 0rom in,er0ering wi,3 ,3e in,ended .ur.ose o0 ,3e a..lica,ion1

Debugging
As youve seen, encountering errors is nearly a certainty when developing a piece of software. Syntax errors, of course, are the easiest to detect, because the IDE tells you right where they are and what the nature of the error is. Its the runtime errors that are harder to locate and correct, because of the many forms these errors can ta e. !ouve seen examples of errors that will cause your program to crash, as well as errors that spiral your program off into an infinite loop, and even errors that produce no outward signs at all"they simply cause the program to behave in some unintended way. #ortunately, $isual Studio .%E& provides you with a fine selection of tools to detect and remove the errors in your program. &he act of hunting and eliminating errors is called debugging, because youre goal is to remove the bugs 'or de(bug) the program.

Navgu+ara, BCA

Page 86 o0 56

Advanced Visual and Windows Programming(BCA-205)

Str)ct)red E-ception $and+in(


(n s,ruc,ured e;ce.,ion 3andling: *loc9s o0 code are enca.sula,ed: wi,3 eac3 *loc9 3aving one or more associa,ed 3andlers1 %ac3 3andler s.eci0ies some 0orm o0 0il,er condi,ion on ,3e ,/.e o0 e;ce.,ion i, 3andles1 W3en an e;ce.,ion is raised */ code in a .ro,ec,ed *loc9: ,3e se, o0 corres.onding 3andlers is searc3ed in order: and ,3e 0irs, one wi,3 a ma,c3ing 0il,er condi,ion is e;ecu,ed1 A single me,3od can 3ave mul,i.le s,ruc,ured e;ce.,ion 3andling *loc9s: and ,3e *loc9s can also *e nes,ed wi,3in eac3 o,3er1 "3e Try....atch...Fina++y s,a,emen, is used s.eci0icall/ 0or s,ruc,ured e;ce.,ion 3andling1 &or more in0orma,io1

0nstr)ct)red E-ception $and+in(


"3e On Error s,a,emen, is used s.eci0icall/ 0or uns,ruc,ured e;ce.,ion 3andling1 (n uns,ruc,ured e;ce.,ion 3andling: On Error is .laced a, ,3e *eginning o0 a *loc9 o0 code1 (, ,3en 3as Gsco.eG over ,3a, *loc9Q i, 3andles an/ errors occurring wi,3in ,3e *loc91 (0 ,3e .rogram encoun,ers ano,3er On Error s,a,emen,: ,3a, s,a,emen, *ecomes valid and ,3e 0irs, 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 o0 code: w3ile s,ill running code1
Try ? tryStatements @ ? Catch ? exception ? As type @ @ ? When expression @ ? 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 (0 an e;ce.,ion occurs w3ile .rocessing ,3e Try *loc9: eac3 .atch s,a,emen, is e;amined in ,e;,ual order exception #.,ional1 An/ varia*le name1 "3e ini,ial value o0 exception is ,3e value o0 ,3e ,3rown error1 Used wi,3 .atch ,o s.eci0/ ,3e error caug3,1 Navgu+ara, BCA Page 8B o0 56

Advanced Visual and Windows Programming(BCA-205) When #.,ional1 A .atch s,a,emen, wi,3 a When clause will onl/ ca,c3 e;ce.,ions w3en expression evalua,es ,o Tr)e1 A When clause is onl/ a..lied a0,er c3ec9ing ,3e ,/.e o0 ,3e e;ce.,ion: and expression ma/ re0er ,o ,3e iden,i0ier 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 0il,er1 "/.icall/ used ,o 0il,er */ error num*er1 Used wi,3 When 9e/word ,o s.eci0/ circums,ances under w3ic3 ,3e error is caug3,1 catchStatements #.,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 2e/word ,3a, *rea9s ou, o0 ,3e Try....atch...Fina++y s,ruc,ure1 %;ecu,ion resumes wi,3 ,3e Fina++y *loc9 i0 .resen,: o,3erwise wi,3 ,3e code immedia,el/ 0ollowing ,3e End Try s,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, o0 ,3e Try s,a,emen,1 #inallyStatements #.,ional1 ),a,emen,(s) ,3a, are e;ecu,ed a0,er all o,3er error .rocessing 3as occurred1 End Try "ermina,es ,3e Try....atch...Fina++y s,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 (0 an error occurs in ,3e Try *loc9: .rogram con,rol is .assed ,o ,3e a..ro.ria,e .atch s,a,emen, 0or dis.osi,ion1 "3e exception argumen, is an ins,ance o0 ,3e E-ception class or an ins,ance o0 a class ,3a, derives 0rom ,3e E-ception class corres.onding ,o ,3e error ,3a, occurred in ,3e Try *loc91 "3e E-ception class ins,ance con,ains in0orma,ion a*ou, ,3e error including: among o,3er ,3ings: i,s num*er and message1
:ri"ate S+b 7+tto,1AClicB#7.Val se, er As S.stem.Object) 7.Val e As A S.stem.<"e,tAr4s$ 2a, les 7+tto,1.ClicB im A AS i,te4er Tr. A=CSD7CAC Catc8 e( As <(ce/tio, Ms47o(#'Ca,6t assi4, "al+e stri,4 to i,te4er' $ <, Tr. <, S+b

E-a*p+e
"3e 0ollowing sim.li0ied e;am.le illus,ra,es ,3e s,ruc,ure o0 ,3e Try....atch...Fina++y s,a,emen,-

Navgu+ara, BCA

Page 8C o0 56

Advanced Visual and Windows Programming(BCA-205)


:+blic S+b Tr.<(am/le#$ Dim ( As &,te4er = 5 6 Declare "ariables. Dim . As &,te4er = 1 Try 6 Set +/ str+ct+re error 8a, li,4. ( /= . 6 Ca+se a 'Di"i e b. Eero' error. Catch e( As <(ce/tio, >8e, . = 1 6 Catc8 t8e error. Ms47o(#e(.toStri,4$ 6 S8ow 5rie, l. error messa4e. Finally 7ee/#$ 6 7ee/ a5ter error /rocessi,4. End Try <, S+b

ArrayList Collection Type


An Arra/$is, is a so.3is,ica,ed version o0 an arra/1 "3e #rray"ist class .rovides some 0ea,ures ,3a, are o00ered in mos, Collec,ions classes *u, are no, in ,3e Arra/ class1 &or e;am.le

"3e ca.aci,/ o0 an #rray is 0i;ed: w3ereas ,3e ca.aci,/ o0 an #rray"ist is au,oma,icall/ e;.anded as reAuired1 (0 ,3e value o0 ,3e #rray"ist..apacity .ro.er,/ is c3anged: ,3e memor/ realloca,ion and co./ing o0 elemen,s are au,oma,icall/ done1 #rray"ist .rovides me,3ods ,3a, add: inser,: or remove a range o0 elemen,s1 (n #rray: /ou can ge, or se, ,3e value o0 onl/ one elemen, a, a ,ime1 A s/nc3roniDed version o0 #rray"ist is eas/ ,o crea,e using ,3e Synchroni,ed me,3od1 #rray leaves i, u. ,o ,3e user ,o im.lemen, s/nc3roniDa,ion1 #rray"ist .rovides me,3ods ,3a, re,urn read-onl/ and 0i;ed-siDe wra..ers ,o ,3e collec,ion1 #rray does no,1

#n ,3e o,3er 3and: #rray o00ers some 0le;i*ili,/ ,3a, #rray"ist does no,1 &or e;am.le

Eou can se, ,3e lower *ound o0 an #rray: *u, ,3e lower *ound o0 an #rray"ist is alwa/s Dero1

Navgu+ara, BCA

Page 85 o0 56

Advanced Visual and Windows Programming(BCA-205)


An #rray can 3ave mul,i.le dimensions: w3ile an #rray"ist alwa/s 3as e;ac,l/ one dimension1 An #rray o0 a s.eci0ic ,/.e (o,3er ,3an Ob ect) 3as *e,,er .er0ormance ,3an an #rray"ist *ecause ,3e elemen,s o0 #rray"ist are o0 ,/.e Ob ect and: ,3ere0ore: *o;ing and un*o;ing ,/.icall/ occur i0 s,oring or re,rieving a value ,/.e1

'os, si,ua,ions ,3a, call 0or an arra/ can use #rray"ist ins,ead1 (, is easier ,o use and: in general: 3as .er0ormance similar ,o an arra/ o0 ,/.e Ob ect1 #rray is in ,3e Syste* names.aceQ #rray"ist is in ,3e Syste*..o++ections names.ace1

P)b+ic Properties
Ca.aci,/ Coun, Ge,s ,3e num*er o0 elemen,s ac,uall/ con,ained in ,3e #rray"ist1 (s&i;ed)iDe Ge,s a value indica,ing w3e,3er ,3e #rray"ist 3as a 0i;ed siDe1 (s!ead#nl/ Ge,s a value indica,ing w3e,3er ,3e #rray"ist is read-onl/1 (s)/nc3roniDed Ge,s a value indica,ing w3e,3er access ,o ,3e #rray"ist is s/nc3roniDed (,3read-sa0e)1 Ge,s or se,s ,3e num*er o0 elemen,s ,3a, ,3e #rray"ist can con,ain1

P)b+ic 'ethods
Ada.,er Crea,es an #rray"ist wra..er 0or a s.eci0ic ($is,1 Add Adds an o*+ec, ,o ,3e end o0 ,3e #rray"ist1 Add!ange Adds ,3e elemen,s o0 an (Collec,ion ,o ,3e end o0 ,3e #rray"ist1 Binar/)earc3 #verloaded1 Uses a *inar/ searc3 algori,3m ,o loca,e a s.eci0ic elemen, in ,3e sor,ed #rray"ist or a .or,ion o0 i,1 Clear !emoves all elemen,s 0rom ,3e #rray"ist1 Clone Crea,es a s3allow co./ o0 ,3e #rray"ist1 Con,ains =e,ermines w3e,3er an elemen, is in ,3e #rray"ist1 Co./"o #verloaded1 Co.ies ,3e #rray"ist or a .or,ion o0 i, ,o a one-dimensional arra/1 Navgu+ara, BCA Page 50 o0 56

Advanced Visual and Windows Programming(BCA-205) %Auals #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 (nser, (nser,s an elemen, in,o ,3e #rray"ist a, ,3e s.eci0ied inde;1 (nser,!ange (nser,s ,3e elemen,s o0 a collec,ion in,o ,3e #rray"ist a, ,3e s.eci0ied inde;1 !emove !emoves ,3e 0irs, occurrence o0 a s.eci0ic o*+ec, 0rom ,3e #rray"ist1 !e.ea, !e,urns an #rray"ist w3ose elemen,s are co.ies o0 ,3e s.eci0ied value1 !everse #verloaded1 !everses ,3e order o0 ,3e elemen,s in ,3e #rray"ist or a .or,ion o0 i,1

>as3,a*le Class
A $ashtab+e consis,s o0 *uc9e,s ,3a, con,ain ,3e elemen,s o0 ,3e collec,ion1 A *uc9e, is a vir,ual su*grou. o0 elemen,s wi,3in ,3e $ashtab+e: w3ic3 ma9es searc3ing and re,rieving easier and 0as,er ,3an in mos, collec,ions1 %ac3 *uc9e, is associa,ed wi,3 a 3as3 code: genera,ed using a 3as3 0unc,ion and *ased on ,3e 9e/ o0 ,3e elemen,1 A 3as3 0unc,ion is an algori,3m ,3a, re,urns a numeric 3as3 code *ased on a 9e/1 "3e 9e/ is ,3e value o0 some .ro.er,/ o0 ,3e o*+ec, *eing s,ored1 A 3as3 0unc,ion mus, alwa/s re,urn ,3e same 3as3 code 0or ,3e same 9e/1 (, is .ossi*le 0or a 3as3 0unc,ion ,o genera,e ,3e same 3as3 code 0or ,wo di00eren, 9e/s: *u, a 3as3 0unc,ion ,3a, genera,es a uniAue 3as3 code 0or eac3 uniAue 9e/ resul,s in *e,,er .er0ormance w3en re,rieving elemen,s 0rom ,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,<s 3as3 code1 W3en a value is *eing searc3ed 0or in ,3e $ashtab+e: ,3e 3as3 code is genera,ed 0or ,3a, value: and ,3e *uc9e, associa,ed wi,3 ,3a, 3as3 code is searc3ed1 P)b+ic Properties Coun, (s&i;ed)iDe (s!ead#nl/ (s)/nc3roniDed Ge,s ,3e num*er o0 9e/-and-value .airs con,ained in ,3e $ashtab+e1 Ge,s a value indica,ing w3e,3er ,3e $ashtab+e 3as a 0i;ed siDe1 Ge,s a value indica,ing w3e,3er ,3e $ashtab+e is read-onl/1 Ge,s a value indica,ing w3e,3er access ,o ,3e $ashtab+e is s/nc3roniDed (,3read-sa0e)1

Navgu+ara, BCA

Page 54 o0 56

Advanced Visual and Windows Programming(BCA-205)

(,em

Ge,s or se,s ,3e value associa,ed wi,3 ,3e s.eci0ied 9e/1 Ge,s an (Collec,ion con,aining ,3e 9e/s in ,3e $ashtab+e1 Ge,s an o*+ec, ,3a, can *e used ,o s/nc3roniDe access ,o ,3e $ashtab+e1 Ge,s an (Collec,ion con,aining ,3e values in ,3e $ashtab+e1

2e/s )/nc!oo, Values

P)b+ic 'ethods
Add Clear Clone Con,ains !emove "o),ring Adds an elemen, wi,3 ,3e s.eci0ied 9e/ and value in,o ,3e $ashtab+e1 !emoves all elemen,s 0rom ,3e $ashtab+e1 Crea,es a s3allow co./ o0 ,3e $ashtab+e1 =e,ermines w3e,3er ,3e $ashtab+e con,ains a s.eci0ic 9e/1 !emoves ,3e elemen, wi,3 ,3e s.eci0ied 9e/ 0rom ,3e $ashtab+e1 !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"ist is *ased on ,3e (=ic,ionar/ in,er0aceQ ,3ere0ore: eac3 elemen, o0 a Sorted"ist is a 9e/-and-value .air1 Sorted"ist .rovides me,3ods ,3a, re,urn onl/ ,3e lis, o0 9e/s or onl/ ,3e lis, o0 values1 As wi,3 #rray"ist: a Sorted"ist is a seAuence o0 elemen,s1 (, is inde;ed: and is sor,ed according ,o a s.eci0ied com.arer1 Sorted"ist is uniAue 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 o0 56

Advanced Visual and Windows Programming(BCA-205)

P)b+ic Properties
Ca.aci,/ Coun, (s&i;ed)iDe (s!ead#nl/ Ge,s or se,s ,3e ca.aci,/ o0 ,3e Sorted"ist1 Ge,s ,3e num*er o0 elemen,s con,ained in ,3e Sorted"ist1 Ge,s a value indica,ing w3e,3er ,3e Sorted"ist 3as a 0i;ed siDe1 Ge,s a value indica,ing w3e,3er ,3e Sorted"ist is read-onl/1 Ge,s a value indica,ing w3e,3er access ,o ,3e Sorted"ist is s/nc3roniDed (,3readsa0e)1 Ge,s and se,s ,3e value associa,ed wi,3 a s.eci0ic 9e/ in ,3e Sorted"ist1 Ge,s ,3e 9e/s in ,3e Sorted"ist1 Ge,s an o*+ec, ,3a, can *e used ,o s/nc3roniDe access ,o ,3e Sorted"ist1 Ge,s ,3e values in ,3e Sorted"ist1

(s)/nc3roniDed

(,em 2e/s )/nc!oo, Values

P)b+ic 'ethods
Add Clear Clone Con,ains Adds an elemen, wi,3 ,3e s.eci0ied 9e/ and value ,o ,3e Sorted"ist1 !emoves all elemen,s 0rom ,3e Sorted"ist1 Crea,es a s3allow co./ o0 ,3e Sorted"ist1 =e,ermines w3e,3er ,3e Sorted"ist con,ains a s.eci0ic 9e/1

Seriali-ation.inder Class
Allows users ,o con,rol class loading and manda,e w3a, class ,o load1

P)b+ic 'ethods
Bind"o"/.e W3en overridden in a derived class: con,rols ,3e *inding o0 a serialiDed o*+ec, ,o a ,/.e1

Navgu+ara, BCA

Page 57 o0 56

Advanced Visual and Windows Programming(BCA-205) #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 )erves as a 3as3 0unc,ion 0or a .ar,icular Ge,>as3Code (in3eri,ed 0rom Ob ect) ,/.e: sui,a*le 0or use in 3as3ing algori,3ms and da,a s,ruc,ures li9e a 3as3 ,a*le1 Ge,s ,3e "/.e o0 ,3e curren, ins,ance1 Ge,"/.e (in3eri,ed 0rom Ob ect) !e,urns a ),ring ,3a, re.resen,s ,3e curren, "o),ring (in3eri,ed 0rom Ob ect) #*+ec,1 %Auals (in3eri,ed 0rom Ob ect)

serialization and deserialization


&he last step is the seriali*ation and deseriali*ation of the items on the +ist,ox control. Seriali*ation is the process of storing the ob-ect to a dis file, and deseriali*ation is the opposite process. &o seriali*e ob-ects, we first store them into an Array+ist ob-ect. &he Array+ist ob-ect is a dynamic array that stores ob-ects. it can be seriali*ed as a whole. +i ewise, the dis file is deseriali*ed as an Array+ist. then each element of the Array+ist is moved to the Items collection of the +ist,ox control. &he Array+ist ob-ect is discussed in detail in /hapter 00, along with the techni1ues for seriali*ing and deseriali*ing its elements.

.har c+ass
.har varia*les are s,ored as unsigned 46-*i, (2-*/,e) num*ers ranging in value 0rom 0 ,3roug3 655751 %ac3 num*er re.resen,s a single Unicode c3arac,er1 =irec, conversions *e,ween ,3e .har da,a ,/.e and ,3e numeric ,/.es are no, .ossi*le: *u, /ou can use ,3e #scW and .hrW 0unc,ions 0or ,3is .ur.ose1

)ublic ,ields
'a;Value 'inValue !e.resen,s ,3e larges, .ossi*le value o0 a .har1 "3is 0ield is cons,an,1 !e.resen,s ,3e smalles, .ossi*le value o0 a .har1 "3is 0ield is cons,an,1

P)b+ic 'ethods
Com.are"o Com.ares ,3is ins,ance ,o a s.eci0ied o*+ec, and re,urns an indica,ion o0 ,3eir rela,ive values1

Navgu+ara, BCA

Page 58 o0 56

Advanced Visual and Windows Programming(BCA-205) #verridden1 !e,urns a value indica,ing w3e,3er ,3is ins,ance is eAual ,o a s.eci0ied o*+ec,1 #verloaded1 (ndica,es w3e,3er a Unicode c3arac,er is ca,egoriDed as a decimal digi,1 #verloaded1 (ndica,es w3e,3er a Unicode c3arac,er is ca,egoriDed as an al.3a*e,ic le,,er1

%Auals (s=igi, (s$e,,er

Strin( .+ass
!e.resen,s ,e;,Q ,3a, is: a series o0 Unicode c3arac,ers1

P)b+ic Properties
C3ars $eng,3 Ge,s ,3e c3arac,er a, a s.eci0ied c3arac,er .osi,ion in ,3is ins,ance1 Ge,s ,3e num*er o0 c3arac,ers in ,3is ins,ance1

P)b+ic 'ethods
Clone are !e,urns a re0erence ,o ,3is ins,ance o0 Strin(1

Com. #verloaded1 Com.ares ,wo s.eci0ied Strin( o*+ec,s1

Com. #verloaded1 Com.ares ,wo Strin( o*+ec,s */ evalua,ing ,3e numeric are#rdinal values o0 ,3e corres.onding C3ar o*+ec,s in eac3 s,ring1 Com.are"o #verloaded1 Com.ares ,3is ins,ance wi,3 a s.eci0ied o*+ec,1 , Conca #verloaded1 Conca,ena,es one or more ins,ances o0 Strin(: or ,3e Strin( re.resen,a,ions o0 ,3e values o0 one or more ins,ances o0 #*+ec,1 Co./ Crea,es a new ins,ance o0 Strin( wi,3 ,3e same value as a s.eci0ied Strin(1 Co./"o Co.ies a s.eci0ied num*er o0 c3arac,ers 0rom a s.eci0ied .osi,ion in ,3is ins,ance ,o a s.eci0ied .osi,ion in an arra/ o0 Unicode c3arac,ers1

Navgu+ara, BCA

Page 55 o0 56

Advanced Visual and Windows Programming(BCA-205)

%ndsWi,3 =e,ermines w3e,3er ,3e end o0 ,3is ins,ance ma,c3es ,3e s.eci0ied Strin(1 %Auals #verloaded1 #verridden1 =e,ermines w3e,3er ,wo Strin( o*+ec,s 3ave ,3e same value1

, a,or

&orma #verloaded1 !e.laces eac3 0orma, i,em in a s.eci0ied Strin( wi,3 ,3e ,e;, eAuivalen, o0 a corres.onding o*+ec,<s value1 Ge,%numer !e,rieves an o*+ec, ,3a, can i,era,e ,3roug3 ,3e individual c3arac,ers in ,3is ins,ance1 (nde;#0 #verloaded1 !e.or,s ,3e inde; o0 ,3e 0irs, occurrence o0 a Strin(: or one or more c3arac,ers: wi,3in ,3is ins,ance1

(nde;#0An #verloaded1 !e.or,s ,3e inde; o0 ,3e 0irs, occurrence in ,3is ins,ance o0 an/ c3arac,er in a s.eci0ied arra/ o0 Unicode c3arac,ers1 (nser, (nser,s a s.eci0ied ins,ance o0 Strin( a, a s.eci0ied inde; .osi,ion in ,3is ins,ance1

(n,ern !e,rieves ,3e s/s,em<s re0erence ,o ,3e s.eci0ied Strin(1 ned (s(n,er !e,rieves a re0erence ,o a s.eci0ied Strin(1 oin #verloaded1 Conca,ena,es a s.eci0ied se.ara,or Strin( *e,ween eac3 elemen, o0 a s.eci0ied Strin( arra/: /ielding a single conca,ena,ed s,ring1

$as,(nde;# #verloaded1 !e.or,s ,3e inde; .osi,ion o0 ,3e las, occurrence o0 a s.eci0ied Unicode c3arac,er or Strin( wi,3in ,3is ins,ance1

$as,(nde;# #verloaded1 !e.or,s ,3e inde; .osi,ion o0 ,3e las, occurrence in ,3is 0An/ ins,ance o0 one or more c3arac,ers s.eci0ied in a Unicode arra/1 #verloaded1 !ig3,-aligns ,3e c3arac,ers in ,3is ins,ance: .adding on ,3e Pad$e0, le0, wi,3 s.aces or a s.eci0ied Unicode c3arac,er 0or a s.eci0ied ,o,al leng,31 #verloaded1 $e0,-aligns ,3e c3arac,ers in ,3is s,ring: .adding on ,3e Pad!ig3, rig3, wi,3 s.aces or a s.eci0ied Unicode c3arac,er: 0or a s.eci0ied ,o,al leng,31 =ele,es a s.eci0ied num*er o0 c3arac,ers 0rom ,3is ins,ance *eginning a, !emove a s.eci0ied .osi,ion1

Navgu+ara, BCA

Page 56 o0 56

Advanced Visual and Windows Programming(BCA-205)

!e.lace

#verloaded1 !e.laces all occurrences o0 a s.eci0ied Unicode c3arac,er or Strin( in ,3is ins,ance: wi,3 ano,3er s.eci0ied Unicode c3arac,er or Strin(1 #verloaded1 (den,i0ies ,3e su*s,rings in ,3is ins,ance ,3a, are delimi,ed ).li, */ one or more c3arac,ers s.eci0ied in an arra/: ,3en .laces ,3e su*s,rings in,o a Strin( arra/1 =e,ermines w3e,3er ,3e *eginning o0 ,3is ins,ance ma,c3es ,3e s.eci0ied ),ar,sWi,3 Strin(1 #verloaded1 !e,rieves a su*s,ring 0rom ,3is ins,ance1 )u*s,ring #verloaded1 Co.ies ,3e c3arac,ers in ,3is ins,ance ,o a Unicode "oC3arArr c3arac,er arra/1

a/

"o$ower "o),ring "oU..er "rim

#verloaded1 !e,urns a co./ o0 ,3is Strin( in lowercase1 #verloaded1 #verridden1 Conver,s ,3e value o0 ,3is ins,ance ,o a Strin(1 #verloaded1 !e,urns a co./ o0 ,3is Strin( in u..ercase1 #verloaded1 !emoves all occurrences o0 a se, o0 s.eci0ied c3arac,ers 0rom ,3e *eginning and end o0 ,3is ins,ance1

String.uilder Class
"3e Strin( o*+ec, is immu,a*le1 %ver/ ,ime /ou use one o0 ,3e me,3ods in ,3e Syste*.Strin( class: /ou crea,e a new s,ring o*+ec, in memor/: w3ic3 reAuires a new alloca,ion o0 s.ace 0or ,3a, new o*+ec,1 (n si,ua,ions w3ere /ou need ,o .er0orm re.ea,ed modi0ica,ions ,o a s,ring: ,3e over3ead associa,ed wi,3 crea,ing a new Strin( o*+ec, can *e cos,l/1 "3e )/s,em1"e;,1),ringBuilder class can *e used w3en /ou wan, ,o modi0/ a s,ring wi,3ou, crea,ing a new o*+ec,1 &or e;am.le: using ,3e Strin(B)i+der class can *oos, .er0ormance w3en conca,ena,ing man/ s,rings ,oge,3er in a loo.1

P)b+ic Properties
Ca.aci,/ C3ars $eng,3 Ge,s or se,s ,3e ma;imum num*er o0 c3arac,ers ,3a, can *e con,ained in ,3e memor/ alloca,ed */ ,3e curren, ins,ance1 Ge,s or se,s ,3e c3arac,er a, ,3e s.eci0ied c3arac,er .osi,ion in ,3is ins,ance1 Ge,s or se,s ,3e leng,3 o0 ,3is ins,ance1

Navgu+ara, BCA

Page 5B o0 56

Advanced Visual and Windows Programming(BCA-205) Ge,s ,3e ma;imum ca.aci,/ o0 ,3is ins,ance1

'a;Ca.aci,/

P)b+ic 'ethods
A..end (nser, !emove !e.lace "o),ring #verloaded1 A..ends ,3e s,ring re.resen,a,ion o0 a s.eci0ied o*+ec, ,o ,3e end o0 ,3is ins,ance1 #verloaded1 (nser,s ,3e s,ring re.resen,a,ion o0 a s.eci0ied o*+ec, in,o ,3is ins,ance a, a s.eci0ied c3arac,er .osi,ion1 !emoves ,3e s.eci0ied range o0 c3arac,ers 0rom ,3is ins,ance1 #verloaded1 !e.laces all occurrences o0 a s.eci0ied c3arac,er or s,ring in ,3is ins,ance wi,3 ano,3er s.eci0ied c3arac,er or s,ring1 #verloaded1 #verridden1 Conver,s a Strin(B)i+der ,o a ),ring1

!ateTime Structure
!e.resen,s an ins,an, in ,ime: ,/.icall/ e;.ressed as a da,e and ,ime o0 da/1

P)b+ic Properties
=a,e Ge,s ,3e da,e com.onen, o0 ,3is ins,ance1

=a/#0Wee9 =a/#0Eear >our 'illisecond 'inu,e 'on,3 Now )econd "ic9s

Ge,s ,3e da/ o0 ,3e wee9 re.resen,ed */ ,3is ins,ance1 Ge,s ,3e da/ o0 ,3e /ear re.resen,ed */ ,3is ins,ance1 Ge,s ,3e 3our com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1 Ge,s ,3e milliseconds com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1 Ge,s ,3e minu,e com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1 Ge,s ,3e mon,3 com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1 Ge,s a DateTi*e ,3a, is ,3e curren, local da,e and ,ime on ,3is com.u,er1 Ge,s ,3e seconds com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1 Ge,s ,3e num*er o0 ,ic9s ,3a, re.resen, ,3e da,e and ,ime o0 ,3is ins,ance1

Navgu+ara, BCA

Page 5C o0 56

Advanced Visual and Windows Programming(BCA-205) Ge,s ,3e ,ime o0 da/ 0or ,3is ins,ance1 Ge,s ,3e curren, da,e1 Ge,s a DateTi*e ,3a, is ,3e curren, local da,e and ,ime on ,3is com.u,er e;.ressed as ,3e coordina,ed universal ,ime (U"C)1 Ge,s ,3e /ear com.onen, o0 ,3e da,e re.resen,ed */ ,3is ins,ance1

"ime#0=a/ "oda/ U,cNow Eear

P)b+ic 'ethods
Add Add=a/s Add>ours Add'illiseconds Add'inu,es Add'on,3s Add)econds Add"ic9s AddEears Com.are Com.are"o =a/s(n'on,3 %Auals (s$ea.Eear )u*,rac, Adds ,3e value o0 ,3e s.eci0ied "ime).an ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 da/s ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 3ours ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 milliseconds ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 minu,es ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 mon,3s ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 seconds ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 ,ic9s ,o ,3e value o0 ,3is ins,ance1 Adds ,3e s.eci0ied num*er o0 /ears ,o ,3e value o0 ,3is ins,ance1 Com.ares ,wo ins,ances o0 DateTi*e and re,urns an indica,ion o0 ,3eir rela,ive values1 Com.ares ,3is ins,ance ,o a s.eci0ied o*+ec, and re,urns an indica,ion o0 ,3eir rela,ive values1 !e,urns ,3e num*er o0 da/s in ,3e s.eci0ied mon,3 o0 ,3e s.eci0ied /ear1 #verloaded1 #verridden1 !e,urns a value indica,ing w3e,3er an ins,ance o0 DateTi*e is eAual ,o a s.eci0ied o*+ec,1 !e,urns an indica,ion w3e,3er ,3e s.eci0ied /ear is a lea. /ear1 #verloaded1 )u*,rac,s ,3e s.eci0ied ,ime or dura,ion 0rom ,3is ins,ance1

Navgu+ara, BCA

Page 55 o0 56

Advanced Visual and Windows Programming(BCA-205) Conver,s ,3e value o0 ,3is ins,ance ,o ,3e 0orma, o0 a local o.era,ing s/s,em 0ile ,ime1 #verloaded1 #verridden1 Conver,s ,3e value o0 ,3is ins,ance ,o i,s eAuivalen, s,ring re.resen,a,ion1

"o&ile"ime "o),ring

TimeSpan Structure
!e.resen,s a ,ime in,erval1

P)b+ic Properties
=a/s >ours 'illiseconds 'inu,es )econds Ge,s ,3e num*er o0 w3ole da/s re.resen,ed */ ,3is ins,ance1 Ge,s ,3e num*er o0 w3ole 3ours re.resen,ed */ ,3is ins,ance1 Ge,s ,3e num*er o0 w3ole milliseconds re.resen,ed */ ,3is ins,ance1 Ge,s ,3e num*er o0 w3ole minu,es re.resen,ed */ ,3is ins,ance1 Ge,s ,3e num*er o0 w3ole seconds re.resen,ed */ ,3is ins,ance1

P)b+ic 'ethods
Add Com.are &ramewor91 =ura,ion %Auals Adds ,3e s.eci0ied Ti*eSpan ,o ,3is ins,ance1 Com.ares ,wo Ti*eSpan values and re,urns an in,eger ,3a, indica,es ,3eir rela,ions3i.1 !e,urns a Ti*eSpan w3ose value is ,3e a*solu,e value o0 ,3is ins,ance1 #verloaded1 #verridden1 !e,urns a value indica,ing w3e,3er ,wo ins,ances o0 Ti*eSpan are eAual1

&rom=a/s !e,urns a Ti*eSpan ,3a, re.resen,s a s.eci0ied num*er o0 da/s: w3ere ,3e s.eci0ica,ion is accura,e ,o ,3e neares, millisecond1

Navgu+ara, BCA

Page 60 o0 56

Advanced Visual and Windows Programming(BCA-205)

!irectory Class
%;.oses s,a,ic me,3ods 0or crea,ing: moving: and enumera,ing ,3roug3 direc,ories and su*direc,ories1

P)b+ic 'ethods
Crea,e=irec,or/ =ele,e %;is,s Ge,Crea,ion"ime Ge,Crea,ion"imeU,c Crea,es all direc,ories and su*direc,ories as s.eci0ied */ path1 #verloaded1 =ele,es a direc,or/ and i,s con,en,s1 =e,ermines w3e,3er ,3e given .a,3 re0ers ,o an e;is,ing direc,or/ on dis91 Ge,s ,3e crea,ion da,e and ,ime o0 a direc,or/1 Ge,s ,3e crea,ion da,e and ,ime: in coordina,ed universal ,ime (U"C) 0orma,: o0 a direc,or/1 Ge,s ,3e curren, wor9ing direc,or/ o0 ,3e a..lica,ion1 #verloaded1 Ge,s ,3e names o0 su*direc,ories in ,3e s.eci0ied direc,or/1 !e,urns ,3e volume in0orma,ion: roo, in0orma,ion: or *o,3 0or ,3e s.eci0ied .a,31 #verloaded1 !e,urns ,3e names o0 0iles in ,3e s.eci0ied direc,or/1

Ge,Curren,=irec,or/ Ge,=irec,ories Ge,=irec,or/!oo, Ge,&iles

,ile Class
Provides s,a,ic me,3ods 0or ,3e crea,ion: co./ing: dele,ion: moving: and o.ening o0 0iles: and aids in ,3e crea,ion o0 &ile),ream o*+ec,s1

P)b+ic 'ethods
A..end"e;, Co./ Crea,e Crea,es a ),reamWri,er ,3a, a..ends U"&-C encoded ,e;, ,o an e;is,ing 0ile1 #verloaded1 Co.ies an e;is,ing 0ile ,o a new 0ile1 #verloaded1 Crea,es a 0ile in ,3e s.eci0ied .a,31

Navgu+ara, BCA

Page 64 o0 56

Advanced Visual and Windows Programming(BCA-205) Crea,es or o.ens a 0ile 0or wri,ing U"&-C encoded ,e;,1 =ele,es ,3e s.eci0ied 0ile1 An e;ce.,ion is no, ,3rown i0 ,3e s.eci0ied 0ile does no, e;is,1 =e,ermines w3e,3er ,3e s.eci0ied 0ile e;is,s1 #verloaded1 #.ens a &ile),ream on ,3e s.eci0ied .a,31 #.ens an e;is,ing 0ile 0or reading1 #.ens an e;is,ing U"&-C encoded ,e;, 0ile 0or reading1 #.ens an e;is,ing 0ile 0or wri,ing1

Crea,e"e;, =ele,e %;is,s #.en #.en!ead #.en"e;, #.enWri,e

DirectoryInfo .+ass
%;.oses ins,ance me,3ods 0or crea,ing: moving: and enumera,ing ,3roug3 direc,ories and su*direc,ories1

P)b+ic Properties
A,,ri*u,es Ge,s or se,s ,3e &ileA,,ri*u,es o0 ,3e curren, &ile)/s,em(n0o1 Ge,s or se,s ,3e crea,ion ,ime o0 ,3e curren, &ile)/s,em(n0o o*+ec,1 Ge,s or se,s ,3e crea,ion ,ime: in coordina,ed universal ,ime (U"C): o0 ,3e curren, &ile)/s,em(n0o o*+ec,1 #verridden1 Ge,s a value indica,ing w3e,3er ,3e direc,or/ e;is,s1 Ge,s ,3e s,ring re.resen,ing ,3e e;,ension .ar, o0 ,3e 0ile1 Ge,s ,3e 0ull .a,3 o0 ,3e direc,or/ or 0ile1

Crea,ion"imeU,c %;is,s %;,ension &ullName

P)b+ic 'ethods
Crea,e Crea,e#*+!e0 Crea,es a direc,or/1 Crea,es an o*+ec, ,3a, con,ains all ,3e relevan, in0orma,ion reAuired ,o genera,e a .ro;/ used ,o communica,e wi,3 a remo,e

Navgu+ara, BCA

Page 62 o0 56

Advanced Visual and Windows Programming(BCA-205) o*+ec,1 Crea,es a su*direc,or/ or su*direc,ories on ,3e s.eci0ied .a,31 "3e s.eci0ied .a,3 can *e rela,ive ,o ,3is ins,ance o0 ,3e DirectoryInfo class1 #verloaded1 #verridden1 =ele,es a DirectoryInfo and i,s con,en,s 0rom a .a,31 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 #verloaded1 !e,urns ,3e su*direc,ories o0 ,3e curren, direc,or/1 #verloaded1 !e,urns a 0ile lis, 0rom ,3e curren, direc,or/1

Crea,e)u*direc,or/

=ele,e

Ge,=irec,ories Ge,&iles

,ileInfo Class
Provides ins,ance me,3ods 0or ,3e crea,ion: co./ing: dele,ion: moving: and o.ening o0 0iles: and aids in ,3e crea,ion o0 &ile),ream o*+ec,s1

P)b+ic Properties
A,,ri*u,es Crea,ion"ime Crea,ion"imeU,c =irec,or/ =irec,or/Name Ge,s or se,s ,3e &ileA,,ri*u,es o0 ,3e curren, &ile)/s,em(n0o1 Ge,s or se,s ,3e crea,ion ,ime o0 ,3e curren, &ile)/s,em(n0o o*+ec,1 Ge,s or se,s ,3e crea,ion ,ime: in coordina,ed universal ,ime (U"C): o0 ,3e curren, &ile)/s,em(n0o o*+ec,1 Ge,s an ins,ance o0 ,3e .aren, direc,or/1 Ge,s a s,ring re.resen,ing ,3e direc,or/<s 0ull .a,31

P)b+ic 'ethods
A..end"e;, Co./"o Crea,e Crea,e#*+!e0 Crea,es a ),reamWri,er ,3a, a..ends ,e;, ,o ,3e 0ile re.resen,ed */ ,3is ins,ance o0 ,3e Fi+eInfo1 #verloaded1 Co.ies an e;is,ing 0ile ,o a new 0ile1 Crea,es a 0ile1 Crea,es an o*+ec, ,3a, con,ains all ,3e relevan, in0orma,ion reAuired ,o genera,e a .ro;/ used ,o communica,e wi,3 a remo,e

Navgu+ara, BCA

Page 67 o0 56

Advanced Visual and Windows Programming(BCA-205) o*+ec,1 Crea,es a ),reamWri,er ,3a, wri,es a new ,e;, 0ile1 #verridden1 Permanen,l/ dele,es a 0ile1 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 )erves as a 3as3 0unc,ion 0or a .ar,icular ,/.e: sui,a*le 0or use in 3as3ing algori,3ms and da,a s,ruc,ures li9e a 3as3 ,a*le1 #verloaded1 #.ens a 0ile wi,3 various readLwri,e and s3aring .rivileges1 Crea,es a read-onl/ &ile),ream1

Crea,e"e;, =ele,e %Auals Ge,>as3Code #.en #.en!ead

)at" Class
Per0orms o.era,ions on ),ring ins,ances ,3a, con,ain 0ile or direc,or/ .a,3 in0orma,ion1 "3ese o.era,ions are .er0ormed in a cross-.la,0orm manner1

P)b+ic Fie+ds
Pa,3)e.ara,or A .la,0orm-s.eci0ic se.ara,or c3arac,er used ,o se.ara,e .a,3 s,rings in environmen, varia*les1

P)b+ic 'ethods
C3ange%;,ension Com*ine Ge,=irec,or/Name Ge,%;,ension Ge,&ileName C3anges ,3e e;,ension o0 a .a,3 s,ring1 Com*ines ,wo .a,3 s,rings1 !e,urns ,3e direc,or/ in0orma,ion 0or ,3e s.eci0ied .a,3 s,ring1 !e,urns ,3e e;,ension o0 ,3e s.eci0ied .a,3 s,ring1 !e,urns ,3e 0ile name and e;,ension o0 ,3e s.eci0ied .a,3 s,ring1

Stream/riter Class
(m.lemen,s a "e;,Wri,er 0or wri,ing c3arac,ers ,o a s,ream in a .ar,icular encoding1 &or a lis, o0 all mem*ers o0 ,3is ,/.e

Navgu+ara, BCA

Page 68 o0 56

Advanced Visual and Windows Programming(BCA-205) 'e,3odsClose %Auals &lus3 #verridden1 Closes ,3e curren, Strea*Writer and ,3e underl/ing s,ream1 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 #verridden1 Clears all *u00ers 0or ,3e curren, wri,er and causes an/ *u00ered da,a ,o *e wri,,en ,o ,3e underl/ing s,ream1 )erves as a 3as3 0unc,ion 0or a .ar,icular ,/.e: sui,a*le 0or use in 3as3ing algori,3ms and da,a s,ruc,ures li9e a 3as3 ,a*le1 #verloaded1 #verridden1 Wri,es ,o ,3e s,ream1

Ge,>as3Code

Wri,e

StreamReader Class
(m.lemen,s a "e;,!eader ,3a, reads c3arac,ers 0rom a */,e s,ream in a .ar,icular encoding1 Close %Auals (ni,ialiDe$i0e,ime)ervice Pee9 !ead !eadBloc9 !ead$ine !ead"o%nd #verridden1 Closes ,3e Strea*%eader and ,3e underl/ing s,ream and releases an/ s/s,em resources associa,ed wi,3 ,3e reader1 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 #*,ains a li0e,ime service o*+ec, ,o con,rol ,3e li0e,ime .olic/ 0or ,3is ins,ance1 #verridden1 !e,urns ,3e ne;, availa*le c3arac,er *u, does no, consume i,1 #verloaded1 #verridden1 !eads ,3e ne;, c3arac,er or ne;, se, o0 c3arac,ers 0rom ,3e in.u, s,ream1 !eads a ma;imum o0 coun, c3arac,ers 0rom ,3e curren, s,ream and wri,es ,3e da,a ,o $u##er: *eginning a, index1 #verridden1 !eads a line o0 c3arac,ers 0rom ,3e curren, s,ream and re,urns ,3e da,a as a s,ring1 #verridden1 !eads ,3e s,ream 0rom ,3e curren,

Navgu+ara, BCA

Page 65 o0 56

Advanced Visual and Windows Programming(BCA-205)

.inaryReader Class
!eads .rimi,ive da,a ,/.es as *inar/ values in a s.eci0ic encoding1

P)b+ic 'ethods
Close %Auals Ge,>as3Code Closes ,3e curren, reader and ,3e underl/ing s,ream1 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 )erves as a 3as3 0unc,ion 0or a .ar,icular ,/.e: sui,a*le 0or use in 3as3ing algori,3ms and da,a s,ruc,ures li9e a 3as3 ,a*le1 !e,urns ,3e ne;, availa*le c3arac,er and does no, advance ,3e */,e or c3arac,er .osi,ion1 #verloaded1 !eads c3arac,ers 0rom ,3e underl/ing s,ream and advances ,3e curren,

Pee9C3ar !ead

.inary/riter Class
Wri,es .rimi,ive ,/.es in *inar/ ,o a s,ream and su..or,s wri,ing s,rings in a s.eci0ic encoding1

P)b+ic 'ethods
Close %Auals !eadB/,es !eadC3ar Closes ,3e curren, reader and ,3e underl/ing s,ream1 #verloaded1 =e,ermines w3e,3er ,wo #*+ec, ins,ances are eAual1 !eads count */,es 0rom ,3e curren, s,ream in,o a */,e arra/ and advances ,3e curren, .osi,ion */ count */,es1 !eads ,3e ne;, c3arac,er 0rom ,3e curren, s,ream and advances ,3e curren, .osi,ion o0 ,3e s,ream in accordance wi,3 ,3e Encodin( used and ,3e s.eci0ic c3arac,er *eing read 0rom ,3e s,ream1

Navgu+ara, BCA

Page 66 o0 56

Advanced Visual and Windows Programming(BCA-205)

@0ESTION=#NSWE%
8 What are ob ects and properties? $o4 are they re+ated to each other?
Ans- An o*+ec, is a com*ina,ion o0 code and da,a ,3a, can *e ,rea,ed as a uni,1 An o*+ec, can *e a .iece o0 an a..lica,ion: li9e a con,rol or a 0orm1 An en,ire a..lica,ion can also *e an o*+ec,1 #*+ec,s le, /ou declare varia*les and .rocedures once and ,3en reuse ,3em w3enever needed1 &or e;am.le: i0 /ou wan, ,o add a s.ell c3ec9er ,o an a..lica,ion /ou could de0ine all ,3e varia*les and su..or, 0unc,ions ,o .rovide s.elling c3ec9 0unc,ionali,/ ,o /our a..lica,ion1 >owever: i0 /ou crea,e /our s.ell c3ec9er as a class: /ou can reuse i, in o,3er a..lica,ions */ adding a re0erence ,o ,3e com.iled assem*l/1 Be,,er /e,: /ou ma/ *e a*le ,o save /oursel0 some wor9 */ using a s.ell c3ec9er class ,3a, someone else 3as alread/ develo.ed1 Pro.er,ies re.resen, in0orma,ion s,ored in an o*+ec,1 "3e values .ro.er,ies are re,rieved and se, wi,3 assignmen, s,a,emen,s ,3e same wa/ ,3a, varia*les are re,rieved and se,1 #*+ec,s are crea,ed as iden,ical co.ies o0 ,3eir class1 #nce ,3e/ e;is, as individual o*+ec,s: 3owever: ,3eir .ro.er,ies can *e c3anged1 &or e;am.le: i0 /ou add ,3ree c3ec9 *o;es ,o a 0orm: eac3 c3ec9 *o; *u,,on o*+ec, is an ins,ance o0 ,3e .hec<Bo- class1 "3e individual .hec<Boo*+ec,s s3are a common se, o0 c3arac,eris,ics and ca.a*ili,ies (.ro.er,ies: 0ields: me,3ods:

Navgu+ara, BCA

Page 6B o0 56

Advanced Visual and Windows Programming(BCA-205) and even,s): de0ined */ ,3e class1 >owever: eac3 3as i,s own name: can *e se.ara,el/ ena*led and disa*led: can *e .laced in a di00eren, loca,ion on ,3e 0orm "3e 0ollowing e;am.le se,s and re,rieves ,3e value o0 a .ro.er,/1 =im @ As (n,eger F C =im #*+4 As New Class4 < =eclares an ins,ance o0 a class1 #*+41Pro.4 F @ < Pro.er,/ assignmen,1 Assigns ,3e num*er C ,o Pro.41 @ F #*+41Pro.4 I 4 < !e,rieval1 "3e varia*le @ con,ains ,3e num*er 51

9 E-p+ain the difference bet4een By%ef and ByVa+ . When 4o)+d each be )sed?
Ans- "3e By%ef 9e/word indica,es ,3a, an argumen, is .assed in suc3 a wa/ ,3a, ,3e called .rocedure can c3ange ,3e value o0 a varia*le underl/ing ,3e argumen, in ,3e calling code1 W3ile : "3e ByVa+ 9e/word indica,es ,3a, an argumen, is .assed in suc3 a wa/ ,3a, ,3e called .rocedure or .ro.er,/ canno, c3ange ,3e value o0 a varia*le underl/ing ,3e argumen, in ,3e calling code1 "3e By%ef 9e/word is used in: =eclare ),a,emen,: &unc,ion ),a,emen,: )u* ),a,emen, "3e ByVa+ 9e/word is used in: =eclare ),a,emen,: &unc,ion ),a,emen,: Pro.er,/ ),a,emen,: )u* ),a,emen,

What is the p)rpose of a c+ass?

Ans- - "3e classes ,3a, /ou 3ave wor9ed wi,3 u. un,il now 3ave genera,ed visual o*+ec,s suc3a as a ,e;, *o;es and la*els1"3ese were easil/ crea,ed 0rom ,3e ,ool*o; a, design ,ime1Eou can also crea,e o*+ec,s a, run,ime1#ne %;am.le a class ,3a, /ou would ins,an,ia,e a, run,ime is ,3e 0on, class 1

O=A

What are property proced)res and 4hat is their p)rpose?

Ans- - A Property .rocedure is a series o0 Visual Basic s,a,emen,s ,3a, mani.ula,e a cus,om .ro.er,/ on a module: class: or s,ruc,ure1 Pro.er,/ .rocedures are also 9nown as property accessors1 A .ro.er,/ di00ers 0rom a .u*lic varia*le or a 0ield in ,3e 0ollowing res.ec,sEou im.lemen, a .ro.er,/ wi,3 e;ecu,a*le code (i,s Property .rocedures): ra,3er ,3an wi,3 a single declara,ion s,a,emen,1 Property .rocedures are e;ecu,ed w3en ,3e .ro.er,/ value is se, or re,rieved1 "3is allows a class ,o .er0orm cus,om ac,ions w3en clien, code accesses ,3e .ro.er,/1

Navgu+ara, BCA

Page 6C o0 56

Advanced Visual and Windows Programming(BCA-205) A .ro.er,/ does no, 3ave an/ s,orage loca,ion associa,ed wi,3 i,s declara,ion1 Al,3oug3 i,s Property .rocedures o0,en de0ine local varia*les and cons,an,s: ,3ese are usuall/ no, availa*le ,o ,3e code accessing ,3e .ro.er,/1 "3ere0ore: w3ile /ou can include a varia*le or a 0ield as a mem*er o0 a s,ruc,ure or arra/: /ou canno, do ,3is wi,3 a .ro.er,/1 Eou can de0ine a .ro.er,/ as read-onl/: wri,e-onl/: or readLwri,e1 "3e de0aul, is readLwri,e1 Visual Basic .rovides ,3e 0ollowing Property .rocedures /et .rocedures re,urn ,3e value o0 a .ro.er,/Q ,3e/ are called w3en ,3e .ro.er,/ is accessed in an e;.ression1 Set .rocedures se, a .ro.er,/ ,o a value: including an o*+ec, re0erenceQ ,3e/ are called w3en a value is assigned ,o ,3e .ro.er,/1

Eou usuall/ de0ine Property .rocedures in .airs: using ,3e /et and Set 9e/words: *u, /ou can de0ine ei,3er .rocedure alone i0 ,3e .ro.er,/ is read-onl/ (/et) or wri,e-onl/ (Set)1 Pro.er,/ =eclara,ion A .ro.er,/ i,sel0 is de0ined */ a *loc9 o0 code enclosed wi,3in ,3e Property and End Property s,a,emen,s1 (nside ,3is *loc9: eac3 Property .rocedure a..ears as an in,ernal *loc9 enclosed wi,3in a declara,ion s,a,emen, (/et or Set) and an End s,a,emen,1 "3e s/n,a; 0or declaring a .ro.er,/ and i,s .rocedures is as 0ollowsX=e0aul,Y Xaccessi$ilityY Pro.er,/ propertynameX(argumentlist)Y As datatype Ge, < 111 !e,urn expression < expression is re,urned as .ro.er,/<s value1 %nd Ge, )e, X(B/Val ne%&alue As datatype)Y < 111 l&alue F ne%&alue < ne%&alue is ,3e new value ,o *e assigned1 %nd )e, %nd Pro.er,/ "3e accessi*ili,/ can *e Pu*lic: Pro,ec,ed: &riend: Protected Friend: or Priva,e1 Eou can de0ine .ro.er,ies in classes: s,ruc,ures: and modules1 Pro.er,ies are P)b+ic */ de0aul,: w3ic3 means /ou can call ,3em 0rom an/w3ere in /our a..lica,ion1

What steps are needed to assi(n property va+)es to an ob ect?

Ans- - "# assign .ro.er,/ a, design ,ime we can se, ,3roug3 .ro.er,/ window or we can assign */ men,ioning i,s .ro.er,/ in code window1

$o4 can yo) 4rite *ethods for a ne4 c+ass?

Navgu+ara, BCA

Page 65 o0 56

Advanced Visual and Windows Programming(BCA-205) Ans- -Eou can crea,e a me,3od */ adding su* .rocedures and 0unc,ions 0or ,3e *e3aviours needed */ ,3e class1 &or ,3is class:/ou will add a me,3od as a 0unc,ion .rocedure ,o calcula,e ,3e e;,ended .rice:w3ic3 is ,3e .rice 0or ,3e *oo9 mul,i.lied */ ,3e Auan,i,/1 ),e. 4 -A0,er ,3e .ro.er,/ .rocedure:,/.e in .u*lic 0unc,ion e;,ended .rice as decimal and .ress %n,er1No,ice ,3a, ,3e edi,or adds ,3e .aren,3esis a0,er ,3e 0unc,ion name ),e. 2 - "/.e ,3e code 0or ,3e 0unc,ion Pu*lic 0unc,ion e;,ended.rice()as decimal Calcula,e ,3e e;,ended .rice !e,urn 'in,Auan,i,/Kmdec.rice %nd 0unc,ion

What is para*eteri,ed constr)ctor?

Ans- - (ni,ialiDes a new ins,ance o0 ,3e Parame,er'odi0ier class wi,3 ,3e num*er o0 .arame,ers ,o modi0/1 P)b+ic S)b Ne45 7 ByVa+ parameterCount #s (n,eger 7 6 Para*eters parameterCount "3e num*er o0 .arame,ers ,o modi0/

E E-p+ain the differences bet4een a pretest and posttest in a DoF"oop?


Ans- - "3e 0irs, 0orm o0 ,3e loo. ,es, 0or ,3e com.ila,ion a, ,3e ,o. o0 ,3e loo. called .re,es,1 W3ile "3e second 0orm o0 ,3e loo. ,es, 0or ,3e com.ila,ion a, ,3e *o,,om o0 ,3e loo.

88 In What proced)re do yo) 4rite the +o(ic for sendin( o)tp)t to the printer?
Ans- -

89

Define the fo++o4in( ter*s1

Navgu+ara, BCA

Page B0 o0 56

Advanced Visual and Windows Programming(BCA-205) (a) Arra/ (*) %lemen, )u*scri.,ed varia*le Ans- (a) Arraa/ - Collec,ion o0 similar da,a ,/.e value o0 s.eci0ied inde; in an arra/ (c))u*scri., (d) (nde; (e)

elemen,-

8B Disc)ss ho4 and 4hen the va+)e of the +oop inde- chan(ed thro)(ho)t the processin( of +oop? Ans- - $oo. ,ermina,e *ased on a condi,ion ,3a, /ou s.eci0/1 %;ecu,ion o0 loo. con,inues w3ile a condi,ion is ,rue un,il condi,ion is ,rue1 Eou can c3oose ,3e .lace and condi,ion a, ,3e ,o. or *o,,om o0 ,3e loo.1 W3en ,3e c3ec9 condi,ion second ,ime ,3a, ,ime incremen, or decremen, loo. inde;1 8D Define the fo++o4in( ter*s1 (a) #rray- An Arra/ is a lis, or series o0 value: similar ,o a lis, *o; or com*o *o;1 Eou can ,3in9 o0 an arra/ as a lis, *o; wi,3ou, ,3e *o;-wi,3ou, ,3e visual re.resen,a,ion1 An/ ,ime /ou need ,o 9ee. a series o0 varia*les 0or la,er .rocessing: suc3 as re-ordering: calcula,ing or .rin,ing1 Eou need ,o se, u. an arra/1 (*) E+e*ent- %ac3 0ield o0 da,a in a varia*le declares as a s,ruc,ure is re0erred as an elemen, o0 ,3e s,ruc,ure1 "o access elemen,: use ,3e do, no,a,ion similar ,o ,3a, used 0or o*+ec,: s.eci0/ varia*le1 %lemen,1 (c) S)bscrip,- "3e real advan,age o0 using an arra/ is no, realiDed un,il /ou use varia*le 0or su*scri., in .lace o0 ,3e cons,an,1 )u*scri., ma/ *e cons,an,s: varia*le or numeric e;.ression1 Al,3oug3 ,3e su*scri., ma/ *e in,egers1 (d) Inde-- "3e su*scri., (w3ic3 ma/ also *e called an inde;) inside ,3e .aren,3esis is ,3e .osi,ion o0 ,3e elemen, wi,3in ,3e arra/1 (e) S)bscripted Variab+e- An arra/ is a series o0 ,3e individual varia*le: all re0erence */ ,3e same name1 )ome,imes arra/ are re0erred ,o as a ,a*le or su*scri.,ed varia*le1 &or an arra/ 0or sor,ing names: /ou ma/ 3ave s,rName(0): s,rName(4) s,rName(2) and so on1 9G Describe the +o(ic of a tab+e +oo<)p? Ans- "3e ,ec3niAue used ,o 0ind ,3e su*scri., is called a ,a*le loo9-u.1 "3ings donZ, alwa/s wor9ou, as nea,l/ as 3aving seAuen,ial grou. num*er ,3a, can *e used ,o access ,3e ,a*le direc,l/: some,imes /ou will 3ave ,o do a li,,le wor9 ,o 0ind ,3e correc, value1 !econsider ,3e eig3, scou, ,roo.s and ,3eir ,ic9e, sales1 Now ,3e grou.s are no, num*ered 4 ,o C *u,

Navgu+ara, BCA

Page B4 o0 56

Advanced Visual and Windows Programming(BCA-205) 404:407:440:445:424:427:470 and 4851"3e grou. num*er and ,3e num*er o0 ,ic9e,s sold is s,ill in.u,: and ,3e num*er o0 ,ic9e,s mus, *e added ,o ,3e correc, ,o,al1 Bu, now /ou mus, do one more s,e.-de,ermine ,o w3ic3 arra/ elemen, ,o add ,3e ,ic9e, sale: using a ,a*le loo9u.1 "3e 0irs, s,e. in ,3e .ro+ec, is ,o es,a*lis3 a s,ruc,ure wi,3 ,3e grou. num*er and ,3e ,o,al and ,3en dimensions an arra/ o0 ,3e s,ruc,ure1 Be0ore an/ .rocessing is done: /ou mus, load ,3e grou. num*er in,o ,3e ,a*le1 "3e *es, .lace ,o do is in ,3e &ormS$oad%ven, .rocedure: w3ic3 is e;ecu,ed once as ,3e 0orm is loaded in,o ,3e memor/1 =uring .rogram e;ecu,ion ,3e user s,ill en,ers ,3e grou. num*er and ,3e num*er o0 ,ic9e,s sold in,o ,e;, *o;1 98 Na*e so*e sit)ations in 4hich it is i*portant to perfor* va+idation 4hen 4or<in( 4ith s)bscripted variab+es. Ans- A su*scri., mus, re0erence a valid elemen, o0 ,3e arra/1 (0 a lis, con,ains 40 names: i, would no, ma9e sense ,o as9- W3a, is ,3e 45,3 name on ,3e lis,? #r w3a, is ,3e 2 [ ,3 name on ,3e lis,? Visual Basic rounds 0rac,ional su*scri.,s and ,3rows an e;ce.,ion 0or a su*scri., ,3a, is ou, o0 range1 =im s,rName(20) As ),ring Cons, in,Value As (n,egerF40 A0,er e;ecu,ion o0 ,3e .receding s,a,emen,s: w3ic3 o0 ,3e 0ollowing are valid su*scri.,s? 41 s,rName(20) 21 s,rName(in,Value) 71 s,rName(in,ValueK2) 81 s,rName(in,ValueK7) 51 s,rName(0) 61 s,rName(in,Value-20) B1 s,rName(in,ValueL7) C1 s,rName(in,ValueL5-2) 99 .o*pare a t4o=di*ensiona+ tab+e to an array of a str)ct)re. Ans- "o de0ine a ,wo-dimensional arra/ or ,a*le ,3e =im s,a,emen, s.eci0ies ,3e num*er o0 rows and columns in ,3e arra/1 "3e row is 3oriDon,al and ,3e column is ver,ical1 Bo,3 o0 ,3ese ,wo s,a,emen,s es,a*lis3 an arra/ o0 elemen,s1 us, as wi,3 ,3e single dimensional arra/ /ou canZ, s.eci0/ ,3e num*er o0 elemen, wi,3 ,3e .aren,3esis and s.eci0/ ini,ial value1 >ow can /ou ini,ialiDe values in a ,wo-dimensional ,a*le? Ans- Numeric arra/ elemen,s are ini,iall/ se, ,o 0 and s,ring elemen, are se, ,o em.,/ s,ring and o0 course /ou can assign ini,ial value w3en /ou declare ,3e arra/1 Bu, man/ si,ua,ions reAuire ,3a, /ou reini,ialiDe arra/ ,o 0 or some o,3er value1 =im in,!ow As (n,eger =im in,Column As (n,eger &or in,!owF0 "o 2 &or in,ColumnF0 "o 7

Navgu+ara, BCA

Page B2 o0 56

Advanced Visual and Windows Programming(BCA-205)

9?

4hat is an ob ect ? a property? # *ethod?

Ans- - (n #$%: a .rogramming s,ruc,ure enca.sula,ing *o,3 da,a and 0unc,ionali,/ ,3a, are de0ined and alloca,ed as a single uni, and 0or w3ic3 ,3e onl/ .u*lic access is ,3roug3 ,3e .rogramming s,ruc,ure<s in,er0aces1 A C#' o*+ec, mus, su..or,: a, a minimum: ,3e I0n<no4n in,er0ace: w3ic3 main,ains ,3e o*+ec,<s e;is,ence w3ile i, is *eing used and .rovides access ,o ,3e o*+ec,<s o,3er in,er0aces1 See also C#' and (n,er0ace1 A .ro.er,/- (n0orma,ion ,3a, is associa,ed wi,3 an o*+ec,1 (n #$%: .ro.er,ies 0all in,o ,wo ca,egories- run-,ime .ro.er,ies and .ersis,en, .ro.er,ies1 !un-,ime .ro.er,ies are ,/.icall/ associa,ed wi,3 con,rol o*+ec,s or ,3eir con,ainers1 &or e;am.le: *ac9ground color is a run,ime .ro.er,/ se, */ a con,rol<s con,ainer1 Persis,en, .ro.er,ies are associa,ed wi,3 s,ored o*+ec,s1 )ee also Persis,en, .ro.er,ies and !un-,ime .ro.er,ies1 A me,3od-- "3ere are ,wo ,/.es o0 me,3ods- su*rou,ines: w3ic3 do no, re,urn values: and 0unc,ions: w3ic3 do1 "3e *od/ and End cons,ruc, o0 a me,3od ma/ onl/ *e omi,,ed i0 ,3e me,3od is de0ined in an in,er0ace or 3as ,3e ')stOverride modi0ier1 (0 no re,urn ,/.e is s.eci0ied on a 0unc,ion and s,ric, seman,ics are *eing used: a com.ile-,ime error occursQ o,3erwise ,3e ,/.e is im.lici,l/ Ob ect1 "3e accessi*ili,/ domain o0 ,3e re,urn ,/.e and .arame,er ,/.es o0 a me,3od mus, *e ,3e same as or a su.erse, o0 ,3e accessi*ili,/ domain o0 ,3e me,3od i,sel01 MethodDeclaration --F Su$Declaration \ unctionDeclaration Su$Declaration X Attri$utes Y X 'rocedureModi#ierI Y S)b Identi#ier X 5 X X (andles)rImplements Y X +lock X End S)b Line*erminator Y --F ormal'arameterList Y 6 Y Line*erminator Y

unctionDeclaration --F X Attri$utes Y X 'rocedureModi#ierI Y F)nction Identi#ier X 5 X ormal'arameterList Y 6 Y X #s X Attri$utes Y *ype,ame Y X (andles)rImplements Y Line*erminator X +lock Y X End F)nction Line*erminator Y 'rocedureModi#ier AccessModi#ier Shado4s Shared Overridab+e NotOverridab+e ')stOverride Overrides Over+oads --F \ \ \ \ \ \ \

Navgu+ara, BCA

Page B7 o0 56

Advanced Visual and Windows Programming(BCA-205) (andles)rImplements --F (andlesClause \ MethodImplementsClause 9B E-p+ain the ho4 to create a ne4 ob ect??

Ans-- An o*+ec,-crea,ion e;.ression is used ,o crea,e a new ins,ance o0 a class ,/.e or a s,ruc,ure ,/.e1 "3e ,/.e o0 an o*+ec, crea,ion e;.ression mus, *e a class ,/.e or a s,ruc,ure ,/.e and canno, *e a ')stInherit class1 Given an o*+ec, crea,ion e;.ression o0 ,3e 0orm Ne4 *5A6: w3ere * is a class ,/.e or s,ruc,ure ,/.e and A is an o.,ional argumen, lis,: overload resolu,ion de,ermines ,3e correc, cons,ruc,or o0 * ,o call1 (0 no cons,ruc,or is calla*le: a com.ile-,ime error occursQ o,3erwise ,3e e;.ression resul,s in ,3e crea,ion o0 a new ins,ance o0 * using ,3e c3osen cons,ruc,or1 (0 ,3ere are no argumen,s: ,3e .aren,3eses ma/ *e omi,,ed1 )$-ectCreationExpression --F Ne4 *ype,ame X 5 X ArgumentList Y 6 Y 9C What actions tri((er the constr)ctor and destr)ctor *ethod of a ob ect? Ans-- Cons,ruc,ors are s.ecial me,3ods ,3a, allow con,rol over ini,ialiDa,ion1 "3e/ are run a0,er ,3e .rogram *egins or w3en an ins,ance o0 a ,/.e is crea,ed1 Unli9e o,3er mem*ers: cons,ruc,ors are no, in3eri,ed and do no, in,roduce a name in,o a ,/.e<s declara,ion s.ace1 Cons,ruc,ors ma/ onl/ *e invo9ed */ o*+ec,-crea,ion e;.ressions or */ ,3e 1N%" &ramewor9Q ,3e/ ma/ never *e direc,l/ invo9ed1 (, is use0ul ,o ,3in9 o0 varia*le ini,ialiDers as s,a,emen,s ,3a, are au,oma,icall/ inser,ed in ,3e *loc9 o0 a cons,ruc,or1 "3e 0ollowing e;am.le con,ains several varia*le ini,ialiDers "3e e;am.le corres.onds ,o ,3e code s3own *elow: w3ere eac3 commen, indica,es an au,oma,icall/ inser,ed s,a,emen,(m.or,s )/s,em1Collec,ions Class A Priva,e ;: /: coun, As (n,eger Pu*lic )u* New() '/Base1New() < (nvo9e o*+ec,() cons,ruc,or1 ; F 4 < "3is is a varia*le ini,ialiDer1 / F - 4 < "3is is a varia*le ini,ialiDer1 coun, F 0 %nd )u* Pu*lic )u* New(n As (n,eger) '/Base1New() < (nvo9e #*+ec, cons,ruc,or1 ; F 4 < "3is is a varia*le ini,ialiDer1 / F - 4 < "3is is a varia*le ini,ialiDer1 coun, F n %nd )u*

Navgu+ara, BCA

Page B8 o0 56

Advanced Visual and Windows Programming(BCA-205) %nd Class Class B (n3eri,s A Priva,e sAr,2 As =ou*le Priva,e i,ems As Arra/$is, Priva,e ma; As (n,eger Pu*lic )u* New() 'e1New(400) i,ems1Add(Gde0aul,G) %nd )u* Pu*lic )u* New(n As (n,eger) '/Base1New(n - 4) sAr,2 F )/s,em1'a,31)Ar,(210) < "3is is a varia*le ini,ialiDer1 i,ems F New Arra/$is,(400) < "3is is a varia*le ini,ialiDer1 ma; F n %nd )u* %nd Class Destr)ctor1= G=es,ruc,orG 0unc,ions are ,3e inverse o0 cons,ruc,or 0unc,ions1 "3e/ are called w3en o*+ec,s are des,ro/ed (dealloca,ed)1 =esigna,e a 0unc,ion as a class<s des,ruc,or */ .receding ,3e class name wi,3 a ,ilde (H)1 &or e;am.le: ,3e des,ruc,or 0or class ),ring is declared- ]),ring()1 "3e des,ruc,or is commonl/ used ,o Gclean u.G w3en an o*+ec, is no longer necessar/1 Consider ,3e 0ollowing declara,ion o0 a ),ring classLL s.ec4Sdes,ruc,ors1c.. ^include Ns,ring13O class ),ring _ .u*lic),ring( c3ar Kc3 )Q LL =eclare cons,ruc,or ]),ring()Q LL and des,ruc,or1 .riva,ec3ar KS,e;,Q `Q LL =e0ine ,3e cons,ruc,or1 ),ring--),ring( c3ar Kc3 ) _ LL =/namicall/ alloca,e ,3e correc, amoun, o0 memor/1 S,e;, F new c3arXs,rlen( c3 ) I 4YQ

Navgu+ara, BCA

Page B5 o0 56

Advanced Visual and Windows Programming(BCA-205)

LL (0 ,3e alloca,ion succeeds: co./ ,3e ini,ialiDa,ion s,ring1 i0( S,e;, ) s,rc./( S,e;,: c3 )Q ` LL =e0ine ,3e des,ruc,or1 ),ring--]),ring() _ LL =ealloca,e ,3e memor/ ,3a, was .reviousl/ reserved LL 0or ,3is s,ring1 dele,eXY S,e;,Q ` void main() _ ` 9D Differentiate bet4een over+oadin( and overridin(? #ns1= Over+oadin(1= #verloading is ,3e onl/ wa/ ,o declare iden,icall/ named en,i,ies o0 ,3e same 9ind in a declara,ion s.ace1 #nl/ me,3ods: ins,ance cons,ruc,ors: and .ro.er,ies ma/ *e overloaded1 #verloaded ,/.e mem*ers mus, .ossess uniAue signa,ures1 "3e signa,ure o0 a ,/.e mem*er consis,s o0 ,3e name o0 ,3e ,/.e mem*er and ,3e num*er and ,/.es o0 ,3e mem*er<s 0ormal .arame,ers1 "3e 0ollowing are no, .ar, o0 a mem*er<s signa,ure: and 3ence can no, *e overloaded on

'odi0iers ,o a ,/.e mem*er (0or e;am.le: Shared or Private)1 'odi0iers ,o a .arame,er (0or e;am.le: ByVa+ or By%ef)1 "3e names o0 ,3e .arame,ers1 "3e re,urn ,/.e o0 a me,3od1 "3e elemen, ,/.e o0 a .ro.er,/1

Ovrridin(1= "3e Overrides modi0ier indica,es ,3a, a me,3od overrides a *ase-,/.e overrida*le me,3od wi,3 ,3e same signa,ure1 Cer,ain com*ina,ions o0 ,3ese modi0iers are no, validOverridab+e and NotOverridab+e are mu,uall/ e;clusive and canno, *e com*ined1

Navgu+ara, BCA

Page B6 o0 56

Advanced Visual and Windows Programming(BCA-205) ')stOverride im.lies Overridab+e (and so can<, s.eci0/ i,) and canno, *e com*ined wi,3 NotOverridab+e1 ')stOverride me,3ods canno, override o,3er me,3ods: and so canno, *e com*ined wi,3 ,3e Overrides modi0ier1 NotOverridab+e canno, *e com*ined wi,3 Overridab+e or ')stOverride1 Overrides im.lies Overridab+e (and so can<, s.eci0/ i,) and canno, *e com*ined wi,3 ')stOverride1

"3ere are also addi,ional res,ric,ions on overrida*le me,3odsA ')stOverride me,3od ma/ no, include a me,3od *od/ or an End cons,ruc,: ma/ no, override ano,3er me,3od: and ma/ onl/ a..ear in ')stInherit classes1 (0 a me,3od s.eci0ies Overrides and ,3ere is no ma,c3ing *ase me,3od ,o override: a com.ile-,ime error occurs1 An overriding me,3od ma/ no, s.eci0/ Shado4s1 A me,3od ma/ no, override ano,3er me,3od i0 ,3e overriding me,3od<s accessi*ili,/ domain is no, eAual ,o or grea,er ,3an ,3e accessi*ili,/ domain o0 ,3e me,3od *eing overridden1 Private me,3ods ma/ no, *e Overridab+e: NotOverridab+e: or ')stOverride: nor ma/ ,3e/ override o,3er me,3ods1 'e,3ods in NotInheritab+e classes ma/ no, *e declared Overridab+e or ')stOverride1

9E IN What sit)ation 4o)+d a +oop be )sed in a prod)cer? #ns1= A con,rol s,ruc,ure allows /ou ,o con,rol ,3e 0low o0 /our .rogram e;ecu,ion Using con,rol s,ruc,ure /ou can ,es, ,3e condi,ion de.anding on ,3e resul, and e;ecu,e one or more line o0 code re.e,i,ivel/ 70 E-p+ain different bet4een do F 4hi+e and For +oop? #ns1= DOF W$I"E1=(0 condition is Tr)e: all s,a,emen,s in statements are e;ecu,ed un,il ,3e Wend s,a,emen, is encoun,ered1 Con,rol ,3en re,urns ,o ,3e Whi+e s,a,emen, and condition is again c3ec9ed1 (0 condition is s,ill Tr)e: ,3e .rocess is re.ea,ed1 (0 i, is no, Tr)e: e;ecu,ion resumes wi,3 ,3e s,a,emen, 0ollowing ,3e Wend s,a,emen,1 Whi+e...Wend loo.s can *e nes,ed ,o an/ level1 %ac3 Wend ma,c3es ,3e mos, recen, Whi+e1 Note "3e Do..."oop s,a,emen, .rovides a more s,ruc,ured and 0le;i*le wa/ ,o .er0orm loo.ing1 "3e 0ollowing e;am.le illus,ra,es use o0 ,3e Whi+e...Wend s,a,emen,=im Coun,er Coun,er F 0 < (ni,ialiDe varia*le1 Whi+e Coun,er N 20 < "es, value o0 Coun,er1 Coun,er F Coun,er I 4 < (ncremen, Coun,er1

Navgu+ara, BCA

Page BB o0 56

Advanced Visual and Windows Programming(BCA-205) Aler, Coun,er Wend < %nd W3ile loo. w3en Coun,er O 451 FO% "OOP1= C3anging ,3e value o0 counter w3ile inside a loo. can ma9e i, more di00icul, ,o read and de*ug /our code1 E-it For can onl/ *e used wi,3in a For Each...Ne-t or For...Ne-t con,rol s,ruc,ure ,o .rovide an al,erna,e wa/ ,o e;i,1 An/ num*er o0 E-it For s,a,emen,s ma/ *e .laced an/w3ere in ,3e loo.1 E-it For is o0,en used wi,3 ,3e evalua,ion o0 some condi,ion (0or e;am.le: If...Then): and ,rans0ers con,rol ,o ,3e s,a,emen, immedia,el/ 0ollowing Ne-t1 Eou can nes, For...Ne-t loo.s */ .lacing one For...Ne-t loo. wi,3in ano,3er1 Give eac3 loo. a uniAue varia*le name as i,s counter1 "3e 0ollowing cons,ruc,ion is correc,For ( F 4 To 40 For F 4 To 40 For 2 F 4 To 40 ... Ne-t Ne-t Ne;, ?8.What is the P)rpose of the Na*e Property .ontro+ ? Ans:=> (0 /ou C3ange ,3e name o0 ,3e 0orm /ou 'us, se, .ro+ec,Zs s,ar,u. o*+ec, .ro.er,/ ,o ,3e new name o0 ,3e 0orm1 "3e name .ro.er,/ gives ,3e menu i,em a name similar ,o naming o,3er con,rol1 Wi,3 ,3e use o0 name .ro.er,/ we can c3ange ,3e la*el name: $is, *o; name: Bu,,on Name: Con,rols Names1 ??.What is the p)rpose of the Te-t property of a b)tton ? the Te-t Property of a for* ? Ans:=> We can se, ,3e ,e;, in a *u,,on wi,3 a ,e;, Pro.er,/ in ,3e ,ool *ar *u,,on collec,ion edi,or1 "3e ,e;, .ro.er,/ o0 ,3e con,rol =e,ermines w3a, will *e dis.la/ed on ,3e 0orm: wi,3 ,e;, .ro.er,/ we can c3ange ,e;, o0 ,3e 0orm1 ?A.What Property *)st be set to center te-t in a +abe+ ? What sho)+d be the va+)e of the property? Ans:=> "3e "e;, Align ( Alignmen,) Pro.er,/ allow /ou ,o se, ,3e alignmen, o0 ,3e ,e;, wi,3in ,3e la*el "e;, Align ( 'iddleCen,er "3is Pro.er,/ will *e se, W3en /ou Wan, ,o )e, "3e cen,er "e;, in a la*el

Navgu+ara, BCA

Page BC o0 56

Advanced Visual and Windows Programming(BCA-205) ?B.$o4 does the behavior of radio b)ttons differ fro* the behavior of chec< bo-es ? Ans:=> Check +oxes -"3e/ are )Auare1 !adio +utton ." "3e/ are !ound1 Check +oxes -C3ec9 Bo;es can wor9 inde.enden,l/1 !adio +utton -!adio Bu,,ons are in,ended ,o wor9 in grou.s1 Check +oxes ." (, allow 'ul,i.le selec,ion1 !adio +utton -W3en /ou selec, one !adio Bu,,on in Grou. ,3e o,3ers are au,oma,icall/ deselec,ed1 Check +oxes -(, allow "3e user ,o selec, and deselec, an o.,ion1 !adio +utton ." (, use w3en onl/ one *u,,on o0 grou. ma/ *e selec,ed1 ?C.E-p+ain ho4 to *a<e a (raphic appear in a pict)re bo- contro+. Ans:=> "o =is.la/ a Gra.3ic 0rom a *i,ma.: icon: P%G: G(& or o,3er image 0ile ,a.e /ou can see a .ic,ure *o; - 0rom ,3e .ic,ure *o;es1 /ou can se, ,3e ('AG% .ro.er,/ ,o ,3e image /ou wan, ,o dis.la/: ei,3er a, disgn ,ime or a, run ,ime1 Eou can cli. and .osi,ion an image wi,3 ,3e GsiDe modeG .o.er,/ Picturesizemode :/ ,ormal -),andard .ic,ure*o; *e3aviour1 / Autosi0e." &i,s ,3e .ic,ure *o; ,o ,3e image1 / Stretchinage." Allow /ou ,o s,re,c3 ,3e image in code1 / Center Image." Cen,ers ,3e image in ,3e .ic,ure *o;1 ?I.What is the p)rpose of Jeyboard access <eys ? $o4 can yo) define the* in yo)r pro ect ? $o4 do yo) they operate at r)n ti*e ? Ans:=> Access 9e/ allow user ,o o.en a menu */ .ressing ,3e Al,(Al,er) 9e/ and a le,,er 9e/1 "o o.en ,3e edi, menu in all windows a..lica,ion 0or: eg1 Eou can .ress Al,I%1 % is ,3e edi, menu<s access 9e/1

Navgu+ara, BCA

Page B5 o0 56

Advanced Visual and Windows Programming(BCA-205)

?D.E-p+ain the p)rpose of the #cceptB)tton and .ance+B)tton properties of the for*. /ive an e-a*p+e of a (ood )se for each ? Ans:=> Acceptbutton : Eou Can ma9e one o0 /our *u,,on ,3e de0aul, *u,,on */ se,,ing ,3e acce.,*u,,on .ro.er,/ o0 ,3e 0orm ,o ,3e *u,,on name1w3en ,3e user .resses en,er ,3a, *u,,on is au,oma,icall/ selec,ed1 Cancelbutton: "3e Cancel*u,,on is ,3e *u,,on ,3a, is selec,ed w3en ,3e user .resses ,3e %sc 9e/1 /ou can ma9e a *u,,on ,3e cacel*u,,on */ se,,ing ,3e 0orm<s cancel*u,,on .ro.er,/1an e;am.le o0 good ,ime ,o se, ,3e cancel *u,,on .ro.er,/ is on a 0orm wi,3 o9 H cancel *u,,on1 ?E.What is Too+tip ? $o4 can yo) 'a<e a Too+tip appear? Ans:=> "ool,i. are ,3ose small windows ,3a, a..ear wi,3 e;.lana,or/ ,e;, w3en /ou le, ,3e mouse res, on a con,rol or window 1 "3a,<s w3a, "ool ,i.s are used 0or -,o give Auic93el. w3en ,3e mouse res, on an i,em1 "o connec, a ,ool,i. wi,3 a con,rol /ou use i,<s se, ,ool ,i. me,3od1 Synte-1= "ool,i.1se, "ool,i. ( *u,,on41G,3is is a *u,,onG) AG.4hat is Foc)se? $o4 can yo) .ontro+ Which ob ect has the Foc)se ? Ans:=> "3is me,3od moves ,3e &ocus ,o ,3e con,rol ,o w3ic3 ,3e me,3od a..lies: regardless o0 ,3e conrol ,3a, 3as ,3e &ocus a, ,3e ,ime1 Eour valida,ion rou,in could move ,3e &ocus ,o ,3e con,rol wi,3 an erroneous en,r/ wi,3 ,3e 0ollowing s,a,emen,"e;,*o;41&ocus (,<s also .ossi*le ,o G,re.G ,3e 0ocus ,o a s.eci0ic "e;, Bo; con,rol un,il ,3e user en,ers a valid value:*/ calling ,3e &ocus ma,3od 0rom wi,3in ,3e $eave even,1"3e 0ollowing code sagmen, doesn<, allow users ,o move ,3e &ocus ,o ano,3er con,rol w3ile "e;,Bo;4 doesn<, con,ain a valid numeric valuePriva,e su* "e;,*o;4Sleave(B/val sender As #*+ec, :B/val e as )/s,em1%ven,Args) >andles "e;,*o;41$eave (0 No, (sNumeric("e;,*o;41"e;,)"3en "e;,*o;1&ocus() %nd )u* A8. What is *essa(ebo- and When sho)+d )se one? Ans:=> Wi,3 ,3e use o0 message*o; /ou can use ,3e msg*o; and in.u, *o; 0unc,ions1 /ou can also use ,3e message*o; class *uil, in,o ,3e 1ne, 0ramewor9 ,o dis.la/ messages and acce., in.u, 0rom ,3e user1

Navgu+ara, BCA

Page C0 o0 56

Advanced Visual and Windows Programming(BCA-205) Synte-1= 'essage*o;1s3ow ( argumen,s ) several c3oices 0or argumen, lis, in,roduce conce., o0 overloded 0unc,ions mul,i.le signa,ure ,o c3oose 0orm message*o;1s3ow(,e;,message) message*o;:s3ow(,e;,message:,i,al*ar "e;,) A?.E-p+ain the difference bet4een a *en) K a s)b*en). Ans:=> 'ain menu is ,3e con,e;, menu1 (nside o0 main menu is called su* menu1 AA.$o4 .an the )ser <no4 if a *en) ite* contains a s)b*en)? Ans:=> W3en our mouse cursor is goes on ,o ,3e main menu ,3en inside menu will *e o.en ,3us we 9now ,3a, 'ain menu i,em con,ains1 AB.Na*e at +east three types of co**on dia+o(bo-es1 Ans:=> #.en0ile =ialog*o; )ave0ile =ialog*o; &on,color =ialog*o; Prin, =ialog*o; Prin, Preview =ialog*o; AC.What is conte-t *en) ? $o4 4o)+d yo) attech a conte-t *en) to a contra+? Ans:=> Con,e;, menu are ,3ose 3and/ menuse ,3a, .o. u. over con,rols: usuall/ w3en /ou rig3, - Clic9 ,3em1 #*+ec, 'ars3al*/!e0#*+ec, Com.onen, 'enu Con,e;,'enu "3ere are some .u*lic .ro.er,ies o0 con,e;,menu 'e,3od 'eans Ge,con,e;,'enu Ge,s ,3e Con,e;, 'enu ,3a, con,ains ,3is menu AD.What is +istbo-? # co*bobo-? Ans:=> Combo Box:=> "3e windows 0orms com*o*o; con,rol is use ,o dis.la/ ,3e da,a in a dro.-down com*o*o;1"3e com*o*o; is made u. o0 ,wo .ar,s-,3e ,o. .ar, is a ,e;,*o; ,3a, allow ,3e user ,o ,/.e in all or .ar, o0 a lis, i,em1,3e ano,3er .ar, is a lis, *o; ,3a, dis.la/s a lis, o0 i,em 0rom w3ic3 ,3e user can selec, one or more1 Eou can se, and access ,3e ,e;, in a com*o*o;<s ,e;, *o; wi,3 ,3e ,e;, .ro.er,/ 1

Navgu+ara, BCA

Page C4 o0 56

Advanced Visual and Windows Programming(BCA-205) "o add or dele,e (,ems in a com*o *o; con,rol:use ,3e (,ems1Add: (,em1(nser,:(,em1Clear:(,em1Addrange:(,ems1!emove or (,em1!emovea, me,3od ist Box:-> $is, *o; dis.la/s a lis, o0 i,ems 0rom w3ic3 ,3e user can selec, one or more 1 (0 ,3ere are ,oo man/ (,ems ,o dis.la/ a, once: a scroll *ar au,oma,icall/ a..ers ,o le, ,3e users scroll ,3roug3 ,3e lis,1 /ou also can scroll $is, Bo;es 3oriDon,all/ w3en /ou se, ,3e 'ul,i Colmn .ro.er,/ ,o "rue1 "3e )elec,(nde; .ro.er,/ re,urns an in,eger value ,3a, corres.onds ,o ,3e selec,ed i,ems AE.Na*e and decribe the three sty+es of co*bobo-es? Ans:=> "3ere are Three ,/.es o0 Com*o*o;es 11 Simple Com$o +ox -(nclude a ,e;, *o; and a lis, w3ic3 does no, dro. down1 ,3e user can selec, 0rom ,3e lis, or ,/.e in ,3e ,e;, *o;1 "3e siDe o0 ,3e sim.le com*o *o; include *o,3 ,3e edi, and lis, .or,ion1 B/ de0aul, a sim.le com*o *o; is siDed so ,3a, non o0 ,3e lis, is dis.la/ed1 (ncrease ,3e >ig3, .ro.er,/ ,o dis.la/ more o0 ,3e lis,1 21 Drop do%n Com$o +ox ." (ncludes a dro. down lis, and a ,e;, *o;1 ,3e user can selec, 0rom ,3e lis, or ,/.e in ,3e ,e;, *o;1 21 Drop do%n list com$o +oxes ." "3is s,/le allows selec,ion onl/ 0rom dro. down lis,1 ,3is is ,3e good one ,o 9ee. in mind w3en /ou wan, ,o res,ric, ,3e user<s in.u,: Bu, i0 /ou wan, ,o use ,3is one: Eou also s3ould consider sim.le lis, *o;1 B8.E-p+ain the p)rpose of the se+ectedinde- property and the ite*.co)nt property. Ans:=> !electedIndex:Eou can use ,3e selec,edinde; .ro.er,/ ,o ge, ,3e selec,edlis, i,em 1/ou can c3ange selec,ed i,em */ c3anging ,3e selec,edinde; value in code : w3ic3 will ma9e ,3e corres.onding i,em a..ear in ,3e ,e;, .or,ion o0 ,3e com*o*o; as wi,3 lis, *o;es i0 no i,em is selec,ed : ,3e selec,ed inde; value is -41 i0 ,3e 0irs, i,em in ,3e lis, is selec,ed: ,3en ,3e selec,edinde; value is 01 Item"count:"3e i,em1coun, .ro.er,/ re0lec,s ,3e num*er o0 i,em in ,3e lis, ( "3e value o0 ,3e i,em1coun, .ro.er,/ is alwa/s one more ,3an ,3e larges, .ossi*le selec,edinde; value selec,edinde; is aero - *ased)1 B9.When and ho4 is infor*ation p+aced inside a +istbo- or co*bobo-. Ans:=> A com*o*o; is a com*ina,ion o0 a ,e;,*o; and a lis, *o; : so a, design ,ime : /ou can c3ange ,e;, in ,3e ,e;, *o; .ar, */ c3anging ,3e "e;, .ro.er,/ 1 Eou c3ange ,3e i,ems in ,3e lis, *o; .ar, wi,3 ,3e i,em .ro.er,/ (,3is i,em o.ens ,3e s,ring collec,ion %di,or discussed 0or lis,*o;es w3en /ou clic9 i, in ,3e .ro.er,/ window) a, design ,ime1

Navgu+ara, BCA

Page C2 o0 56

Advanced Visual and Windows Programming(BCA-205) As wi,3 lis, *o;es : /ou also can use ,3e i,ems1inser, :i,ems1add and i,ems1addrange me,3od ,o add i,ems ,o ,3e lis,.ar, o0 a com*o *o;1 B?.What is the p)rpose of the printdoc)*ent contro+? The print preivie4 dia+o( contro+? Ans:=> "3e wa/ Eou .rin, documen,s in v* 3as *ecome 0airl/ involved : revolving around ,3e .rin,documen, class1Eou add an o*+ec, o0 ,3is class ,o a .ro+ec,:and ,3en 3andle even, li9e .rin,.age:w3ic3 is called ever/ ,ime a new .age is ,o *e .rin,ed w3en i, is added ,o a 0orm : ,3e .rin,documen, com.onen, a..ears in ,3e ,ra/ a, ,3e *o,,om o0 ,3e windows 0orm designer Printpre#ie$ dialogs:Eou use .rin,.review dialogs ,o le, ,3e user see w3a, a documen, will loo9 li9e w3en i,<s .rin,ed1 ,3is dialog is su..or,ed wi,3 ,3e .rin,.reviewdialog class1,3is dialog con,ains *u,,ons 0or .rin,ing: Dooming in: dis.la/ing one or mul,i.le .ages : and closing ,3e dialog*o;1 Basics o0 v*1ne, B? What are the properties and events? E-p+ain 4ith e-a*p+e. LMProperties1= Pro.er,ies are use ,o se, con0igura,ion da,a 0or o*+ec,s: suc3 as ,e;, in a ,e;, *o; or ,3e wid,3 o0 a lis, *o; 1Pro.er,ies .rovides in,er0ace ,o se, or ge, ,3e value o0 da,a in,ernal ,o an o*+ec,1 Pro.er,ies uses Ge, and )e, ,3e .rocedure in a .ro.er,/ s,a,emen,1 %;am.le(n ,3is eg1 we are crea,ing a readLwri,e .ro.er,/ named Pro.4 in 'odule2: and s,oring ,3e .ro.er,/<s value in .riva,e ,e;, s,ring named Pro.er,/ Value in 'odule2 1 'odule 'odule4 )u* 'ain () 1111 1111 1111 %nd )u* %nd 'odule 'odule 'odule2 Priva,e Pro.er,/ Value as s,ring Pu*lic Pro.er,/ Pro.4 () As ),ring Ge, !e,urn Pro.er,/ Value %nd Ge, )e, (B/ Val Value As ),ring) Pro.er,/ Value FValue %nd )e, %nd Pro.er,/ %nd 'odule Events1= An ac,ion ,3a, ma/ *e caused */ ,3e user: suc3 as a clic9 : drag: 9e/ .ress

Navgu+ara, BCA

Page C7 o0 56

Advanced Visual and Windows Programming(BCA-205) or scroll1 %ven,s can also *e ,riggered */ an in,ernal ac,ion suc3 as re.ain,ing ,3e 0orm or valida,ing ,3e user in.u,1 E-a*p+e1= BA What are the different editions of 'icrosoft VB.Net? LM"3e di00eren, edi,ions o0 'icroso0, VB1Ne, are4) Academic edi,ion 2) Pro0essional edi,ion 7) %n,er.rise =evelo.er edi,ion 8) %n,er.rise Arc3i,ec, edi,ion BC What is IDE? E-p+ain. LMA develo.men, environmen, suc3 as visual s,udio: is called an (=%((n,egra,ed =evelo.men, %nvironmen,)1"3e (=% consis,s o0 various ,ools including a 0orm designer: w3ic3 allows /ou ,o visuall/ crea,e a 0ormQ an edi,or 0or en,ering and modi0/ing .rogram code1 (n earlier versions o0 Visual ),udio: eac3 language 3ad i,s own (=%1 &or e;am.le: ,o crea,e a VB .ro+ec, /ou would use ,3e VB (=%: and ,o crea,e a CII .ro+ec, /ou would use ,3e CII (=%1 Bu, in Visual ),udio1Ne,: /ou use ,3e one (=% ,o crea,e .ro+ec,s in an/ o0 ,3e 1N%" languages1 "3e di00eren, ,/.es o0 (=% is as *elow--"3e s,ar, .age -"ool *o; -'enu *ar -New .ro+ec, =ialog*o; -#*+ec, Browser -)olu,ion %;.lorer -Class View Window -Com.onen, "ra/ -"3e server e;.lorer -Pro.er,/ Window BI What is the difference bet4een Jey)p and Jeydo4n event? LMJey)p1= (, 3a..ens w3en 9e/ is released w3ile ,3e con,rol 3as 0ocus1 Jeydo4n1= (, 3a..ens w3en a 9e/ is .ressed down w3ile ,3e con,rol 3as 0ocus1 BD What is 'essa(e Bo-? $o4 to 4rite the *)+tip+e+ine *essa(ebo-? LM'essage *o; is a 0unc,ion w3ic3 is an eas/ wa/ ,o add mul,i.le 0orms alread/ *uil, in a Visual Basic1We can also use ,3e 'essageBo; class *uil, in,o ,3e 1Ne, &ramewor9 ,o dis.la/ messages and acce., in.u, 0rom ,3e user1 Argumen,s .assed ,o ,3is 0unc,ion4) Prom., 2) Bu,,ons 7) "i,le "3is 0unc,ion re,urns ,3e value 0rom ,3e 'sgBo;!esul, enumera,ion1 %gPriva,e )u* Bu,,on4SClic9(B/Val sender As )/s,em1#*+ec,:

Navgu+ara, BCA

Page C8 o0 56

Advanced Visual and Windows Programming(BCA-205) (B/Val e As )/s,em1%ven,Args) >andles Bu,,on41Cl =im !esul, As (n,eger !esul,F'sgBo;(G"3is is a 'essage Bo;bG: 'sgBo;),/le1#2Cancel I S 'sgBo;),/le1(n0orma,ion I 'sgBo;),/le1)/s,em'odal: G'essage Bo;G) (0 (!esul,F 'sgBo;!esul,1#2) ,3en "e;,Bo;41"e;,FGEou clic9ed #2G %nd (0 %nd )u* BE What is the difference bet4een VB and VB.Net? LMVB1= 4) Visual Basic 610 is revolu,ionar/ and 0ar reac3ing1 2) A grea, num*er o0 ,ec3niAues suc3 as da,a 3andling: and man/ con,rols: .ro+ec, ,/.es and o,3er as.ec,s o0 visual *asic 610 are no longer availa*le a, all1 7) (, is less .o.ular ,3an VB1Ne, 8) (, is no, 0ull/ o*+ec,-orien,ed language VB.Net1= 4)VB1Ne, 3as *een more ,3an 0our /ears in ,3e ma9ing: and i, re.resen,s en,irel/ new direc,ions 0or visual *asic1 2) A grea, num*er o0 ,ec3niAues suc3 as da,a 3andling: and man/ con,rols: .ro+ec, ,/.es and o,3er as.ec,s o0 VB1Ne, are easil/ availa*le1 7) (, is more .o.ular ,3an visual *asic 6101 8) (, is 0ull/ o*+ec,-orien,ed language1 CG What are the r)+es for na*in( the variab+es? LM C8 What is the I*p+icit and E-p+icit Dec+arations? LM I*p+icit Dec+arations1= (0 /ou ,urn e;.lici, declara,ion o00: /ou can im.lici,l/ declare a varia*le */ sim.l/ using , in /our code1 All im.lici,l/ declared varia*les are given ,3e da,a ,/.e Ob ect1 >owever: /our a..lica,ion is more e00icien, i0 /ou declare all /our varia*les e;.lici,l/ and wi,3 a s.eci0ic da,a ,/.e1 "3is reduces ,3e incidence o0 naming-con0lic, errors and s.elling mis,a9es1 (, also allows ,3e com.iler ,o de,ec, .o,en,ial run-,ime errors suc3 as assigning an Inte(er ,o a Short1 Eou can wri,e a 0unc,ion in w3ic3 /ou do no, declare a local varia*le: as in ,3e 0ollowing e;am.le&unc,ion )a0e)Ar,(Num) "em.Val F 'a,31A*s(Num) < 'a9e sure value is .osi,ive 0or sAuare roo,1 !e,urn 'a,31)Ar,("em.Val) %nd &unc,ion E-p+icit Dec+arations1=

Navgu+ara, BCA

Page C5 o0 56

Advanced Visual and Windows Programming(BCA-205) %;.lici, declara,ions 3as *een in e00ec, 0or ,3e module con,aining ,3e )a0e)Ar, 0unc,ion in ,3e .receding e;am.le: Visual Basic would 3ave recogniDed "em.Val and "emVal as undeclared varia*les and genera,ed errors 0or *o,3 o0 ,3em1 As a resul,: /ou would ,3en e;.lici,l/ declare "em.Val: as 0ollows&unc,ion )a0e)Ar,(Num As )ingle) As )ingle =im "em.Val As )ingle F 'a,31A*s(Num) !e,urn 'a,31)Ar,("emVal) %nd &unc,ion IG What is the difference bet4een proced)re and f)nction? E-p+ain 4ith the e-a*p+e. LMProced)re1= A calla*le series o0 s,a,emen,s ,3a, ma/ or ma/ no, re,urn value1W3en ,3e series o0 s,a,emen,s ,ermina,es :con,rol re,urns ,o ,3e s,a,emen,s ,3a, call ,3e .rocedure1 F)nction1= A .rocedure ,3a, re,urns ,3e value. 886What is I*p+icit and E-p+icit .onversions? LM Conversions can *e ei,3er im.lici, or e;.lici,1 I*p+icit .onversions1= (m.lici, conversions occur wi,3ou, an/ s.ecial s/n,a;1 "3e 0ollowing is an e;am.le o0 im.lici, conversion o0 an Inte(er value ,o a "on( value'odule "es, )u* 'ain() =im in,Value As (n,eger F 427 =im longValue As $ong F in,Value Console1Wri,e$ine(in,Value H G F G H longValue) %nd )u* %nd 'odule E-p+icit .onversions1= %;.lici, conversions: on ,3e o,3er 3and: reAuire cas, o.era,ors1 A,,em.,ing ,o do an e;.lici, conversion on a value wi,3ou, a cas, o.era,or causes a com.ile-,ime error1 (, is )e, ,o #n or #001 #n is ,3e de0aul,1 !eAuires declara,ion o0 varia*les *e0ore ,3e/ are used1 ("3is is ,3e de0aul,) "3e 0ollowing e;am.le uses an e;.lici, conversion ,o conver, a "on( value ,o an Inte(er value1 'odule "es, )u* 'ain()

Navgu+ara, BCA

Page C6 o0 56

Advanced Visual and Windows Programming(BCA-205) =im longValue As $ong F 478 =im in,Value As (n,eger F C(n,(longValue) Console1Wri,e$ine(longValue H G F G H in,Value) %nd )u* %nd 'odule I8 What are the three steps for p+annin( and creatin( Vis)a+ Basic Pro ects? Describe 4hat happens in each step. LM4) )e,,ing U. ,3e user in,er0ace 2) =e0ining ,3e .ro.er,ies 7) Crea,ing ,3e code I9 What is the p)rpose of these vis)a+ basic fi+e types1 .s+n 2 .s)o 2 .vb? LM.sinF solu,ion 0ile1 1suoFsolu,ion user o.,ion 0ile1 1v*FAn/ 0ile 0rom 0ollowing1 -Basic window 0orm -A da,a 0orm -A user con,rol -'odule 0ile -A code 0ile -cus,om con,rol -(n3eri,ed 0orm -Windows services -"3e #u,.u, Window -&orm =esigners -Gra.3ical =esigners I? When is the vis)a+ basic in desi(n ti*e? r)n ti*e? brea< ti*e? LMVisual Basic 3as ,3ree dis,inc, modes1 Desi(n Ti*e1= W3ile we are designing ,3e user in,er0ace and wri,ing code: we are in design ,ime1 %)n Ti*e1= W3en we are ,es,ing and running /our .ro+ec,: we are in run,ime1 Brea< Ti*e1= (0 we ge, a run-,ime error or .ause .ro+ec, e;ecu,ion: we are in *rea9 ,ime1 IA What is vis)a+ basic event? /ive so*e e-a*p+es of events. LM An ac,ion ,3a, ma/ *e caused */ ,3e user: suc3 as a clic9 : drag: 9e/ .ress or scroll1 %ven,s can also *e ,riggered */ an in,ernal ac,ion suc3 as re.ain,ing ,3e 0orm or valida,ing ,3e user in.u,1 IC What is a synta- error2 4hen does it occ)r2 4hat *i(ht ca)se it? LMW3en we *rea9 V*Zs rules 0or .unc,ua,ion: 0orma, or s.elling: we genera,e a s/n,a; error1"3e s/n,a; error ,3a, ,3e edi,or canno, iden,i0/ are 0ound and re.or,ed */ ,3e com.iler as i, a,,em.,s ,o conver, ,3e code in,o in,ermedia,e mac3ine language1 II What is a r)n=ti*e error2 4hen does it occ)r2 4hat *i(ht ca)se it? LM(0 a .ro+ec, 3al,s during e;ecu,ion: i, is called run,ime error or an e;ce.,ion1 ),a,emen,s

Navgu+ara, BCA

Page CB o0 56

Advanced Visual and Windows Programming(BCA-205) ,3a, canno, e;ecu,e correc,l/ cause run,ime error1 !un ,ime errors can *e caused */ a,,em.,ing ,o do im.ossi*le ari,3me,ic o.era,ions1 ID What is a +o(ic error2 4hen does it occ)r2 4hat *i(ht ca)se it? LM"3e .ro+ec, runs *u, .roduces incorrec, resul, is called logic error1 W3en ,3e resul,s o0 ,3e calcula,ion are incorrec, or ,3e ,e;, a..ears: or ,3e ,e;, is #2 *u, a..ears in ,3e wrong loca,ion: logic error will occur1 IE What does conte-t=sensitive $e+p *ean? $o4 can yo) )se it to see the $e+p pa(e for a b)tton? LMA Auic9 wa/ ,o view >el. on an/ ,o.ic is used ,o con,e;,-sensi,ive >el.1 )elec, a VB o*+ec,: suc3 as a 0orm or con,rol: or .lace ,3e inser,ion .oin, in a word in ,3e edi,or: and .ress &41"3e corres.onding 3el. ,o.ic will a..ear in ,3e documen, window: i0 .ossi*le: saving /ou a searc31 DGNa*e and (ive the p)rpose of five types of data avai+ab+e in Vis)a+ Basic. LMData types1= sin(+e1= (, can 3andle 0loa,ing .oin, values1 Do)b+e1= (, can also 3andle 0loa,ing .oin, values1 Boo+ean1= (, ,a9es values li9e ,rue or 0alse onl/1 Strin(1= (, ,a9es ,3e s,ring1 Int1= (, ,a9es ,3e onl/ in,eger values. D8What does dec+arin( a variab+e *ean? LMWe will use =im s,a,emen, ,o declare a varia*le1 "3is s,a,emen, is used a, module: class: s,ruc,ure: .rocedure or *loc9 level1 For e-a*p+e1 =im c as in, (, means ,3a, we 3ave ,a9en c varia*le as in,eger1 D9 What effect does the +ocation of a Di* state*ent have on the variab+e it dec+ares? LMAl,3oug3 ,3ere are several wa/s ,o declare a varia*le: ,3e mos, commonl/ used s,a,emen, is ,3e =im s,a,emen,1 "3e reserved word =im is reall/ s3or, 0or dimension: w3ic3 means siDe1W3en /ou declare a varia*le: ,3e amoun, o0 memor/ reserved de.ends on i,Zs da,a ,/.e1 D?E-p+ain the difference bet4een a constant and a variab+e. LM .onstant1= 4) Eou use ,3e Cons, s,a,emen, ,o declare a cons,an, and se, i,s value1 2) B/ declaring a cons,an,: /ou assign a meaning0ul name ,o a value1 7) #nce a cons,an, is declared: i, canno, *e modi0ied or assigned a new value1 Variab+e1=

Navgu+ara, BCA

Page CC o0 56

Advanced Visual and Windows Programming(BCA-205) 4) )/m*olic names given ,o values s,ored in memor/ and declared wi,3 ,3e =im 9e/word1 2) #nce a Varia*le is declared: i, can *e modi0ied or assigned a new value1 For e-a*p+e1= (0 we 3ave declared a varia*le named ,em.era,ure as an in,eger ,/.e: /ou can s,ore in,eger values li9e B2 or C7 in i,1 DAWhat is the p)rpose of the .Int f)nction K the .Dec F)nction? LM .Int1= "3e .ur.ose o0 ,3e C(n, 0unc,ion is ,o conver, ,o (n, da,a ,/.e1 .Dec1= "3e .ur.ose o0 ,3e C=ec 0unc,ion is ,o conver, ,o decimal da,a ,/.e1 DB What state*ent5s6 can be )sed to dec+are a variab+e? LM "3e =im s,a,emen, can *e used ,o declare a varia*le1 E-a*p+e1= =im s,a,e as in, DCWhat is a *essa(e bo- and 4hen sho)+d yo) )se one? LM'essage*o; is an eas/ wa/ ,o add mul,i.le 0orms alread/ *uil, in visual *asic 1We can also use ,3e message*o; *uil, in,o ,3e 1ne, 0ramewor9 ,o dis.la/ message and acce., in.u, 0rom ,3e user1 DI E-p+ain 4hy the 'essa(eBo-.Sho4 *ethod has *)+tip+e si(nat)res. LM 'essageBo;1)3ow me,3od 3as mul,i.le signa,ure ,o c3oose 0rom 'essageBo;1)3ow("e;, message) 'essageBo;1)3ow("e;, message: "i,le*ar,e;,) 'essageBo;1)3ow("e;, message: "i,le*ar,e;,: S'essgae *o;*u,,ons) 'essageBo;1)3ow("e;, message: "i,le*ar,e;,: S'essgae *o;*u,,ons: 'essage *o; icon) DD Why *)st yo) )se *od)+e=+eve+ variab+es if yo) 4ant to acc)*)+ate a r)nnin( tota+ of transactions? LM'odule level varia*les are accessi*le 0rom all .rocedures o0 a 0orm1 EGWhat is a condition? LM "3is is .reliminar/ documen,a,ion and is su*+ec, ,o c3ange1 Con,ains ,/.e-s.eci0ic in0orma,ion 0or e00ec,s ,3a, are mar9ed as =(%&"SC#N=("(#N1A re0erence ,o an arra/ o0 =icondi,ion s,ruc,ures 0or an e00ec, is .assed in ,3e l.v"/.e).eci0icParams mem*er o0 ,3e =ie00ec, s,ruc,ure1 "3e num*er o0 elemen,s in ,3e arra/ mus, *e ei,3er one: or eAual ,o ,3e num*er o0 a;es associa,ed wi,3 ,3e e00ec,1 Definition Vis)a+ Basic Pu*lic ),ruc,ure Condi,ion .o*p)terN .u*lic s,ruc, Condi,ion 'ana(ed .;; .u*lic SSvalue s,ruc, Condi,ion 3Script (n )cri.,: /ou can use s,ruc,ures: *u, /ou canno, de0ine /our own1 Navgu+ara, BCA Page C5 o0 56

Advanced Visual and Windows Programming(BCA-205)

E8E-p+ain the p)rpose of %e+ationa+ and "o(ica+ operators. LM %e+ationa+ operator1= A rela,ion 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- N($ess ,3an) P"rueF(0 o.erand4 is less ,3an o.erand 21 - NF($ess ,3an or eAual ,o)-"rueF (0 o.erand4 is less ,3an or eAual ,o o.erand 21 - O(Grea,er ,3an)-"rueF (0 o.erand4 is grea,er ,3an o.erand 2 - OF(Grea,er ,3an or eAual ,o)-"rueF (0 o.erand4 is grea,er ,3an or eAual ,o o.erand 2 - F(%Aual ,o)-"rueF (0 o.erand4 is eAual ,o o.erand 2 - NO(No, eAual ,o)-"rueF (0 o.erand4 is no, eAual ,o o.erand 2 - $i9eFPer0orms s,ring .a,,ern ma,c3ing1 - (s - "rueF(0 ,wo o*+ec, re0erences re0er ,o ,3e same o*+ec,1 "o(ica+ operator1= $ogical o.era,or com.are Boolean e;.ression and re,urn a Boolean resul,1 (n s3or,: logical o.era,or are e;.ression w3ic3 re,urn "rue or 0alse resul, over a condi,ional e;.ression1 - And-- Per0orms an And o.era,ion1 - No,-- !everse ,3e logical value o0 i,s o.erand 0rom "rue ,o 0alse and 0alse ,o ,rue1 - #r-- Per0orms an #r o.era,ion1 - @or-- Per0orms an e;clusive or o.era,ion1 - And also-- #.era,or A Ts3or, circui,ed T And o.era,or Qi0 ,3e 0irs, o.erand is 0alse:,3e second o.erand is no, ,es,ed1 - #r%lse-- #.era,or A Ts3or, circui,ed T #r o.era,or Qi0 ,3e 0irs, o.erand is ,rue:,3e second o.erand is no, ,es,ed1

EA6 E-p+ain a Boo+ean variab+e test for Tr)e and Fa+se. /ive an e-a*p+e. LM Boo+ean varia*les are s,ored as 46-*i, (2-*/,e) num*ers: *u, ,3e/ can onl/ *e Tr)e or Fa+se1 Use ,3e 9e/words Tr)e and Fa+se ,o assign one o0 ,3e ,wo s,a,es ,o Boo+ean varia*les1 W3en numeric da,a ,/.es are conver,ed ,o Boo+ean values: 0 *ecomes Fa+se and all o,3er values *ecome Tr)e1 W3en Boo+ean values are conver,ed ,o numeric ,/.es: Fa+se *ecomes 0 and Tr)e *ecomes -41 EB6 What is separator bar and ho4 is it created? LM)e.ara,or *ars are used ,o grou. rela,ed commands wi,3in a menu and ma9e menus easier ,o read1 To add a separator bar as a *en) ite*

Navgu+ara, BCA

Page 50 o0 56

Advanced Visual and Windows Programming(BCA-205) (n ,3e 'enu =esigner: rig3,-clic9 ,3e loca,ion w3ere /ou wan, a se.ara,or *ar: and c3oose

New )e.ara,or1 -orW3en se,,ing ,3e Te-t .ro.er,/ (ei,3er in ,3e Pro.er,ies window: in ,3e 'enu =esigner: or in code) o0 ,3e menu i,em: en,er a das3 (P) ,o ma9e ,3a, menu i,em a se.ara,or *ar1

EI6 E-p+ain the difference bet4een s)b proced)re and f)nction proced)re. LM S)b proced)re1= 4) A .rocedure ,3a, does no, re,urn a value1 2) (n su* .rocedure we use su* 9e/word1 7) (n su* .rocedure i,s ending done wi,3 T%nd su*U F)nction proced)re1= 4) A .rocedure ,3a, re,urns a value1 2) (n 0unc,ion .rocedure we use &unc,ion 9e/word1 7) (n 0unc,ion .rocedure i,s ending done wi,3 T%nd 0unc,ionU1

@)estions
41 21 (. ). *. 61 ,. C1 51 401 441 #hat are ob$ects and properties% &ow are the" related to each other% #hat is the p rpose of these vis al basic file t"pes' .sln!.s o!.vb% #hat is the p rpose of the name propert" of a control% #hat is the p rpose of the text propert" of a b tton% #hat is the p rpose of the text propert" of a form% #hat is vis al basic event% +ive example of events% #hat is the p rpose of ke"board access ke"s% &ow can "o define access ke" in "o r pro$ect% Explain se of accept b tton and cancel b tton properties of the form #hat is a tooltip%how can "o make a tool tip appear% Name and give example of the data t"pes of vb.

Navgu+ara, BCA

Page 54 o0 56

Advanced Visual and Windows Programming(BCA-205) #hat is p rpose of cint f nctions% #hat statements are sed to declared variable% #hat is message box and how it is sed% Explain the relational and logical operators &ow does vis al basic compare the text propert" of a text box% .ist different t"pes of pro$ects in vis al basic .net. &ow to add items in combo box at r ntime% #rite The 1e2 ence 3f Events #hen Form #ill 4e .oaded% +ive the s"ntax to create ser define data t"pes in vb .net. Explain an" three control str ct re of 74 .net with example. Explain 8iff. Mod le available in 74 .net Explain 9ich Textbox with at least Five :roperties ; 5 Methods. .ist elements of 7is al 4asic .net I8E. +ive the different states in vis al basic .net . .ist vis al basic .net n meric data t"pes. #rite s"ntax to generate context men . +ive different t"pes of combo box. Explain different string formatting f nctions with example Explain .ist view control with example #hat Is Event 8riven :rogramming% #hat Is 8ifference 4etween Mod le =nd >lass Mod le% #hat Is 8efa lt :ropert" 3f Textbox =nd >ombo 4ox >ontrol% #hen :aint Event 3f Form #ill 4e >alled% Explain Feat res 3f 7is al 4asic .net. #hat is se of :reserve ke"word% +ive extension of different files created in 74 .net. 8efine propert" and events. #hat is se of strict! compare and explicit ke"words% &ow b ttons can be loaded at r ntime% >reate f nction to find s m of two n mbers which will ret rn s m and take two n mbers as parameters. )5. Explain scope of variable in vis al basic .net. )(. .ist Editions of 7is al 4asic .net Explain Fixed 1i?e =rra" 421 471 481 451 461 -,. -/. -0. 56. 5-. 55. 5(. 5). 5*. 5<. 5,. 5/. 50. (6. (-. (5. ((. (). (*. (<. (,. (/. (0. )6. )-.

Practica+ @)estions1
41 Crea,e a..lica,ion 0or no,e.ad w3ic3 3as 0ollowing menu a1 &ile i1 New ii1 #.en iii1 )ave Navgu+ara, BCA Page 52 o0 56

Advanced Visual and Windows Programming(BCA-205) iv1 )ave as v1 %;i, *1 %di, i1 Cu, ii1 Co./ iii1 Pas,e c1 &orma, i1 &on, ii1 Color Crea,e a..lica,ion in w3ic3 ,3ere are ,wo lis, *o;es and 0or command *u,,on w3ic3 3as 0acili,/ ,o s3i0, one elemen, or more elemen,s 0rom lis,4 ,o lis, 2 and viceversa1Also ,3ere are ,3ree command *u,,on 0or eac3 lis, *o; ,o add new i,emLs: dele,e selec,ed i,emLs and ,o sor, i,em o0 eac3 lis,1 Crea,e a..lica,ion ,o 0orma, ,e;,*o; using scroll *ar1 Use se.ara,e scroll*ar 0or eac3 0orma,,ing1&orma,ing are as under a1 &on, siDe(increase and decrease) *1 &oreground color c1 Bac9 ground color Crea,e class li*rar/ 0or calcula,or1 W3ic3 3as ,wo .ro.er,ies 0or o.erand4 and o.erand21i, s3ould 3ave 0our me,3ods as add :dele,e: su*,rac, and mul,i.l/1 >reate application to displa" greetings in message box. two textbox to enter val es and three command b ttons. ,. >reate applications for calc lator. /. >reate application to find simple interest and compo nd interest. 0. >reate application to change backgro nd color and for gro nd color of textbox b" selecting color from list box. -6. etc. --. -5. -(. >reate application to displa" m ltiplication table of an" no >reate application to find reverse length of string and also >reate application to find intital of name . Ex ' 8r. entered from text box. find that string is palindrome or not. :rathamesh 9amaniklal 7"as . =ns ' 8r. :.9. 7"as. >reate application to displa" date and time in text box and displa" appropriate greeting . Ex ' +ood morning ! good noon

21

71

81 *.

<. >reate application to find area of s2 are !circle! Triangle. @se

Navgu+ara, BCA

Page 57 o0 56

Advanced Visual and Windows Programming(BCA-205) -). >reate application for pa"roll that is enter name and basic

salar" of emplo"ee and create whole salar" slip.


-*. >reate application for notepad.#hich -. Men bar AFile!Edit!FormatB have following facilities.

-<.

>reate application to change backgro nd color of b tton b" scrolling the scroll bar. >reate application to set the indent of the text sing slider. >reate =ctiveC application for stopwatch. >reate form which will work like font foramating dilog box. >reate =ctiveC control for the animation of backgro nd color.

-,. -/. -0. 56.

5-. >reate application for :hone 8irector" :honeAphDno! name! address! cit"! districtB -. =ddition! deletion and modification of an" entr". 55. >reate application for :hone 8irector" :honeAphDno! name! address! cit"! districtB -. Make search criteria based on name and phone n mber. 5. >reate report of that search. 5(. >reate application for the cinema ticket booking s"stem. >inemaAfilmDid! filmDname! thDid! 1howTime!B bookAticketDid! filmDid! rate! bookB -.>reate search form in which ser has to give the choice for film in combobox. It sho ld displa" the ticket stat s of that film in datagrid. 5). >reate application for the cinema ticket booking s"stem. >inemaAfilmDid! filmDname! thDid! 1howTime!B bookAticketDid! filmDid! rate! bookB

Navgu+ara, BCA

Page 58 o0 56

Advanced Visual and Windows Programming(BCA-205)


-. create form to book the ticket. 5*. >reate appliction for train sched ling TrainAtrainDno!trainDname!so rce!destB 1ched leAtrainDno!date!timeB -.make search for the train timings between two dates 5<. >reate appliction for train sched ling TrainAtrainDno!trainDname!so rce!destB 1ched leAtrainDno!date!timeB -.create the trainwise report 5,. >reate inventor" s"stem for the small vendor. ItemAitemDid!itemDname!cp!spstockB 1aleAitemDid!date!2 antit"B -.create itemwise search form.res lt sho ld be displa"ed in flexgrid. 5.generate report for the da"wise sale. 5/. create st dent information s"stem. 1t dentAgrno!st dDname!dob!age!lastschool!fname!address!cit"!phoneB -.create admission form of the st dent. +rno m st be generated b" the s"stem. 5.generate report of the st dent for specific "ear.

50.

>reate application for online examination for an" s b$ect.

-.+ive res lt at the end of the test 5.+enerate report of the serwise test res lt. (6. >reate an application for a bank. =>>D8ET=I.A=>DN3!8=TE!3D4=.!>D4=.B >reate form for withdraw mone" from bank. >reate report for da"wise transaction.

Navgu+ara, BCA

Page 55 o0 56

Advanced Visual and Windows Programming(BCA-205)

Navgu+ara, BCA

Page 56 o0 56

You might also like