Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2004, 08:44 AM
Authorized User
 
Join Date: Jan 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing an array in a class

Hi,

I have a class (A) that contains an array of instances of another class (B).

A third class C has a "pointer" (i.e. a reference variable) to class A.

In class C, I want to get a pointer to one of the class B instances in the array.

However, I cannot make the array public in class A, because VB does not allow public arrays in a class.

If I write a "get" function in class A, I want that function to return a reference to the array item (class B instance), NOT the value of it. This is so that I can subsequently call the methods of that class B instance, from within class C.

So - how do I return a reference to class B, from the "get" function?

Or... is there a much better approach to this?

Thanks.

James

//##
 
Old May 7th, 2004, 01:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In class A:

public property get NumClassB() as long
   NumClassB = ubound(myArray) + 1
end

public property get mClassB(byval index as long) as ClassB
   set mClassB = myArray(index)
end

plus error checking...

In class C:
   dim cb as ClassB
   for k = 0 to mClassA.NumClassB -1
      set cb = mClassA.ClassB(k)
      ... do whatever with cb

plus error checking :)
Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
return more then one array from class file Komila ASP.NET 2.0 Basics 4 June 27th, 2007 07:10 PM
Accessing elements of an Array object abdulqadirpk VB How-To 1 April 2nd, 2007 11:13 AM
Accessing Session variables from custom class mohyneenm ASP.NET 1.0 and 1.1 Professional 2 January 26th, 2005 07:25 PM
accessing a two dimentional collection array levinll Beginning VB 6 0 September 2nd, 2004 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.