Solved

simple OOP question

Posted on 2003-12-01
3
267 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
  • 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 85

Accepted Solution

by:
Mike Tomlinson earned 50 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 85

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now