Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning 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 3rd, 2007, 11:55 AM
Registered User
 
Join Date: May 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can you Assign a Collection to a Property?

Does anyone know if it's possible to pass a Collection to a property in a class? (the class is in another project in the solution).

i.e:
dim colCars as collection
[code to fill collection goes here]
  .
[clsMine instantiation goes here]
clsMine.setCars = colCars ' pass collection

clsMine looks like this:
private mCol as collection
  .
  .
Public Property Let setCars(ByVal Value As Collection) or
Public Property Let setCars(ByVal Value As Object) or
   mCol = Value
End Property

------------

I tried setting up a property similar to above and assign a variable but was unable to get actual data to pass in. I tried defining it as 'collection' and as 'object' in the property; neither worked. Just an empty collection resulted. So, started wondering if 'maybe you just cannot pass collections'?

Mark
 
Old May 3rd, 2007, 03:12 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You must use the keyword Set with objects
Code:
    Dim colCars As Collection
    ' [code to fill collection goes here]
    .
    .
    .
    ' [clsMine instantiation goes here]
    Set clsMine.setCars = colCars   ' pass collection
clsMine looks like this:
Code:
Private mCol As Collection
  .
  .
Public Property Let setCars(ByVal Value As Collection) ' or
Public Property Let setCars(ByVal Value As Object)
    Set mCol = Value
End Property
Use As Collection if it is certain that you will be using a Collection. That way (with early binding) the compiler will check that the methods and properties you use of the Collection object actually apply to it.
 
Old May 3rd, 2007, 05:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

there are two ways to do it, depending if the property is Let or Set.
Because you use Let, you should call it as (no Set):

clsMine.setCars = colCars

Otherwise, you have to use Set as Brian describes

In both cases, in the property itself you must use Set (like Brian said) and basically it is the only change you need to make

Set mCol = Value

"There are two ways to write error-free programs. Only the third one works."
Unknown





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable so assign value to .Lookin Property Colster Excel VBA 1 August 24th, 2007 03:16 PM
How To Assign Value To Session Using Javascript janice.koay Classic ASP Professional 1 May 9th, 2006 12:59 AM
How to assign javascript to Java? salahu Pro JSP 1 August 8th, 2005 03:05 PM
ERROR: "property access must assign to the proper" anpham ASP.NET 1.0 and 1.1 Basics 2 July 1st, 2005 02:25 PM





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