?
Solved

expose an array to a form from a class

Posted on 2003-03-07
3
Medium Priority
?
132 Views
Last Modified: 2010-04-07
hello

i want to be able to expose an array that is a property of a class. i want to take that array and populate a list box with its values


i have a class CCustomer
it looks like this

option explicit

Private arrFilesNotParsed As Variant

Public Property Get FilesNotParsed() As Variant
FilesNotParsed = arrFilesNotParsed()
End Property

private sub populatearray ()
dim notparsedcounter as integer
dim arrNotParsed () as variant
'some things happen here in a  For Each objFile In objFolder.Files loop
' at the end of each loop i have...

        NotParsedCounter = NotParsedCounter + 1
        ReDim Preserve arrNotParsed(NotParsedCounter)
        arrNotParsed(NotParsedCounter) = varReporterName ' varReporterName is a name of a file that has not parsed
arrFilesNotParsed = arrnotparsed
end sub

so i want to pass values to an array in the loop, then save it to a property.
then i want  to allow a form to go get that property and the values it holds.
and then in the form populate a list box with the values in the array

currently in my form i have...

Private function PopulateListBox(arrNotParsedList As Variant) as boolean

Dim i As Integer

    For i = LBound(arrNotParsedList) To UBound(arrNotParsedList)
    lstFilesNotParsed.AddItem (arrNotParsedList), (i)
    Next i

PopulateListBox = true
End Function





thanks
0
Comment
Question by:cocosteel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:cocosteel
ID: 8090493
ps sorry its only 20 pts i wasted 200 on 2 silly questions so im down to 20
0
 
LVL 3

Accepted Solution

by:
phildaley earned 100 total points
ID: 8092008
Use code example below. Note I've made a few mods to existing code.

Class CCustomer - a few minor changes. Made populatearray public so can call from outside to create array. Depending on the rest of your code this may not be necessary.

Option Explicit

Private arrFilesNotParsed() As String

Public Property Get FilesNotParsed() As Variant
    FilesNotParsed = arrFilesNotParsed
End Property

Public Sub populatearray()
    Dim notparsedcounter As Integer
    'some things happen here in a  For Each objFile In objFolder.Files loop
    ' at the end of each loop i have...

       notparsedcounter = notparsedcounter + 1
       ReDim Preserve arrFilesNotParsed(notparsedcounter)
       arrFilesNotParsed(notparsedcounter) = varReporterName ' varReporterName is a name of a file that has not parsed
End Sub

Private Sub Class_Initialize()
    ReDim arrFilesNotParsed(0)
End Sub


Form code: Changed loop start count to 1, otherwise will get an empty first item in listbox. Also fixed bug in original AddItem code. Added a comand button to form to initiate the population of listbox.

Private Function PopulateListBox(arrNotParsedList As Variant) As Boolean

    Dim i As Integer

    For i = 1 To UBound(arrNotParsedList)
        lstFilesNotParsed.AddItem arrNotParsedList(i)
    Next i

    PopulateListBox = True
End Function

Private Sub Command1_Click()
    Dim cCust As CCustomer
   
    Set cCust = New CCustomer
    cCust.populatearray
    PopulateListBox cCust.FilesNotParsed
End Sub
0
 

Author Comment

by:cocosteel
ID: 8094461
thanks phil,
that worked like a dream!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question