• Save
Vb net xp_04
Upcoming SlideShare
Loading in...5
×
 

Vb net xp_04

on

  • 816 views

 

Statistics

Views

Total Views
816
Views on SlideShare
802
Embed Views
14

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 14

http://niitcourseslides.blogspot.in 14

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Vb net xp_04 Vb net xp_04 Presentation Transcript

  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETObjectivesIn this lesson, you will learn to:Identify the different types of procedures in VisualBasic .NETIdentify the importance of procedure overloadingIdentify the importance of procedure overridingImplement the MsgBox( ) functionImplement the CommonDialog classes©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 1 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProceduresAre sets of one or more program statements that can beexecuted by referring to the procedure name.Are the key to modular programming. They simplify the task of maintaining and debugging the application code.Are useful for performing repetitive tasks, such as fetching specific records from a database, and text and controlmanipulation.Are of three types:  Sub procedures  Function procedures  Property procedures©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 2 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSub ProcedureIs a block of code enclosed within the Sub and End Substatements.Does not return a value. However, it can take arguments, such as constants, variables, and expressions that are passed to it by the calling code. Example Public Sub Check_Acct_Status (ByValCustAcct As Integer, ByVal Amount As Single) ’The statements of the Sub procedure are given here. End Sub©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 3 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSub Procedure (Contd.) Can be defined in a module, a class, or a structure. Can be created with one of the following access modifiers:  Public  Protected  Friend  Protected Friend  Private©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 4 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSub Procedure (Contd.) Can take arguments. You declare each argument by specifying the argument name and the data type. Can have an optional argument. An optional argument must be declared at the end of the argument list and must have a default value. Can be called by using the Call keyword and providing values for all the arguments that are not optional. You can pass arguments to a sub procedure either by value or by reference. Can be further categorized as:  General procedures  Event-handling procedures©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 5 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSub Procedure (Contd.) General procedure  Is a block of code that performs a specific task. Event-handling procedure  Is a block of code that is executed when a specific event occurs, such as the click of a button or the loading of a form in the memory.  Is a combination of the object name and the type of event that has occurred.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 6 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETFunction ProcedureIs a block of code enclosed within the Function and End Function statements.Returns a value to the calling code. Example Public Function Check_Acct_Status (ByValCustAcct As Integer, ByVal Amount As Single) As Integer The statements of the Sub procedure are given here. Return Amount End Function©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 7 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETFunction Procedure (Contd.) Can be defined in a module, a class, or a structure. Can be created with one of the following access modifiers:  Public, Protected, Friend, Protected Friend, and Private. Has Public access by default. Uses the Return statement to return a value to the calling procedure. Return value can be trapped by calling a function and assigning the return value of the function to a variable. Example TotalAmount = Calculate_Amount(Total_Salary,months)©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 8 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProperty ProcedureIs a set of code statements that are used to assign orretrieve the values of the properties declared within amodule, a class, or a structure.Is a type of variable that stores the values of an object of a class or a structure.Can help you define a property as read-only, write-only, or read/write type.Is of two types:  Get procedures are used to retrieve the values from a property.  Set procedures are used to assign values to a property.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 9 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProperty Procedure (Contd.)Is always invoked implicitly by the code that refers to the property, that is, the code uses the name of the property and provides values for all the arguments that are not optional.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 10 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETPassing Arguments to a ProcedureYou can pass arguments to a procedure:  By value using the ByVal keyword  By reference using the ByRef keywordIn Visual Basic .NET, the default argument passing mechanism is ByVal.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 11 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETParameter ArrayCan be used to pass an array of values for an argument of a procedure.Is defined by using the keyword ParamArray.Rules:You cannot use more than one parameter array in aprocedure, and it must be the last argument in the proceduredefinition.The parameter array must be passed by value.The code within the procedure must use the parameterarray as a one-dimensional array. In addition, each element of the array must be of the same data type as the datatype of ParamArray.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 12 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETParameter Array (Contd.)The parameter array is optional. The default value of aparameter array is an empty one-dimensional array.The parameter array must be the lone optional argument in the list of arguments for a procedure. All otherarguments preceding the parameter array must be used.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 13 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProcedure Overloading Means defining multiple procedures using the same name but different argument lists, also referred to as signature. When you overload a procedure:  Each overloaded version uses the same procedure name.  Each overloaded version differs from all the other overloaded versions in one of the following ways: ®The number of arguments ®The order of the arguments ®The data types of the arguments©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 14 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProcedure Overloading (Contd.) You cannot overload a procedure by varying only one or more of the following items:  The procedure modifiers, such as Public, Shared, and Static  The argument names  The argument modifiers, such as ByRef and Optional  The data type of the return value©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 15 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProcedure Overriding Means redefining a base class procedure in a derived class without changing the name of the procedure. Rules:  You can override procedures that are declared with the Overridable keyword in the base class.  You need to explicitly declare a procedure in the base class with the Overridable keyword in order to override it in the derived class.  Overridden procedures need to have the same arguments as the inherited members from the base class.  The redefined implementation of a procedure in the derived class can call the implementation defined in the parent class by specifying MyBase keyword before the procedure name.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 16 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETBuilt-in Functions in Visual Basic .NET Functions Usage Len (string expression) To find the length of the string expression that is passed as the argument Mid (string expression, starting position, To extract a particular number of number of characters) characters, starting at a given character position, from the string expression that is passed as the argument CDate (string expression) To convert the string expression that is passed as the argument to the Date type CTime (string expression) To convert the string expression that is passed as the argument to the Time type Val (string/object/ char expression) To convert the numbers contained in a string/char/object to a numeric value©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 17 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETBuilt-in Functions in Visual Basic .NET(Contd.) Functions Usage CBool (expression) To convert a string or numeric expression to Boolean values CByte (string/numeric expression) To convert a string or a numeric expression to a Byte data type CInt (string/numeric expression) To convert a string or a decimal expression to an integer CObj (string/numeric expression) To convert a string or numeric value to an object CChar (string/numeric expression) To convert a string or numeric value to a Char CStr (string/numeric expression) To convert a string or numeric value to a String CDec (string/numeric expression) To convert a string or numeric value to a Decimal CType(expression.datatype/object/class/ To convert an expression from one type structure) to another©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 18 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProblem Statement 4.D.1The customer data entry forms at the call centers of DiazTelecommunications need to include options to check for avalid customer ID and telephone number. The customer IDshould start with the letter ‘C’ and have three digits after it.The telephone number should consist of eight digits. The formshould also have the facility to display error messages whenincorrect data is entered. Additionally, the form should havethe provision to clear the last customer details entered.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 19 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask ListIdentify the checks that need to be applied on the form.Identify the changes needed in the design of the form.Identify the mechanism to display error messages.Add the additional controls to the form.Check the data and display an error message.Save the application.Run the application to validate the checks applied on the form.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 20 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask 1: Identify the checks that need to be applied on theform.Result:As per the problem statement, the customer data entry form needs to have a provision to check for a valid customer id and telephone number.You can add the provision for checking the validity of the customer id and the telephone number by includingprocedures in the customer data entry application.Since Visual Basic .NET allows the use of procedureoverloading, you can create two versions of a procedure in the customer data entry application to check the validity of the customer id and the telephone number.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 21 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask 2: Identify the changes needed in the design ofthe form.You will create an overloaded procedure for checking the validity of the customer id and the telephone number.You can name the procedure Check_data ().Result:The following table recommends suitable prefixes that you can use for the two buttons: Object Prefix Example Button cmd cmdCheckdata Button cmd cmdReset©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 22 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask 3: Identify the mechanism to display errormessages.Messages can be displayed by using either  Msgbox ()Function  MessageBox Class©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 23 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask 3: Identify the mechanism to display errormessages. (Contd.)Result:To display an error message to users when an invalidcustomer id or telephone number is entered in the customersdata entry form, you can use either the MessageBoxclass or the built-in MsgBox()function.Since MessageBox class offers greater control over theinterface of the message box, such as displayingappropriate icons, you should use the MessageBox class todisplay error message when invalid customer id or telephonenumber is entered.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 24 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETTask 4: Add the additional controls to the form.Task 5: Check the data and display an errormessage.Task 6: Save the application.Task 7: Run the application to validate the checksapplied on the form.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 25 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETProblem Statement 4.P.1The Employee data entry form in the call centers at DiazTelecommunications requires options to check for validemployee ID and age entries. The employee ID should startwith the letter ‘E’ and have three digits after it. The age shouldbe more than 20 years and less than 61 years. The formshould also have the facility to display error messages whenincorrect data is entered. Additionally, the form should have aprovision to clear the last employee details entered. Thedetails of an employee essentially include the employee id,the employee’s first name, the employee’s last name, theaddress, the age, the date of joining, the department, and thesalary.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 26 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETJust a Minute…2. There are two labels named Label1 and Label2 and one button named Button1 on the form, Form1. Predict the output of the code, when Button1 is clicked at run time.3. There are two labels named Label1 and Label2 and one button named Button1 on the form, Form1. You have created a user-defined Sub procedure called MySub to process information when the user clicks Button1. Predict the output of the code, when the program is executed.4. There is one label named Label1 and one button named Button1 on the form, Form1. What will be the output of the code when Button1 is clicked at run time?©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 27 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETCommon Dialog ClassesAre used to access the default Font dialog box to change the font of the text or used to open a file by using the Open dialog box and display the contents.Are of the following types:  ColorDialog  FontDialog  FileDialog  PrintDialog  PageSetupDialog©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 28 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETColorDialog ClassIs used to change the background and the foreground color of text.FontDialog ClassIs used to change the font, the font style, and the size of text.FileDialog ClassIs an abstract class that is inherited from the CommonDialog class.You cannot instantiate it directly. However, you can use the OpenFileDialog or SaveFileDialog class to open a file or save an existing file.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 29 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETPrintDialog Class Is used to print text or graphics.PageSetupDialog Class Used to set the page details for printing in Windows applications.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 30 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETJust a Minute…2. What will be the output of the code when Button1 is clicked at run time?3. The code snippet is written in the Code Editor window of Form1. While building the project, there was a build error. What would you do to resolve the error?©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 31 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSummaryIn this lesson, you learned that:A procedure is a set of one or more program statementsthat can be executed by referring to the procedure name.Procedures are of three types:  Sub  Function  PropertySub procedures can be of two types:  General  Event-handling©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 32 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSummary (Contd.) Property procedure is of two types:  Get procedures are used to retrieve values from a property.  Set procedures are used to assign values to a property. Property procedures are used to access properties declared within a module, a class, or a structure. Arguments can be passed to a procedure either by value or by reference. Parameter arrays enable you to pass an array of values as an argument to a procedure. Procedure overloading is defining multiple procedures having the same name but different argument lists.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 33 of 34
  • Introducing Procedures and CommonDialog Classesin Visual Basic .NETSummary (Contd.) Procedure overriding enables you to redefine a base class procedure in a derived class without changing the name of the procedure. The CommonDialog class is the base class for the most commonly used dialog boxes, such as, Font, File, Print, and Page Setup.©NIIT Introducing Procedures and CommonDialog Classes in VB .NET/Lesson 4/Slide 34 of 34