Download as RTF, PDF, TXT or read online from Scribd
Download as rtf, pdf, or txt
You are on page 1of 17
February 2011
Bachelor of Computer Application (BCA) Semester 5
BC0053 B! "et # $%& ' Cre(its Assi)nment Set 1 ('0 %ar*s) Ques1. Describe the following: i) Code Editor Window ii) Solution Explorer Ans. (i) Code Editor Window: The Code Editor Window, Shown in Figure create and edit visual Basic source code. After you have designed the user interface for your proect !y placing controls on the for", you#ll turn to the Code Editor to develop the $isual Basic state"ents that "a%e the controls functional. The easiest way to call up the Code Editor is to dou!le&clic% a control. Then, you can !egin typing the $isual Basic state"ents that will !e e'ecuted when the user perfor"s the "ost co""on action on that control. (f you dou!le&clic% on a !utton, for e'a"ple, you can enter the state"ents that will !e e'ecuted when the user clic%s on that !utton. The Code Editor wor%s "uch li%e other te't editors you#ve wor%ed with. )owever, the Code Editor has a nu"!er of special features that si"plify the tas% of editing $isual Basic code. For e'a"ple, color is used to distinguish $isual Basic *eywords fro" varia!les, co""ents, and other language ele"ents. And "any types of coding errors are auto"atically highlighted as you type so you can correct the". Description + The Code Editor window is where you create and edit the $isual Basic code that your application re,uires. The Code Editor wor%s "uch li%e any other te't editor you have used, so you shouldn#t have "uch trou!le learning how to use it. + -ou can display the Code Editor !y dou!le&clic%ing the for" or one of the controls in the For" .esigner window. /r, you can clic% the view Code Button in the Solution E'plorer. + /nce you#ve opened the Code Editor, you can return to the For" .esigner !y clic%ing the 0.esign) ta! at the top of the Code Editor or the $iew .esigner !utton in the solution E'plorer 0to the right of the $iew Code !utton). -ou can also "ove a"ong these windows !y pressing Ctrl1Ta! or Shift1Ctrl1Ta!. + (t#s i"portant to reali2e that the For" .esigner and the Code Editor do not represent two different files, instead they provide you with two views of the sa"e $isual Basic source file. The For" .esigner gives you a visual representation of the for" that is i"ple"ented !y your $isual Basic code. The Code Editor lets you edit the code for the for". Ques. Describe the oper!tors !nd const!nts" s#$bols in %isu!l &!sic.'et Ans. There are various types of operators in $isual Basic, and (3ll go over the" all here. )ere are the Arith"etic operators 0for e'a"ple, the e'pression 4 1 5 yields a value of ()6 + ) E'ponentiation + 7ultiplication 8 * .ivision + + (nteger division + ,od 7odulus + - Addition + &Su!traction These are the Assign"ent operators 0for e'a"ple, te$per!ture . / stores the value / in the varia!le te$per!ture)6 + . Assign"ent + ). E'ponentiation followed !y assign"ent + 0. 7ultiplication followed !y assign"ent + *. .ivision followed !y assign"ent + +. (nteger division followed !y assign"ent + -. Addition followed !y assign"ent + 1. Su!traction followed !y assign"ent + 2. Concatenation followed !y assign"ent )ere are the Co"parison operators 0these values yield true or false values9for e'a"ple, 3 4 5 yields a value of 6rue)6 + 7 0:ess than)96rue if operand1 is less than operand2 + 7. 0:ess than or e,ual to)96rue if operand1 is less than or e,ual to operand2 + ; 0<reater than)96rue if operand1 is greater than operand2 + 4. 0<reater than or e,ual to)96rue if operand1 is greater than or e,ual to operand2 + . 0E,ual to)96rue if operand1 e,uals operand2 + 7 4 0=ot e,ual to)96rue if operand1 is not e,ual to operand2 + 8s96rue if two o!ect references refer to the sa"e o!ect + 9i:e9>erfor"s string pattern "atching These are the String Concatenation operators 0for e'a"ple, ?;i ?2 ? there ? yields the string ?)i there?.)6 + 2 String concatenation + - String concatenation These are the :ogical@Bitwise operators, where bitwise "eans wor%ing !it !y !it with nu"erical values. These types of operators can wor% on logical values 0for e'a"ple, if bln%!lue1 is set to 6rue and bln%!lue is set to <!lse, then bln%!lue1 =r bln%!lue returns a value of 6rue) or nu"!ers for !itwise operations, which wor% on their operands !it !y !it 0for e'a"ple, if int%!lue1 is set to A and int%!lue is set to B, then int%!lue1 =r int%!lue yields C)6 + And> >erfor"s an And operation 0for logical operations6 6rue if !oth operands are 6rue, <!lse otherwiseD the sa"e for !it&!y&!it operations where you treat ? as <!lse and 1 as 6rue). + 'ot> Eeverses the logical value of its operand, fro" 6rue to <!lse and <!lse to 6rue, for !itwise operations, turns ? into 1 and 1 into ?. + =r> /perator perfor"s an =r operation 0for logical operations6 6rue if either operand is 6rue, <!lse otherwiseD the sa"e for !it&!y&!it operations where you treat ? as <!lse and 1 as 6rue). + @or> /perator perfor"s an exclusiAe1=r operation 0for logical operations6 6rue if either operand, !ut not !oth, is 6rue, and <!lse otherwiseD the sa"e for !it&!y&!it operations where you treat ? as <!lse and 1 as 6rue). + AndAlso> /perator A ?short circuited? And operatorD if the first operand is <!lse, the second operand is not tested. + =rElse> /perator A ?short circuited? =r operator, if the first operand is 6rue, the second is not tested. Const!nt or S#$bols: Constants values once defined cannot !e changed in the progra". Constants are declared using Const %eyword, li%e6 .i" Const >( As .ou!le F C.B5A Constants "ust !e initiali2ed as they are declared. .i"$onst 7AE*S As (nteger (t is a notation convention to use capital letters while na"ing constants. QuesB. Write ! progr!$ to print the d!# of the wee: t!:ing the input of nu$bers 1 to / !s input using Select... C!se st!te$ent. Ans. Su! 7ain0) di" n as integer F Syste".console.readline0) select case n case B Console.writeline0?Sunday?) case A Console.writeline0?7onday?) case C6 Console.writeline0?Tuesday?) case 56 console.writeline0?Wednesday?) case 46 console.writeline0?Thursday?) case G6 console.writeline0?Friday?) case H6 console.writeline0?Saturday?) case else Console.writeline0?Wee% has only H days?) end select end su! Ques5. Design ! for$ b!sed !pplic!tions using l!bels" text boxes" !nd buttons to perfor$ b!sic !rith$etic oper!tions on integers. Ans. Set 6he Croperties: Control Cropert# :a!el B Caption6 First =o. :a!elA Caption6 Second =o. Te't6 0e"pty) Te't!o'A Te't6 0e"pty) =a"e6 C"dadd Co""andA Caption6 SIB =a"e6 C"dsu! Co""andC Caption6 7I: =a"e6 C"d"ul Co""and5 Caption6 .($ =a"e6 C"ddiv Co""and4 Caption6 EJ(T =a"e6 C"dEJ >rivate Su! For"B K:oad0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles 7yBase.:oad End Su! >rivate Su! C"dadd KClic%0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles C"dadd.Clic% Te'tBo'C.Te't F $al0Te'tBo'B.Te't) 1 $al0Te'tBo'A.Te't) End Su! >rivate Su! C"dsu! KClic%0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles C"dsu!.Clic% Te'tBo'C .Te't F $al0Te'tBo'B .Te't) & $al0Te'tBo'A.Te't) End Su! >rivate Su! C"d"ul KClic%0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles C"d"ul.Clic% Te'tBo'C.Te't F $al0Te'tBo'B.Te't) L $al0Te'tBo'A.Te't) End Su! >rivate Su! C"ddiv KClic%0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles C"ddiv.Clic% Te'tBo'C.Te't F $al0Te'tBo'B.Te't) @ $al0Te'tBo'A.Te't) End Su! >rivate Su! C"de' KClic%0By$al sender As Syste"./!ect, By$al e As Syste".EventArgs) )andles C"de'.Clic% End End Su! End Class Ques3. Describe the concept of Exceptions in .'et enAiron$ent Ans. .=ET i"ple"ents a syste"wide, co"prehensive approach to e'ception handling. As noted in the chapter introduction, instead of an error number, there is an exception object. This o!ect contains infor"ation relevant to the error, e'posed as properties of the o!ect. :ater you#ll see a su""ary of the properties and the infor"ation they e'pose in a ta!le. Such an o!ect is an instance of a class that derives fro" a class na"ed Syste".E'ception. As shown later, a variety of su!classes of Syste".E'ception are used for different circu"stances. ("portant >roperties and 7ethods of an E'ception The E'ception class has properties that contain useful infor"ation a!out the e'ception, as shown in the following ta!le6 Cropert# Description )elp:in% A string indicating the lin% to help for this e'ception (nnerE'ception Eeturns the e'ception o!ect reference to an inner 0nested) e'ception 7essage A string that contains a description of the error, suita!le for displaying to users Source A string containing the na"e of an o!ect that generated the error Stac%Trace A read&only property that holds the stac% trace as a te't string. The stac% trace is a list of the pending "ethod calls at the point at which the e'ception was detected. That is, if 7ethodA called 7ethodB, and an e'ception occurred in 7ethodB, the stac% trace would contain !oth 7ethodA and 7ethodB. TargetS ite A read&only string property that holds the "ethod that threw the e'ception The two "ost i"portant "ethods of the E'ception class are as follows6 ,ethod Description <etBaseE'ception Eeturns the first e'ception in the chain ToString Eeturns the error string, which "ight include as "uch infor"ation as the error "essage, the inner e'ceptions, and the stac% trace, depending on the error February 2011 Bachelor of Computer Application (BCA) Semester 5 BC0053 B ! "et # $%& ' Cre(its Assi)nment Set 2 ('0 %ar*s) Ques1. Describe the process of !dding !nd upd!ting records with !n ex!$ple in %& .net D Ans. (n the last section, you learned how to "ove through the records in your .ataSet, and how to display the records in Te't!o'es on your for". (n this lesson, we#ll see how to add new records, how to delete the" and how to Ipdate a records. Before we start the coding for these new !uttons, it#s i"portant to understand that the .ataSet is disconnected fro" the data!ase. What this "eans is that if you#re adding a new record, you#re not adding it to the data!ase6 you#re adding it to the D!t!SetM Si"ilarly, if you#re updating or .eleting, you are doing it to the .ataSet, and '=6 to the data!ase. After you have "ade all of your changes, you T)E= co""it these changes to the data!ase. -ou do this !y issuing a separate co""and. But we#ll see how it all wor%s. -ou#ll need to add a few "ore !uttons to your for" & five of the". Change the '!$e properties of the new Buttons to the following6 N btnAddNew N btnCommit N btn Update N btnDelete N btnClear Change the 6ext properties of the !uttons to ?Add 'ew Eecord ?, ?Co$$it Ch!nges?, ?Fpd!te Eecord ?, ?Delete Eecord?, and ?Cle!r*C!ncel?. -our for" "ight loo% so"ething li%e this6 0i) Fpd!ting ! Eecord To reference a particular colu"n 0ite") in a row of the .ataSet, the code is this6 ds.6!bles(GAddress&oo:G).Eows().8te$(1) That will return whatever is at (te" B on Eow A. As well as returning a value, you can also set a value. -ou do it li%e this6 ds. Tables("AddressBoo"!."ows(2!.#tem(1! $ "%ane" =ow (te" B Eow A will contain the te't ?Oane?. This won#t, however, affect the data!aseM The changes will ust get "ade to the D!t!Set. To illustrate this, add the following code to your btnFpd!te6 ds. Tables("AddressBoo"!."ows(inc!.#tem(1! $ txt&irstName. Text ds. Tables("AddressBoo"!."ows(inc!.#tem(2! $ txt'urname. Text (s)Box("Data updated"! Eun your progra", and clic% the 'ext Eecord !utton to "ove to the first record. ?Oohn? should !e displayed in your first te't!o', and ?S"ith? in the second te't!o'. Clic% inside the te't!o'es and change ?Oohn? to ?Ooan? and ?S"ith? to ?S"ithy?. 0Without the ,uotes). =ow clic% your Fpd!te Eecord !utton. 7ove to the ne't record !y clic%ing your 'ext Eecord !utton, and then "ove !ac% to the first record. -ou should see that the first record is now ?Ooan S"ithy?. Close down your progra", then run it again. Clic% the 'ext Eecord !utton to "ove to the first record. (t will still !e ?Oohn S"ith?. The data you updated has !een lostM So here, again, is why6 GCh!nges !re $!de to the D!t!Set" !nd '=6 to the D!t!b!seG Try it out. Eun your progra", and change one of the records. Clic% the Fpd!te !utton. Then close the progra" down, and load it up again. -ou should see your new changes displayed in the te't!o'es. 0ii) Add ! 'ew Eecord Adding a new record is slightly "ore co"ple'. First, you have to add a new Eow to the .ataSet, then co""it the new Eow to the .ata!ase. But the Add 'ew Eecord !utton on our for" is ,uite si"ple. The only thing it does is to switch off other !uttons, and clear the te't!o'es, ready for a new entry. )ere#s the code for your Add 'ew Eecord !utton6 btnCommit.*nabled $ True btnAddNew.*nabled $ &alse btnUpdate.*nabled $ &alse btnDelete.*nabled $ &alse txt&irstName. Clear(! txt'urname. Clear(! So three !uttons are switched off when the Add 'ew Eecord !utton is clic%ed, and one is switched on. The !utton that gets switched on is the Co""it Changes !utton. The Ena!led property of btnCo$$it gets set to 6rue. But, for this to wor%, you need to set it to <!lse when the for" loads. So return to your For". Clic% btnCo$$it to select it. Then locate the En!bled >roperty in the >roperties !o'. Set it to <!lse. When the For" starts up, the !utton will !e switched off. The Clear@Cancel !utton can !e used to switch it !ac% on again. So add this code to your !tnClear6 btnCommit.*nabled $ &alse btnAddNew.*nabled $ True btnUpdate.*nabled $ True btnDelete.*nabled $ True inc $ + Na,i)ate"ecords(! We#re switching the Co$$it Ch!nges !utton off, and the other three !ac% on. The other two lines ust "a%e sure that we display the first record again, after the Cancel !utton is clic%ed. /therwise the te't!o'es will all !e !lan%. To add a new record to the data!ase, we#ll use the Co$$it Ch!nges !utton. So dou!le clic% your btnCo$$it to access its code. Add the following6 #- inc ./ 01 T1en Dim cb As New 2leDb.2leDbCommandBuilder(da! Dim dsNew"ow As Data"ow dsNew"ow $ ds. Tables("AddressBoo"!.New"ow(! dsNew"ow.#tem("&irstName "! $ txt&irstName. Text dsNew"ow.#tem("'urname "! $ txt'urname. Text ds. Tables("AddressBoo"!."ows.Add(dsNew"ow! da. Update(ds3 "AddressBoo"! (s)Box("New "ecord added to t1e Database"! btnCommit.*nabled $ &alse btnAddNew.*nabled $ True btnUpdate.*nabled $ True btnDelete.*nabled $ True *nd #- The code is so"ewhat longer than usual, !ut we#ll go through it. The first line is an (f State"ent. We#re ust chec%ing that there is a valid record to add. (f there#s not, the inc varia!le will !e on "inus B. (nside of the (f State"ent, we first set up a Co$$!nd &uilder, as !efore. The ne't line is this6 Dim dsNew"ow As Data"ow (f you want to add a new row to your .ataSet, you need a D!t!Eow o!ect. This line ust sets up a varia!le called ds'ewEow. The type of varia!le is a .ataEow. To create the new .ataEow o!ect, this line co"es ne't6 dsNew"ow $ ds. Tables("AddressBoo"!.New"ow(! We#re ust saying, ?Create a =ew Eow o!ect in the AddressBoo% .ataSet, and store this in the varia!le called ds=ewEow.? As you can see, 'ewEow() is a "ethod of ds.6!bles. Ise this "ethod to add rows to your .ataSet. The actual values we want to store in the rows are co"ing fro" the te't!o'es. So we have these two lines6 dsNew"ow.#tem("&irstName "! $ txt&irstName. Text dsNew"ow.#tem("'urname "! $ txt'urname. Text The ds'ewEow o!ect we created has a >roperty called 8te$. This is li%e the (te" property you used earlier. (t represents a colu"n in your .ataSet. We could have said this instead6 dsNew"ow.#tem(1! $ txt&irstName. Text dsNew"ow.#tem(2! $ txt'urname. Text The 8te$ property is now using the inde' nu"!er of the .ataSet colu"ns, rather than the na"es. The result is the sa"e, though6 to store new values in these properties. We#re storing the te't fro" the te't!o'es to our new Eow. We now only need to call the 7ethod that actually adds the Eow to the .ataSet6 ds. Ta bles("A ddressBoo"!." ows .A dd(dsNew" ow! To add the Eow, you use the Add "ethod of the Eows property of the .ataSet. (n !etween the round !rac%ets, you need the na"e of your .ataEow 0the varia!le ds'ewEow, in our case). -ou should %now what the rest of the code does. )ere#s the ne't line6 da. Update(ds3 "AddressBoo"! Ques. Write ! si$ple @,9 file for student det!ils (sn!$e" sno" sbr!nch" s!ddr) D Ans. college.'"l Pcollege; Pstudent; Pstudent !ranchFQCSEQ; Psna"e firstna"eFQhQ;Ea"aP@sna"e; Psno; BP@sno; Psaddr;)ydera!adP@saddr; P@student; Pstudent; Pstudent !ranchFQECEQ; Psna"e firstna"eFQrQ;sitaP@sna"e; Psno; BP@sno; Psaddr;.elhiP@saddr; P@student; Pstudent; Pstudent !ranchFQEEEQ; Psna"e firstna"eFQpQ;EaniP@sna"e; Psno; BP@sno; Psaddr;>unaP@saddr; P@student; P@college; The root ele"ent in the e'a"ple is Pcollege;. All Pstudent; ele"ents in the docu"ent are contained within Pcollege;. The Pstudent; ele"ent has 5 children6 Psna"e;, P sno;, Ps!ranch;, Psaddr;. QuesB. Wh!t is $e!nt b# D6DD Wh!t !re the building bloc:s of D6D D Ans. .T. is one of the specifications included in to J7:. .T. has its own s"all set of constructs and gra""ar rules that helps us to prepare our "ar%up language specifications. That is the constructs of .T. are understood !y the J7: parsers that can help our "ar%up language i"ple"entation application. .T. file contains the building bloc:s 0i.e. tags) of an J7: file. The !uilding !loc%s of J7: docu"ent are6 B. Ele"ents 0Tags) A. Attri!utes C. Entities 5. >C.ATA 4. C.ATA Ques5. Expl!in @,9 '!$esp!ces with !n ex!$ple. Ans. =a"espace allows us to define the ele"ents and attri!utes with a uni,ue identification. This is si"ilar to pac%ages concept we have in ava This allows defining the ele"ents in different JS. docu"ents and references the" uni,uely. Ex!$ple 1: Pstaff; Pna"e;haiP@na"e ; Pdept; Pna"e;helloP@na"e ; P@dept; Proo";C4 4C GP@roo"; P@staff; (n this e'a"ple we have two ele"ents called n!$e !ut they each represent different things and have different "eanings. Applications confuse these two ite"s, thus rendering the whole J7: docu"ent useless. (n a s"all docu"ent that is not a pro!le" as you can si"ply invent a new na"e for one of the ele"ents. For large organi2ations there are "ore nu"!er of J7: Sche"as, for this purpose we use the concept called n!$esp!ces. Ex!$ple: '!$e Conflicts (n J7:, ele"ent na"es are defined !y the developer. This often results in a conflict when trying to "i' J7: docu"ents fro" different J7: applications. This J7: carries infor"ation a!out a co"pany 0e"p details)6 Pco"pany; Peno; BP@eno; Pena"e;)elloP@ena"e; P@co"pany; This J7: carries infor"ation a!out a co"pany 0dept details)6 Pco"pany; Pdno; B AC54P@dno; Pdna"e;co"putersP@dna"e; P@co"pany; (f these J7: frag"ents were added together, there would !e a na"e conflict. Both contain a Pco"pany; ele"ent, !ut the ele"ents have different content and "eaning. Solving the =a"e Conflict Ising a >refi' =a"e conflicts in J7: can easily !e avoided using a na"e prefi'. This J7: carries infor"ation a!out an e"p and dept6 Pe6co"pany; Pe6eno;BP@e6eno; Pe6ena"e;)elloP@e6ena"e; P@e6co"pany; Pd6co"pany; Pd6dno; B AC54P@d6dno; Pd6dna"e;co"putersP@d6dna"e; P@d6 co"pany; (n the e'a"ple a!ove, there will !e no conflict !ecause the two Pco"pany; ele"ents have different na"es. J7: =a"espaces & The '"lns Attri!ute When using prefi'es in J7:, a so&called na"espace for the prefi' "ust !e defined. The na"espace is defined !y the '"lns attri!ute in the start tag of an ele"ent. Ques3. Write ! progr!$ th!t uses the node%!lue propert# to ch!nge the text node of the first 7sn!$e4 ele$ent in Gcollege.x$lH. Ans. Pht"l; Phead; Pscript typeF?te't@avascript? srcF?load'"ldoc. s?; P@script; P@head; P!ody; Pscript typeF?te't@avascript?; '"l.ocFloadJ7:.oc0?college.'"l?)D 'F'"l.oc.getEle"entsByTag=a"e0?sna"e?)RSTD docu"ent. write 0'"l.oc.docu"entEle"ent.node=a"e)D docu"ent. write 0?P!r @;?)D docu"ent.write0'"l.oc.docu"entEle"ent.nodeType)D P@script; P@!ody; P@ht"l; =utput : College.'"l B
Chatlog 2-22-14 To 4 - 27 - 14 - Weekend Performance Tuning - Analyzing With DBA Skillsets - Every Sat - Sun 10 - 00 Am To 5 - 00 PM 2014-04-19 13 - 58