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 7722811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:17:01+00:00 2026-06-01T04:17:01+00:00

I have a custom object that I was adding to an array via a

  • 0

I have a custom object that I was adding to an array via a loop. The problem was when I initialized the object like this:

Dim CallNum As New Lib_CallNum

The last object added in the loop would overwrite all the other objects added during the loop. So I would end up with an array filled with a bunch of the same objects. To fix this I had to change the way I was initializing the object to:

Dim CallNum As Lib_CallNum
Set CallNum = New Lib_CallNum

But I am unsure why the first initialization would not work. So what is the difference between the two sets of code?

  • 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-06-01T04:17:02+00:00Added an answer on June 1, 2026 at 4:17 am

    The Dim inside a loop is not actually executed on each iteration. It is only executed the first time the variable is encountered.

    To demonstrate this, add a section to your Lib_CallNum class initialisation definition:

    Private Sub Class_Initialize()
        Debug.Print "Initialise Lib_CallNum"
        ' ...
    End Sub
    

    and run your original code. Initialise will only be reported once. From then on you are adding the same instance to the array many times.

    The correct way to initialise new instances objects is as @Doug has told you, Set ... = New ...

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that is adding custom objects to an array in a
I have a custom web applet that I am adding to the Lead object
I have a custom principal object that I want to be able to serialize
I have a UITableView that displays various nsstrings from a custom object called a
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have a data object -- a custom class called Notification -- that exposes
I have a custom object that I am trying to bind to a control.
I have a custom object Foo with a boolean property called Flagged and when
What I am attempting to do is the following: I have a custom object
If I where to have a Queue holding a collection of objects (Custom object,bool,bool,bool,bool)

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.