Solved

simple OOP question

Posted on 2003-12-01
3
269 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a task in Outlook from access 11 39
Delphi: ForceDirectory plain function 7 30
Added a column screws up code 5 57
MS Access from Delphi 31 28
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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

776 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