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

x
?
Solved

Objects as Parameters

Posted on 2006-06-30
6
Medium Priority
?
207 Views
Last Modified: 2013-11-23
Hi.  I have a question about passing object as parameters in Visual Basic 6.  Suppose that I have a class module named CPerson that consists of the following code:

    Private m_strName As String
    Public Property Get Name() As String
        Name = m_strName
    End Property
    Public Property Let Name(ByVal strValue As String)
        m_strName = strValue
    End Property

Furthermore, suppose that I have a class module named CGroup that consists of the follow code:

    Private m_objLeader As CPerson
    Public Property Get Leader() As CPerson
        Set Leader = m_objLeader
    End Property
    Public Property Let Leader(ByRef objValue As CPerson)
        Set m_objLeader = objValue
    End Property

When I run the following code:

    Dim objGroup As New CGroup
    Dim objPerson As New CPerson
    objPerson.Name = "Chris"
    Set objGroup.Leader = objPerson

I get the following error message:

    Run-time error '91':
    Object variable or With block variable not set

Could you please tell me why that I am getting this error message?  How do you pass objects as parameters in Visual Basic 6?  Thank you.
0
Comment
Question by:deatc
[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
  • 3
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17020680
the code looks fine so far (except that I would not name a property NAME, as that is a reserved word).

the first step to help us would be to tell us on which line the error occurs.
0
 
LVL 37

Accepted Solution

by:
Harisha M G earned 500 total points
ID: 17020694
Hi, try changing Let to Set

---
Harish
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17020710
good catch. to make it clear (points for mgh_mgharish:

Public Property Set Leader(ByRef objValue As CPerson)
        Set m_objLeader = objValue
    End Property
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17020722
As mgh_mgharish has mentioned, you need to change:

    Public Property Let Leader(ByRef objValue As CPerson)
        Set m_objLeader = objValue
    End Property

To:

    Public Property Set Leader(ByRef objValue As CPerson)
        Set m_objLeader = objValue
    End Property

Let is used for properties of Value type, whereas Set is used for properties that are objects.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17020757
deatc, In the class CPerson, "Name" is a "String", which is a basic data type. So, you should use "Let"

But in the case of CGroup, "Leader" is an "CPerson Object" (it may be built-in object or user defined object), which is not a basic data type. So, you must use "Set" in this case.
0
 
LVL 37

Expert Comment

by:Harisha M G
ID: 17020775
deatc, also a very important point to keep in mind...

When assigning values to basic data types, you shouldn't use "Set". So,
objPerson.Name = "Chris"
is correct and
Set objPerson.Name = "Chris"
would be wrong.

Similarly, while assigning to an object, you must use "Set"

So,
Set objGroup.Leader = objPerson
is correct, and
objGroup.Leader = objPerson
would be wrong.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

721 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