[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Is there a way to shrink an array to fit?

Posted on 2009-05-14
9
Medium Priority
?
366 Views
Last Modified: 2013-11-26
I'm curious if there's a way to shrink an array to fit.

For example I have an array that I will be adding text into and then removing it after I process it.  So when it's processed then I will remove that item from the array (starting from the bottom).  Therefore I may have an array that starts at 5 and ends at 20.

I'm curious to know if there's a way to shrink the array with all the data in it down to an array that starts at 0 and ends at 14.

I know it can be done by copying the array over line by line with a loop, but I wasn't sure if there was a better way to do this.
0
Comment
Question by:mystami
[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
  • 4
  • 4
9 Comments
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24390904
Redim Preserve YourArray(14)
       
0
 
LVL 1

Author Comment

by:mystami
ID: 24391103
That would provide a smaller array but would not make the information move down from 5 to now start at 0 with all the other information as well and the last one now being 14 instead of 20.
0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24391151
Yea, if your pulling items out of the top or the middle the only way to shrink the array would be to reload it. Have you considered using a collection instead of an array?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:mystami
ID: 24391714
I haven't, actually, I forgot about collections!

Have you had any experience with the processing speed of Collections vs. Arrays?
0
 
LVL 1

Author Comment

by:mystami
ID: 24391759
Is there any sort of multidimension collection because I need to be able to store 2 values, one value being the winsock user and the other is the message to send.
0
 
LVL 1

Author Comment

by:mystami
ID: 24391779
Of course 2 collections can always be used but I need something that's going to run as fast as possible.
0
 
LVL 8

Accepted Solution

by:
Bob Hoffman earned 500 total points
ID: 24397618
I would create a structure to hold your data and load the structure to a collection. See snippet.
Not sure how much data you're working with so as far as performance I can't really comment. You could also keep the array approach but make it an object array and load the structure to the array, this would eliminate the need for multiple arrays. To manage the size you could keep track of the number of items you have removed and when you hit some threshold reload the array, maybe 20% deleted records?
 

    Dim cCollection As New Collection
 
    'Structure needs to be in a Module
    Public Structure CollectionData
        Dim Field1 As String
        Dim Field2 As String
 
        Public Sub New(ByVal _Field1 As String, ByVal _Field2 As String)
            Field1 = _Field1
            Field2 = _Field2
        End Sub
 
        Public Overrides Function ToString() As String
            Return Me.Field1
        End Function
    End Structure
 
 
    Public Sub WorkWithCollection()
        Dim cData As New CollectionData
        Dim strKey As String = "Some unique key to access the item later"
 
        'Load the structure
        cData.Field1 = "Some info"
        cData.Field2 = "Some additional info"
 
        'Add to collection
        cCollection.Add(cData, strKey)
 
        'Get the data back
        cData = cCollection.Item(strKey)
 
        'Remove the item
        cCollection.Remove(strKey)
    End Sub

Open in new window

0
 
LVL 8

Expert Comment

by:Bob Hoffman
ID: 24540066
Did you get your question answered?
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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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