Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6547873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:53:02+00:00 2026-05-25T11:53:02+00:00

I have a class where one of the member variables is an array. I

  • 0

I have a class where one of the member variables is an array. I am trying to assign an array to the object but keep getting the ‘Can’t assign array’ compile error. Also I was curious as how to get UBound of the array in object. UBound(obj.array) doesn’t compile. I am using excel 07 vba.

'Test routine that keeps failing

Sub test()  

Dim Arr(2) As String
Arr(0) = ""
Arr(1) = "Pizza"
Arr(2) = "Hoes"

Dim obj As Cats
Set obj = New Cats
obj.avry = Arr
obj.field = 4    
MsgBox UBound(obj.ary)

End Sub  


'Class declaration
Private pary() As String
Private pfield As Long

Public Property Get ary(ByVal index As Long) As String
    Set ary = pary(index)
End Property

Public Property Let avry(Value() As String)
    ReDim pary(UBound(Value)) As String
    For i = LBound(Value) To UBound(Value)
        pary(i) = Value(i)
    Next i
End Property

Public Property Get field() As Long
    field = pfield
End Property

Public Property Let field(Value As Long)
    pfield = Value
End Property

Private Sub Class_Initialize()
    pfield = 0
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:53:02+00:00Added an answer on May 25, 2026 at 11:53 am

    There seems to be an issue with passing array parameters to class properties.

    You can get around this by switching the Let parameter to a Variant:

    Public Property Let avry(ByRef arrVal As Variant)
        Dim i As Integer
        If IsArray(arrVal) Then
            ReDim pary(LBound(arrVal) To UBound(arrVal))
            For i = LBound(arrVal) To UBound(arrVal)
                pary(i) = arrVal(i)
            Next i
        End If
    End Property
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple class with only one field member (e.g. String). Is
Basically I have some class objects, each with three properties. Once one class object
If I have a class with 5 member variables, e.g., class XYZ { public:
I have a Class A with quite a number of member variables. In order
I have a C++ class(inside a dll project) whose member variables are boost::shared_ptrs to
Assume I have a Class Foo which has many internal variables, only one constructor
I have a class: class One def initialize; end end I need to create
I have one class that needs to grab an attribute that is set in
I have class which have one public method Start , one private method and
I used to have one class for one file. For example car.cs has the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.