Results 1 to 5 of 5

Thread: Public const in class

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    Is there a way to make public constant in a class ? Or make something else near this ?
    KWell

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    You could have a property that only has a Get procedure for it.

    ie.
    Code:
    Private Const m_MyConst = 5
    
    Public Property Get MyConst()
        MyConst = m_MyConst
    End Property
    Without the Let procedure, MyConst will always be 5 and cannot be changed.

    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    Thanx a lot S@NSIS.
    That's what I search.

    Any idea for user-define type ?
    KWell

  4. #4
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    There are many workarounds for this and you really shouldn't need a UDT inside a class. However, if you need to then try this
    Code:
    'Class to simulate UDT called clsUDT
    
    Option Explicit
    
    Private m_aString As String
    Private m_aInteger As Integer
    Private m_aDate As Date
    
    Public Property Get aString() As String
        aString = m_aString
    End Property
    
    Public Property Let aString(vData As String)
        m_aString = vData
    End Property
    
    Public Property Get aInteger() As Integer
        aInteger = m_aInteger
    End Property
    
    Public Property Let aInteger(vData As Integer)
        m_aInteger = vData
    End Property
    
    Public Property Get aDate() As Date
        aDate = m_aDate
    End Property
    
    Public Property Let aDate(vData As Date)
        m_aDate = vData
    End Property
    
    
    'Class to provide interface for UDT
    Dim m_MyUDT As clsUDT
    
    Private Sub Class_Initialize()
        Set m_MyUDT = New clsUDT
    End Sub
    
    Public Property Get myudt() As clsUDT
        myudt = m_MyUDT
    End Property
    
    Public Property Let myudt(vData As clsUDT)
        m_MyUDT = vData
    End Property
    
    'Add your own code for adding,removing clsUDT objects.
    If you want say, an array of UDT's then you could set up another class to hold a collection of clsUDT with the usual add,remove etc methods.

    Not sure if this is exactly what you are after but hopefully it may provide some pointers.

    Cheers

    Shaun

    [Edited by S@NSIS on 09-28-2000 at 09:16 AM]
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    Thanx.
    It's not exactly what i have in mind, but it can work with my app.
    KWell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width