Polymorph is m

Embed Size (px)

DESCRIPTION

notes

Citation preview

Polymorphism

Polymorphism Fundamentals

Introduction

As mentioned already, inheritance allows you to reuse, in a child class, code that is already implemented in a parent class. In some cases, that original code will be enough. In some other cases, you will need to apply new behavior to a child class even though the parent class already has a behavior close to what you seek.

Re-creating a method in a child class using the same signature (name and arguments, if any) of a method of a parent class is referred to as overriding. Based on this, if a derived and a parent classes have the same member but implemented differently, when accessing that in your code, you need to know what particular member you are referring to, the parent or the derived's. This is the basis of polymorphism. Overriding a Method

When creating the above two classes, imagine that you want to create a method that displays the characteristics of each shape. The method would belong to its corresponding class. This can be done as follows:File: Circle.vbPublic Class Circle

Protected Radius As Double

Protected Function ShowDescription() Return "A circle is a round geometric shape " & vbCrLf & _ "constructed so that all considered points of the " & vbCrLf & _ "shape are at an equal distance from a common point " & vbCrLf & _ "called the center. Also, two equally opposite points " & vbCrLf & _ "from the center are at the exact same dictance from " & vbCrLf & _ "that center." End Function

Public Function CalculateDiameter() As Double Return Radius * 2 End Function

Public Function CalculateCircumference() As Double Return CalculateDiameter() * 3.14159 End Function

Public Sub ShowCharacteristics() Console.WriteLine("Circle Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Radius) Console.WriteLine("Diameter: {0}", CalculateDiameter()) Console.WriteLine("Circumference: {0}" & vbCrLf, CalculateCircumference()) End Sub

End ClassPublic Class Sphere Inherits Circle

Public Sub ShowCharacteristics() ' Because Sphere is based on Circle, you can access ' any public member(s) of Circle without qualifying it(them)

Console.WriteLine("Sphere Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Me.Radius) Console.WriteLine("Diameter: {0}", Me.CalculateDiameter()) Console.WriteLine("Circumference: {0}", Me.CalculateCircumference()) Console.WriteLine("=======================================================") End Sub

End ClassWhen creating a class such as the above Circle, if you create a member that the class' children would override, you can (should/must) indicate this to the compiler. This is done by preceding it with the Overridable keyword. This would be done as follows:Public Class Circle Public Ovirridable Sub ShowCharacteristics() End SubEnd Class

Private Class Sphere Inherits Circle

Public Sub ShowCharacteristics() End SubEnd ClassOnce the member has been marked as overridable, when implementing the child class, in order to override it, you must mark the corresponding member of the child class as override. To do this, precede it with the Overrides keyword. This would be done as follows:File: Circle.vbPublic Class Circle

Protected Radius As Double

Protected Overridable Function ShowDescription() Return "A circle is a round geometric shape " & vbCrLf & _ "constructed so that all considered points of the " & vbCrLf & _ "shape are at an equal distance from a common point " & vbCrLf & _ "called the center. Also, two equally opposite points " & vbCrLf & _ "from the center are at the exact same dictance from " & vbCrLf & _ "that center." End Function

Public Function CalculateDiameter() As Double Return Radius * 2 End Function

Public Function CalculateCircumference() As Double Return CalculateDiameter() * 3.14159 End Function

Public Overridable Sub ShowCharacteristics() Me.Radius = 35.84

Console.WriteLine("Circle Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Me.Radius) Console.WriteLine("Diameter: {0}", Me.CalculateDiameter()) Console.WriteLine("Circumference: {0}" & vbCrLf, Me.CalculateCircumference()) End Sub

End Class

Public Class Sphere Inherits Circle

Protected Overrides Function ShowDescription() Return "A sphere is a three-dimensional geometric " & vbCrLf & _ "shape based on a circle. It is constructed " & vbCrLf & _ "so that all considered points around the shape " & vbCrLf & _ "are at an equal distance from a common point " & vbCrLf & _ "called the center. Like the circle, two equally " & vbCrLf & _ "opposite points from the center are at the exact " & vbCrLf & _ "same dictance from that center." End Function

Public Overrides Sub ShowCharacteristics() ' Because Sphere is based on Circle, you can access ' any public member(s) of Circle without qualifying it(them) Me.Radius = 35.84

Console.WriteLine("Sphere Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Me.Radius) Console.WriteLine("Diameter: {0}", Me.CalculateDiameter()) Console.WriteLine("Circumference: {0}", Me.CalculateCircumference()) Console.WriteLine("=======================================================") End Sub

End ClassFile: Exercise.vbModule Exercise

Public Function Main() As Integer Dim circ As Circle = New Circle circ.ShowCharacteristics()

Dim ball As Sphere = New Sphere ball.ShowCharacteristics()

Return 0 End Function

End ModuleThis would produce:Circle Characteristics=======================================================Description: A circle is a round geometric shapeconstructed so that all considered points of theshape are at an equal distance from a common pointcalled the center. Also, two equally opposite pointsfrom the center are at the exact same dictance fromthat center.-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-Radius: 35.84Diameter: 71.68Circumference: 225.1891712

Sphere Characteristics=======================================================Description: A sphere is a three-dimensional geometricshape based on a circle. It is constructedso that all considered points around the shapeare at an equal distance from a common pointcalled the center. Like the circle, two equallyopposite points from the center are at the exactsame dictance from that center.-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-Radius: 35.84Diameter: 71.68Circumference: 225.1891712=======================================================If you mark as member of a child class with Overrides, it must have a corresponding member in the parent class and that corresponding member must be marked with the Overridable keyword. Shadowing a Method

You can notice in the above example that the derived class produces the same results as the base class. In reality, inheritance is used to solve various Object-Oriented Programming (OOP) problems. One of them consists of customizing, adapting, or improving the behavior of a feature of the parent class. For example, although both the circle and the sphere have an area, their areas are not the same. A circle is a flat surface but a sphere is a volume, which makes its area very much higher. Since they use different formulas for their respective area, you should implement a new version of the area in the sphere. This would be done as follows:Public Class Circle Public Radius As Double

Public Function CalculateArea() As Double Return Radius * Radius * 3.14159 End FunctionEnd Class

Private Class Sphere Inherits Circle

Public Function CalculateArea() As Double Return 4 * Radius * Radius * 3.14159 End Function

End ClassImagine that, in a method of the Sphere class, you call an Area() method, even if you use Me, it may not appear clear what Area() you are accessing. If you create a member, such as a method, in the child class and that has the same signature as an existing member of a parent class, to make sure that you access the derived version of the member, you can hide the corresponding member of the parent class. To do this, precede the member of the child class with the Shadows keyword. This would be done as follows:File: Circle.vbPublic Class Circle

Protected Radius As Double

Protected Overridable Function ShowDescription() Return "A circle is a round geometric shape " & vbCrLf & _ "constructed so that all considered points of the " & vbCrLf & _ "shape are at an equal distance from a common point " & vbCrLf & _ "called the center. Also, two equally opposite points " & vbCrLf & _ "from the center are at the exact same dictance from " & vbCrLf & _ "that center." End Function

Public Function CalculateDiameter() As Double Return Radius * 2 End Function

Public Function CalculateCircumference() As Double Return CalculateDiameter() * 3.14159 End Function

Public Function CalculateArea() As Double Return Radius * Radius * 3.14159 End Function

Public Overridable Sub ShowCharacteristics() Me.Radius = 35.84

Console.WriteLine("Circle Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Radius) Console.WriteLine("Diameter: {0}", Me.CalculateDiameter()) Console.WriteLine("Circumference: {0}", Me.CalculateCircumference()) Console.WriteLine("Area: {0}", Me.CalculateArea()) Console.WriteLine("=======================================================") End Sub

End Class

Public Class Sphere Inherits Circle

Protected Overrides Function ShowDescription() Return "A sphere is a three-dimensional geometric " & vbCrLf & _ "shape based on a circle. It is constructed " & vbCrLf & _ "so that all considered points around the shape " & vbCrLf & _ "are at an equal distance from a common point " & vbCrLf & _ "called the center. Like the circle, two equally " & vbCrLf & _ "opposite points from the center are at the exact " & vbCrLf & _ "same dictance from that center." End Function

Public Shadows Function CalculateArea() As Double Return 4 * Radius * Radius * 3.14159 End Function

Public Function CalculateVolume() As Double Return 4 * 3.14159 * Radius * Radius * Radius / 3 End Function

Public Overrides Sub ShowCharacteristics() ' Because Sphere is based on Circle, you can access ' any public member(s) of Circle without qualifying it(them) Me.Radius = 35.84

Console.WriteLine("Sphere Characteristics") Console.WriteLine("=======================================================") Console.WriteLine("Description: {0}", Me.ShowDescription()) Console.WriteLine("-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-") Console.WriteLine("Radius: {0}", Me.Radius) Console.WriteLine("Diameter: {0}", Me.CalculateDiameter()) Console.WriteLine("Circumference: {0}", Me.CalculateCircumference()) Console.WriteLine("Area: {0}", Me.CalculateArea()) Console.WriteLine("Volume: {0}", Me.CalculateVolume()) Console.WriteLine("=======================================================") End Sub

End ClassFile: Exercise.vbModule Exercise

Public Function Main() As Integer Dim circ As Circle = New Circle circ.ShowCharacteristics()

Dim ball As Sphere = New Sphere ball.ShowCharacteristics()

Return 0 End Function

End ModuleThis would produce:Circle Characteristics=======================================================Description: A circle is a round geometric shapeconstructed so that all considered points of theshape are at an equal distance from a common pointcalled the center. Also, two equally opposite pointsfrom the center are at the exact same dictance fromthat center.-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-Radius: 35.84Diameter: 71.68Circumference: 225.1891712Area: 4035.389947904=======================================================Sphere Characteristics=======================================================Description: A sphere is a three-dimensional geometricshape based on a circle. It is constructedso that all considered points around the shapeare at an equal distance from a common pointcalled the center. Like the circle, two equallyopposite points from the center are at the exactsame dictance from that center.-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-Radius: 35.84Diameter: 71.68Circumference: 225.1891712Area: 16141.559791616Volume: 192837.834310506=======================================================

Inheritance and the .NET Framework

Object: The Ancestor to all Classes

The .NET Framework is the main library used by the Microsoft Visual Basic .NET programming language. When Visual Basic was developed, inheritance was kept in mind art all levels so that the .NET Framework library provides as much functionality as possible to enhance all types of applications necessary. To provide this functionality, the .NET Framework provides a rich set of classes (and namespaces as we will see).At the highest level, the library provides the Object class that serves as the common ancestor to all classes used in the .NET Framework. In fact, any time you create a class to use in your Visual Basic application, the class is automatically derived from Object. Consider the following Square class:Module Exercise Public Class Square Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function End Class

Public Function Main() As Integer Dim sqr As Square = New Square

Console.Write("Enter Side: ") sqr.Side = Double.Parse(Console.ReadLine())

Console.WriteLine() Console.WriteLine("Square Characteristics") Console.WriteLine("Side: {0:F}", sqr.Side) Console.WriteLine("Perimeter: {0:F}", sqr.CalculatePerimeter()) Console.WriteLine("Area: {0:F}", sqr.CalculateArea())

Return 0 End Function

End ModuleHere is an example of running the program:Enter Side: 42.48

Square CharacteristicsSide: 42.48Perimeter: 169.92Area: 1804.55Although the Square class doesn't indicate that it is inheriting from any class, by virtue of belonging to a Visual Basic application, it inherits from Object. For this reason, the above code could also have been written as follows:Module Exercise

Public Class Square Inherits Object

End Class

End ModuleThis would produce the same results. Most of the time, if not always, you don't need to derive a class from Object: this inheritance is automatic and it is implied. The obvious question would be, "What does Object offer to its descendant?". By itself, the Object class provides little but useful functionality to its children. In fact it is equipped with only half a dozen methods. Still, this little functionality allows the various child class to interact easily or perform some operations that would require casting.All of the methods of the Object class are public, making them directly available to the descendant classes. Most are "Overridable"s, meaning if you want to use them, you should implement your own version in your class.String Conversion

One of the functionalities provided by the Object class consists of converting a class to a string. Because this can mean different things to different classes. The Object class provides the method named ToString. Its syntax is:Public Overridable Function ToString() As StringIn some cases, you can directly call this method as it is available to your class already. Here is an example:Module Exercise Public Class Square Inherits Object

Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function End Class

Public Function Main() As Integer Dim sqr As Square = New Square

sqr.ToString()

Return 0 End Function

End ModuleOtherwise, most of the time, you will need to indicate to the compiler how this method should be interpreted by your class, which is done by overriding it. To override this method, follow the rules of overriding a method by associating the Overrides keyword with the syntax of the method. In the body of the method, implement it as you see fit. Here is an example:Module Exercise Public Class Square Inherits Object

Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function

Public Overrides Function ToString() As String Return "Square Characteristics" & vbCrLf & _ "Side: " & CStr(Side) & vbCrLf & _ "Perimeter: " & CStr(CalculatePerimeter()) & vbCrLf & _ "Area: " & CStr(CalculateArea()) End Function End Class

End ModuleBecause the Object.ToString() method returns a String object, you can assign its result to a string or pass it to a function or method that takes a string as argument. Here is an example:Module Exercise Public Class Square Inherits Object

Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function

Public Overrides Function ToString() As String Return "Square Characteristics" & vbCrLf & _ "Side: " & CStr(Side) & vbCrLf & _ "Perimeter: " & CStr(CalculatePerimeter()) & vbCrLf & _ "Area: " & CStr(CalculateArea()) End Function End Class

Public Function Main() As Integer Dim sqr As Square = New Square

Console.WriteLine(sqr.ToString())

Return 0 End Function

End ModuleObject and Classes Comparisons

Another valuable method of the Object class is called Equals. This method is used to compare two instances of a class for equality. This method is overloaded with two versions and each returns a Boolean value.One of the versions of the Object.Equals() method has the following syntax:Overloads Public Overridable Function Equals(ByVal obj As Object) As BooleanThis method can be called by any class of a .NET Framework application and it takes as argument an instance of the class that the called needs to be compared to. Here is an example:Module Exercise

Public Function Main() As Integer Dim number1 As Integer, number2 As Integer

number1 = 248 number2 = 2480 Console.WriteLine("{0} = {1}: {2}", number1, number2, _ number1.Equals(number2))

Return 0 End Function

End ModuleThis would produce:248 = 2480: FalseThe second version of the Object.Equals() method has the following syntax:Overloads Public Shared Function Equals(ByVal objA As Object,_ByVal objB As Object) As BooleanThis version is declared as Shared. This means that it is not called by a specific instance of a class. Instead, it takes two arguments that each represents an instance of the classes that need to be compared. Here is an example of calling it:Module Exercise

Public Function Main() As Integer Dim Country As String, Pais As String

Country = "Senegal" Pais = "Senegal" Console.WriteLine("{0} = {1}: {2}", Country, Pais, _ Equals(Country, Pais))

Return 0 End Function

End ModuleThis would produce:Senegal = Senegal: TrueAlthough this method is made available to all .NET classes by through inheritance from the Object class, in most cases, to make sure it rightly behaves, you should customize its implementation in most of your classes where you intend to call it. Consider the following program:Module Exercise Public Class Square Inherits Object

Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function

Public Overrides Function ToString() As String Return "Square Characteristics" & vbCrLf & _ "Side: " & CStr(Side) & vbCrLf & _ "Perimeter: " & CStr(CalculatePerimeter()) & vbCrLf & _ "Area: " & CStr(CalculateArea()) End Function End Class

Public Function Main() As Integer Dim sqr1 As Square = New Square Dim sqr2 As Square = New Square

Console.WriteLine(" =+= First Square =+=") Console.Write("Enter Side: ") sqr1.Side = Double.Parse(Console.ReadLine()) Console.WriteLine(" =+= Second Square =+=") Console.Write("Enter Side: ") sqr2.Side = Double.Parse(Console.ReadLine())

Console.WriteLine() Console.WriteLine("{0}", sqr1.ToString()) Console.WriteLine() Console.WriteLine("{0}", sqr2.ToString()) Console.WriteLine()

Console.WriteLine("Squares Equality: {0}", sqr1.Equals(sqr2))

Return 0 End Function

End ModuleHere is an example of executing it:=+= First Square =+=Enter Side: 125.84 =+= Second Square =+=Enter Side: 125.84

Square CharacteristicsSide: 125.84Perimeter: 503.36Area: 15835.71

Square CharacteristicsSide: 125.84Perimeter: 503.36Area: 15835.71

Squares Equality: FalseNotice that, although both square instances have the same Side value and produce the same area, the compiler renders them not equal. This is an indication that the compiler doesn't know how to compare two instances of the Square class. The solution to this type of problem is to override the Equals() method in your class instead of relying on the default implementation from the Object class. Here are two overrides of the Equals() methods as overridden for the above Square class:Module Exercise Public Class Square Inherits Object

Public Side As Double

Function CalculatePerimeter() As Double Return Side * 4 End Function

Function CalculateArea() As Double Return Side * Side End Function

Public Overrides Function ToString() As String Return "Square Characteristics" & vbCrLf & _ "Side: " & CStr(Side) & vbCrLf & _ "Perimeter: " & CStr(CalculatePerimeter()) & vbCrLf & _ "Area: " & CStr(CalculateArea()) End Function

Public Overridable Overloads Function Equals(ByVal sqr As Square) As Boolean ' We will only compare the side of the square ' because the calculations of the perimeter and the area ' directly depend on the side ' If the side of the square passed as argument is equal ' to the side of this object, both objects are equal If sqr.Side = Me.Side Then Return True ' If the sides are not equal, then the objects are not equal Return False End Function

Public Overloads Shared Function Equals(ByVal first As Square, _ ByVal second As Square) As Boolean ' We will only compare the side of the square ' If the side of the first square is equal ' to the side of the second one, then both squares are equal If first.Side = second.Side Then Return True ' If the sides are not equal, then the objects are not equal Return False End Function End Class

Public Function Main() As Integer Dim sqr1 As Square = New Square Dim sqr2 As Square = New Square

Console.WriteLine(" =+= First Square =+=") Console.Write("Enter Side: ") sqr1.Side = Double.Parse(Console.ReadLine()) Console.WriteLine(" =+= Second Square =+=") Console.Write("Enter Side: ") sqr2.Side = Double.Parse(Console.ReadLine())

Console.WriteLine() Console.WriteLine("{0}", sqr1.ToString()) Console.WriteLine("{0}", sqr2.ToString())

Console.WriteLine("Squares Equality: {0}", sqr1.Equals(sqr2))

Console.WriteLine() Console.WriteLine(" =+= First Square =+=") Console.Write("Enter Side: ") sqr1.Side = Double.Parse(Console.ReadLine()) Console.WriteLine(" =+= Second Square =+=") Console.Write("Enter Side: ") sqr2.Side = Double.Parse(Console.ReadLine())

Console.WriteLine() Console.WriteLine("{0}", sqr1.ToString()) Console.WriteLine() Console.WriteLine("{0}", sqr2.ToString()) Console.WriteLine()

Console.WriteLine("Squares Equality: {0}", Equals(sqr1, sqr2))

Return 0 End Function

End ModuleHere is an example of testing the program:=+= First Square =+=Enter Side: 125.84 =+= Second Square =+=Enter Side: 125.84

Square CharacteristicsSide: 125.84Perimeter: 503.36Area: 15835.71

Square CharacteristicsSide: 125.84Perimeter: 503.36Area: 15835.71

Squares Equality: True

=+= First Square =+=Enter Side: 38.45 =+= Second Square =+=Enter Side: 16.82

Square CharacteristicsSide: 38.45Perimeter: 153.80Area: 1478.40

Square CharacteristicsSide: 16.82Perimeter: 67.28Area: 282.91

Squares Equality: FalseHere is another run of the same program:=+= First Square =+=Enter Side: 70.68 =+= Second Square =+=Enter Side: 42.04

Square CharacteristicsSide: 70.68Perimeter: 282.72Area: 4995.66

Square CharacteristicsSide: 42.04Perimeter: 168.16Area: 1767.36

Squares Equality: False

=+= First Square =+=Enter Side: 58.26 =+= Second Square =+=Enter Side: 58.26

Square CharacteristicsSide: 58.26Perimeter: 233.04Area: 3394.23

Square CharacteristicsSide: 58.26Perimeter: 233.04Area: 3394.23

Squares Equality: TrueNotice that, this time, the compiler knows how to perform the comparison of two Square objects using either version of the Equals() method.The Current Date

Microsoft Visual Basic provides various functions to perform date and time related operations. These functions allow you to add dates or times, find the difference between dates or times, or add constant values to dates or times.The current date is represented by a function called Date. The Date() function is used to get the system date of the computer. You can use it to display today's date, provided your computer has the correct date.The current time of the computer is represented by a function called Time. The Time() function is used to get the system time of the computer.The Date() and Time() functions can be combined and are represented by a function called Now.

EDITModule1.setConnectProcSet globRSrecordset = New ADODB.Recordset globRSrecordset.Open "SELECT * FROM table_name WHERE BkTitle='" & Trim(txtTitle) & "'", strVar, adOpenKeyset, adLockOptimistic With globRSrecordset If Not .EOF Then !BkTitle = txtTitle !Author = txtAuthor !BkRefNo = Val(txtBkRefNo) !TrnDate = txtDate MsgBox "Record Updated!", vbInformation, "Updated Existing Record" .Update .MoveLast End If .Close End WithDELETEconnectModule.setConnectProcSet globRSrecordset = New ADODB.Recordset globRSrecordset.Open "SELECT * FROM table_name WHERE BkTitle='" & Trim(txtTitle) & "'", strVar, adOpenKeyset, adLockOptimistic With globRSrecordset If Not .EOF Then .Delete End If .Close End WithModule1Public globDBConnect As ADODB.ConnectionPublic globRSrecordset As ADODB.RecordsetPublic strVar As String

Public Sub setConnectProc() Set globDBConnect = New ADODB.Connection strVar = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Location\DatabseName.accdb;Persist Security Info=False" globDBConnect.Open strVar End SubIf you are using Access 2007 use .accdbIf you are using Access 2003 use .mdbPrivate Sub cmdsave_Click(Index As Integer)Set rs = New ADODB.Recordset rs.Open "Select * from Registration where EID=" & CInt(Text1.Text) & "", cn, 1, 2 With rs If .RecordCount = 0 Then .AddNew MsgBox "Succesfully Save", , "Save Complete" End If !EID = Text1 !Fname = txtfname !Lname = txtlname !MI = txtMI !Age = txtage !UserName = txtuser rs.Update

End WithSet rs = NothingviewEnd Sub