of 16
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
  ArguS academy  V.B-PART-III Page 1   Exception Handling An exception is a response to an abnormal or unexpected condition occurring in a program in a program, due to which the execution of a program may be aborted. To avoid the abrupt termination of the program, the exception is generally “caught” and “handled” appropriately. Code is written such that in case an exception occurred, alternative action is taken i nstead of aborting the program abruptly. VB.Net used a structured mechanism to handle exceptions- the try …catch…end try block.  Module mtry Sub main() Dim a as integer=9 Dim b as integer Dim c as integer Try c=a/b System.Console.WriteLine(c) Catch s as System.Exception System.Console.WriteLine(“Error ….divide by zero”)  End try End sub End module When keyword Module mtry1 Sub main() Dim a as short Dim b as short Dim c as decimal System.Console.WriteLine(“Enter values of a and b”)  a=System.Console.ReadLine() b= System.Console.ReadLine() try c=a/b System.Console.WriteLine(c) Catch s as System.Exception when b=0 System.Console.WriteLine(“Error…..divide by zero”)  Finally System.Console.WriteLine(“End of main”)  End try End sub End module Multiple catch block There can be multiple catch blocks in one Try…End Try block. The order in which these catch statements are placed is very important. If a catch with a generic exception is placed right at the beginning followed by specific exception handlers, the specific exception handlers will never be executed as the generic exception handler will be executed first. Option Strict on Module trym Sub main() Dim a as short Dim b as long a=5000 b=50000 try a=CType(b,Short) System.Console.WriteLine(a) Catch s as System.OverflowException System.Console.WriteLine(“Error…..value exceeds range of short”)  Catch s as System.Exception System.Console.WriteLine(“Exception Occured”)  System.Console.WriteLine(s) End try End sub End module  ArguS academy  V.B-PART-III Page 2   Finally The finally Keyword is optionally used with the Try ….Ent try Block when an action wh en an action has to be carried out regardless of whether an exception occurred or not. If the exception occurs, the control is transferred to the catch block wherein the statements enclosed within are executed. The control is then passed onto the finally statement. Module trym12 Sub main() Dim a as integer Dim b as integer Dim c as integer System.Controle.WriteLine(“Enter value of a and b”)  a=System.Console.ReadLine() b=System.Console.ReadLine() try c=a/b System.Console.WriteLine(c) Catch s as System.Exception System.Console.WriteLine(“Error…divide by zero”)  Finally System.Console.WriteLine(“End of main”)  End Try End sub End module Enumeration Enumeration are used when we need to refer to values of primitive types such as byte, short, integer and long as constants or literals Module m1 Enum cities as short Ranchi Bokaro Dhanbad Jamshed Pur End Enum Sub main() System.Console.WriteLine(cities.Dhanbad) End sub End module E.g.-ii Enum Grade as Byte A=100 B=80 C=70 D=60 E=40 End Enum Module m12 Sub main() Dim gradevalue as byte System.Console.WriteLine(“Choose one of the values: 40/60/70/80/100”)  Gradevalue=System.Console.ReadLine() Select case gradevalue Case grade.A System.Console.WriteLine(“You got an A”)  Case grade.B System.Console.WriteLine(“You got an B”)  Case grade.C System.Console.WriteLine(“You got an C”)  Case grade.D System.Console.WriteLine(“You got an D”)  Case grade.E  ArguS academy  V.B-PART-III Page 3   System.Console.Writ eLine(“You got an E”)  Case Else System.Console.WriteLine(“Wrong Choice”)  End select End sub End Module Structure A structure is a composite user-defined data type using which we can group data of different data types together. A structure is useful when we wish to create a record-like structure for an entity. A structure can hold not only fields but also methods, properties and events. Module m12 Public structure book Public title as string Public author as string Public pages as integer Public price as single End structure Sub main() Dim b as new book() System.Console.WriteLine(“Enter Book Title”)  b.title=System.Console.ReadLine() System.Console.WriteLine(“Enter Author Name”) System.Console.WriteLine(“Enter Page”) System.Console.WriteLine(“Enter Price”)  b.price=System.Console.ReadLine() System.Console.WriteLine(“Book Title ”&b.title)   System.Console.WriteLine(“Author Name “&b.auth or) System.Console.WriteLine(“Page “&   System.Console.WriteLine(“Price “&b.price ) Ens sub End module Array within structures Module m123 Public structure x Public arr() as integer End structure Sub main() Dim obj as x Redim obj.arr(1) obj.arr(0)=155 obj.arr(1)=200 System.Console.WriteLine(“1 st   Values ”& obj.arr(0))   System.Console.WrteLine(“2 nd   Values ”& obj.arr(1))  End sub End module Procedures within Structure In addition to data members, a structure can also define functions and procedures within its declaration Module m123 Structure stud Public name as string Public rollno as integer Public sub accept()  ArguS academy  V.B-PART-III Page 4   System.Console.WriteLine(“Enter Name ”)  name=System.Console.ReadLine() System.Console.WriteLine(“Enter Roll No”)  rollno=System.Console.ReadLine() end sub end structure sub main() dim s as stud s.accept() System.Console.WriteLine(“The student details are”)  System.Console.WriteLi ne(“Name ” &   System.Console.WriteLine(“Roll No ” &s.rollno)  End sub End Module Structure within structure A structure can be declared within another structure. This can be useful when a structure contains a composite data type as it member. Module m321 Structure dateofbirth Public day as integer Public month as integer Public year as integer End structure Structure stud Public name as String Public rollno as integer Public dob as dateofbirth Public sub accept() System.Console.WriteLine(“enter name”)  name=System.Console.readLine() System.Console.WriteLine(“enter roll no”)  rollno=System.Console.readLine() end sub public void acceptdob() System.Console.WriteLine(“enter day”) System.Console.WriteLine(“enter month”)  dob.month=System.Console.readLine() System.Console.WriteLine(“enter year”)  dob.year=System.Console.readLine() end sub end structure sub main() dim s as stud s.accept() s.acceptdob() System.Console.WriteLine(“The Student details are”)   System.Console.WriteLine(“Student Name ”&   System.Console.WriteLine(“Roll No ” &s.rollno)   System.Console.WriteLine(“Date ” & & ”/”)   System.Console.WriteLine(“Month ” & s.dob.month & ”/”)   System.Console.WriteLine(“Year ” & s.dob.year & ”/”)  End sub End module Object oriented programming Object oriented programming (oop) is based on a real world interpretation of programming elements. It is a type of programming in which programmers define not only the data elements but also the operations that can be performed on the data elements. An object is an entity consisting of data as well as actions.

Jul 23, 2017


Jul 23, 2017
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks