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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:32:31+00:00 2026-06-07T17:32:31+00:00

If I am accumulating data with no advance information about the number of elements,

  • 0

If I am accumulating data with no advance information about the number of elements, I can use an array and enlarge it as necessary using Redim Preserve, but a List will usually be more efficient. For example:

Dim vehicle As New List(Of String)(4)

vehicle.Add("car")
vehicle.Add("bicycle")
vehicle.Add("truck")
vehicle.Add("taxi")
vehicle.Add("motorbike")
vehicle.Add("bus")

Even though my guess of 4 as the maximum number of elements was wrong, I can add new elements without problems.

I can display the elements so:

For inx = 0 To vehicle.Count - 1
    Debug.Print("    " & inx & " " & vehicle(inx))
Next

and get:

0 car
1 bicycle
2 truck
3 taxi
4 motorbike
5 bus

I can update elements as required and redisplay:

vehicle(2) = "coach"
vehicle(4) = "cart"

For inx = 0 To vehicle.Count - 1
    Debug.Print("    " & inx & " " & vehicle(inx))
Next

to get:

0 car
1 bicycle
2 coach
3 taxi
4 cart
5 bus

I can create a list of structures almost as easily:

Structure SpersonDtl
    Dim familyName As String
    Dim givenName As String
    Dim age As Integer
End Structure

Dim personDtl As New List(Of SpersonDtl)(4)
Dim personDtlCrnt As SpersonDtl

personDtlCrnt.familyName = "Smith"
personDtlCrnt.givenName = "John"
personDtlCrnt.age = 20
personDtl.Add(personDtlCrnt)

personDtlCrnt.familyName = "Brown"
personDtlCrnt.givenName = "Clare"
personDtlCrnt.age = 21
personDtl.Add(personDtlCrnt)

personDtlCrnt.familyName = "Wilson"
personDtlCrnt.givenName = "David"
personDtlCrnt.age = 22
personDtl.Add(personDtlCrnt)

personDtlCrnt.familyName = "Fox"
personDtlCrnt.givenName = "Wendy"
personDtlCrnt.age = 23
personDtl.Add(personDtlCrnt)

Displaying the list’s contents with:

For inx = 0 To personDtl.Count - 1
    Debug.Print("    " & inx & " " & personDtl(inx).givenName & " " & _
                personDtl(inx).familyName & " " & personDtl(inx).age)
Next

gives:

0 John Smith 20
1 Clare Brown 21
2 David Wilson 22
3 Wendy Fox 23

If personDtl were an array, I could update an element easily. To correct Wendy’s age, I would write:

personDtl(3).age = 24

However, the same statement with a list, results in a blue line under personDtl(3).age and the error message: “Expression is a value and therefore cannot be the target of an assignment.“

The best solution I have found is:

Dim personDtlCrnt As SpersonDtl

personDtlCrnt = personDtl(3)
personDtlCrnt.age = 24
personDtl(3) = personDtlCrnt 'Write back.

In my application, I am accumulating information into large, complex structures. To copy an element out of the list, add one new item of information and then copy it back would not be an efficient process.

I would be grateful for any suggestions for an alternative approach.

  • 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-07T17:32:35+00:00Added an answer on June 7, 2026 at 5:32 pm

    Try using a class instead of a structure.

    From Choosing Between Classes and Structures

    Consider defining a structure instead of a class if instances of the type are small and commonly short-lived or are commonly embedded in other objects.

    Do not define a structure unless the type has all of the following characteristics:

    • It logically represents a single value, similar to primitive types (integer, double, and so on).

    • It has an instance size smaller than 16 bytes.

    • It is immutable.

    • It will not have to be boxed frequently.

    If one or more of these conditions are not met, create a reference type instead of a structure. Failure to adhere to this guideline can negatively impact performance.

    You want your SpersonDtl "structure" to be mutable by changing one of the values, which is breaking one of those characteristics listed above.

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

Sidebar

Related Questions

I have large amounts of data (a few terabytes) and accumulating... They are contained
I have a relatively large database (130.000+ rows) of weather data, which is accumulating
Situation I am using Spring Batch to build an Accumulative Snapshot for our Data
I just recently started using this library (the one from CodePlex), but I ran
I'm trying to write Windows app to get data from From Fox Pro DB,
I have data that looks like this. In which I want to plot accumulative
I am inserting data from an Excel sheet to SQL Server 2005 db. I
I'm working on a project right now where I have been slowly accumulating a
I want to log certain activities in MySql with a timecode using time() .
I'm noticing code accumulating in my project that looks like this: Response.Redirect(/Foo/Bar.aspx); This seems

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.