Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple OOP question

Posted on 2003-12-01
3
Medium Priority
?
275 Views
Last Modified: 2013-11-25
Hi....

I have an OOP question.   Suppose I have created a class that loads and parses an XML file.  All of the xml data resides in arrays.  The class method that reads the data is private.  At runtime, I create an instance of my xml_parser class and populate the arrays.  I have also built another class that requires the use of these arrays.  How do I gain access to these variables?  Do I have to make my xml_parser method public?  When I create my other class instance and make a call to it....I tried passing the xml instance in to it.

ex...

xmlClass = new xml_parser()

myClass = new OtherClass(xmlClass)

how is this suppose to work?


thanks,

knoxxx
0
Comment
Question by:JohnnyKnoxville
[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
 
LVL 28

Expert Comment

by:AzraSound
ID: 9853891
You need to make the array's items publicly accessible via properties or the like, e.g.,


Public Property Get ArrayItem(ByVal Index As Long) As String
    ArrayItem = m_myprivatestringarray(Index)
End Property
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 9854832
Here is how to return an entire array with a property:

In Class1:
Private someArray() As String

Private Sub Class_Initialize()
    Dim a As Integer
   
    ' Put some simulated data in our array
    ReDim someArray(Int(Rnd * 24) + 1)
    For a = 0 To UBound(someArray)
        someArray(a) = Chr(Int((122 - 97 + 1) * Rnd + 97))
    Next a
End Sub

Property Get someArrayData() As Variant
    someArrayData = someArray
End Property

In Form1:
Private Sub Form_Load()
    Dim c As Class1
    Set c = New Class1
   
    Dim s() As String
    Dim a As Integer
   
    s = c.someArrayData
    For a = 0 To UBound(s)
        Debug.Print s(a)
    Next a
End Sub

Here is how to pass one class to another:

In Class2:
Private c As Class1

Public Property Set passClass1(ByRef newC As Class1)
    Set c = newC
End Property

Private Sub doSomethingWithClass1()
    Dim s() As String
    Dim a As Integer
   
    s = c.someArrayData
    For a = 0 To UBound(s)
        debugprint s(a)
    Next a
End Sub

Regards,

Idle_Mind
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9872549
Did we answer your question JohnnyKnoxville?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

715 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