Friday, April 26, 2013

Example of Class

Circle.cs

image087
Public Class Circle
    Private cradius As Double
    Public Property Radius() As Double
        Get
            radius = cradius
        End Get
        Set(ByVal value As Double)
            If value < 0 Then
                msgbox("Wrong Input:")
            Else
                cradius = value
            End If
        End Set
    End Property
 
    Public Function Area() As Double
        Return math.pi * radius ^ 2
    End Function
 
    Public Function Circumfrence() As Double
        Return 2 * math.pi * radius
    End Function
End Class




 









Public Class Form4


 


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim c As New circle


        c.Radius = Val(TextBox1.Text)


        MsgBox("Area = " & c.Area)


        MsgBox("Circumfrence =" & c.Circumfrence)


    End Sub


 



End Class

No comments:

Post a Comment

Contact us

Name

Email *

Message *