Share via


How to: Reuse a Working Component

If a component already exists and is debugged and working, it is to your advantage to use it in your code instead of developing another component with the same functionality. Such a component is usually exposed as a class. To reuse it, you create an object from that class.

Example

The .NET Framework provides many examples of components that are available for use. One such component is the TimeZone class in the System namespace. TimeZone provides members that allow you to retrieve information about the time zone of the current computer system.

Public Sub examineTimeZone()
    Dim tz As System.TimeZone = System.TimeZone.CurrentTimeZone
    Dim s As String = "Current time zone is "
    s &= CStr(tz.GetUtcOffset(Now).Hours) & " hours and "
    s &= CStr(tz.GetUtcOffset(Now).Minutes) & " minutes "
    s &= "different from UTC (coordinated universal time)"
    s &= vbCrLf & "and is currently "
    If tz.IsDaylightSavingTime(Now) = False Then s &= "not "
    s &= "on ""summer time""."
    MsgBox(s)
End Sub

The first Dim Statement (Visual Basic) declares an object variable of type TimeZone and assigns to it a TimeZone object returned by the CurrentTimeZone property.

See Also

Tasks

How to: Create an Object

How to: Define a Class That Uses Members of an Existing Class

How to: Access Shared and Nonshared Members of an Object

Concepts

Objects and Classes