방법: 사용자 정의 형식을 Visual Basic 구조로 변환

업데이트: 2007년 11월

Visual Basic 6.0의 Type 문은 Visual Basic 2008에서 Structure 문으로 업그레이드되었습니다. 이 항목에서는 형식을 업그레이드하는 두 가지 다른 옵션인 클래스로 변환과 인터페이스로 변환에 대해서도 설명합니다.

다음 Visual Basic 6.0 형식은 후속 절차에서 설명합니다.

Type Customer
    Dim FirstName As String
    Dim LastName As String
    Dim Id As Long
End Type

Private Function FormatFullName(aCustomer As Customer) As String
    FormatFullName = aCustomer.FirstName & " " & aCustomer.LastName
End Function

업그레이드 마법사는 Visual Basic 6.0 형식을 Visual Basic 2008 구조로 자동 업그레이드합니다. Structure는 메서드와 속성과 같은 멤버를 지원하는 형식입니다.

형식을 구조로 업그레이드하려면

  1. 업그레이드 마법사를 실행합니다.

    참고:

    업그레이드 마법사는 Visual Basic 6.0 응용 프로그램을 Visual Basic 2008로 업그레이드하는 데 사용되는 도구로, Visual Basic 2008에서 Visual Basic 6.0 프로젝트를 열면 자동으로 시작됩니다. 자세한 내용은 방법: Visual Basic 업그레이드 마법사를 사용하여 프로젝트 업그레이드를 참조하십시오.

  2. Structure 형식의 다른 기능을 활용하려면 구조에 더 알맞게 속하는 메서드를 사용합니다. 이 예제에서 FormatFullName 메서드는 구조에서 FormatFullName 메서드로 변환될 수 있습니다.

    Structure Customer
        Dim FirstName As String
        Dim LastName As String
        Dim Id As Integer
    
        Public Function FormatFullName() As String
            Return FirstName & " " & LastName
        End Function
    End Structure
    

업그레이드 마법사는 Visual Basic 6.0 형식을 Visual Basic 2008 구조로 자동 업그레이드합니다. Class 형식은 Structure와 동일한 멤버를 지원하지만 참조 형식입니다. 클래스는 기본 클래스로 사용할 수 있지만 구조는 그렇게 할 수 없습니다.

클래스로 업그레이드하려면

  1. 업그레이드 마법사를 실행합니다.

  2. Structure를 Class로 바꿉니다.

  3. Class 형식의 다른 기능을 활용하려면 구조에 더 알맞게 속하는 메서드를 사용합니다. 다음 코드에서는 클래스에 FormatFullName을 포함하는 방법과 Id 속성을 보여 줍니다.

    Class Customer
        Dim FirstName As String
        Dim LastName As String
        Private idValue As Integer
    
        Public Property Id() As Integer
            Get
                Return idValue
            End Get
            Set(ByVal Value As Integer)
                idValue = Value
            End Set
        End Property
    
        Public Function FormatFullName() As String
            Return FirstName & " " & LastName
        End Function
    End Class
    

세 번째 옵션은 구조를 인터페이스로 변환하는 것입니다.

인터페이스로 업그레이드하려면

  1. 업그레이드 마법사를 실행합니다.

  2. Structure를 Interface로 바꿉니다.

  3. 변수를 속성 선언으로 바꿉니다. 구현은 포함하지 마십시오.

  4. 메서드는 추가하고 구현은 제거합니다.

  5. 코드는 다음과 비슷합니다.

    Interface Customer
        Property FirstName() As String
        Property LastName() As String
        Property Id() As String
    
        Function FormatFullName() As String
    End Interface
    
  6. 이제 인터페이스가 다른 클래스에 의해 구현될 수 있습니다. 정의는 다음과 같습니다.

    Class NewCustomer
        Implements Customer
    
        Public Property FirstName() As String Implements Customer.FirstName
            Get
                ' Add code here.
            End Get
            Set(ByVal Value As String)
                ' Add code here.
            End Set
        End Property
    
        Public Property Id() As String Implements Customer.Id
            Get
                ' Add code here.
            End Get
            Set(ByVal Value As String)
                ' Add code here.
            End Set
        End Property
    
        Public Property LastName() As String Implements Customer.LastName
            Get
                ' Add code here.
            End Get
            Set(ByVal Value As String)
                ' Add code here.
            End Set
        End Property
    
        Public Function FormatFullName() As String _
            Implements Customer.FormatFullName
            ' Add code here.
        End Function
    End Class
    

참고 항목

작업

방법: Visual Basic 업그레이드 마법사를 사용하여 프로젝트 업그레이드

참조

Structure 문

Class 문(Visual Basic)

Interface 문(Visual Basic)