Материал из VB Эксперт
Перейти к: навигация, поиск

Private Member Variable

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim timeObject As New Time( )
       timeObject.DisplayCurrentTime( )
    End Sub
End Class
 Public Class Time
    " Private variables
    Private Year As Integer
    Private Month As Integer
    Private Day As Integer
    Private Hour As Integer
    Private Minute As Integer
    Private Second As Integer
    " Public methods
    Public Sub DisplayCurrentTime( )
    End Sub "DisplayCurrentTime
 End Class "Time

Public and private demo

Imports System.IO
Module Module1
    Sub Main()
        Dim p As New Professor()
        p.Name = "JOe"
        p.OfficeNumber = "123A"
    End Sub
End Module
    Class Professor
        Public Name As String
        Private Age As Integer
        Public OfficeNumber As String
        Private HomePhone As String
        Public Sub ShowProfessor()
            Console.WriteLine("Name: " & Name)
            Console.WriteLine("Age: " & Age)
            Console.WriteLine("Office Number: " & OfficeNumber)
            Console.WriteLine("Home Phone: " & HomePhone)
        End Sub
        Public Sub AssignAge(ByVal EmpAge As Integer)
            If (EmpAge > 18) And (EmpAge < 100) Then
                Age = EmpAge
            End If
        End Sub
        Public Sub AssignHomePhone(ByVal Phone As String)
            HomePhone = Phone
        End Sub
    End Class