Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGive an ActiveX class or control an indexed property
KeywordsActiveX DLL, ActiveX EXE, ActiveX control, indexed property
CategoriesActiveX
 
You can add an indexed property to a class or ActiveX control. If you want to put the class in a separate project (ActiveX DLL or ActiveX EXE), or if you are building an ActiveX control, you'll need to set a reference so the main program's project can refer to the class/control's project.

Select the ActiveX DLL/EXE/control project. Open the Project menu and select the Properties command. Enter the name of the project in the Project Name field. This example uses the name ScoreArrayProject.

Now select the other project, open the Project menu, and select References. Find the ScoreArrayProject entry and select it. Now the main program can use the classes defined in the ActiveX DLL project.

Once you have done this, you can build the property procedures. The following code shows how the ScoreArray class implements an indexed Score property. Note that the main program must call SizeArray to allocate the array before it can use the Score properties. Note also that this simple example does not bounds checking on the index values.

 
' The scores.
Private m_Scores() As Single

' Size the array.
Public Sub SizeArray(ByVal max_index As Integer)
    ReDim Preserve m_Scores(1 To max_index)
End Sub

' Save a Score value.
Public Property Let Score(ByVal Index As Integer, ByVal _
    new_value As Single)
    m_Scores(Index) = new_value
End Property

' Return a Score value.
Public Property Get Score(ByVal Index As Integer) As Single
    Score = m_Scores(Index)
End Property
 
The following code shows how the main program uses the ScoreArray class.
 
Private m_ScoreArray As ScoreArray

Private Sub Form_Load()
    ' Allocate and initialize the ScoreArray.
    Set m_ScoreArray = New ScoreArray
    m_ScoreArray.SizeArray 5
End Sub

' Save the new value.
Private Sub cmdSaveValue_Click()
Dim i As Integer
Dim v As Single
Dim txt As String

    i = CInt(txtIndex.Text)
    v = CSng(txtValue.Text)
    m_ScoreArray.Score(i) = v

    ' Display all the values.
    For i = 1 To 5
        txt = txt & m_ScoreArray.Score(i) & vbCrLf
    Next i
    txtAllScores.Text = txt
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated