Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

expose an array to a form from a class

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
cocosteel
Asked:
cocosteel
  • 2
1 Solution
 
cocosteelAuthor Commented:
ps sorry its only 20 pts i wasted 200 on 2 silly questions so im down to 20
0
 
phildaleyCommented:
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
 
cocosteelAuthor Commented:
thanks phil,
that worked like a dream!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now