Question resize Queue?

There doesn't need to be. The purpose of ReDim is to "resize" an array and ReDim Preserve "resizes" an array without losing the existing elements. I use the quotes because you actually cannot resize an array, only make it appear to have been resized. What actually happens is that a new array of the specified size is created, the existing elements copied from the old array to the new if Preserve was used, then the new array is assigned to the variable in place of the old.

Basically all collections will grow and shrink dynamically as you Add and Remove items. As such, the need for a specific way to resize a collection doesn't exist. It's size is always however many items you've added. You add an item and the collection is inherently bigger. You remove an item and it's inherently smaller. An array is like an egg carton while a collection is like a bag made of stretchy material.

Now, if that doesn't provide enough information to enable you to proceed, please provide a FULL and CLEAR description of what you're actually trying to achieve, rather than how you're trying to achieve it, and we can provide advice on the best way to achieve it.
 
i am just trying to change the size of the queue while there are data in it. I just wonder if there is a command for it instead of taking everything out and put in a new one.
But are you saying that you cant size limit a queue?
 
That really doesn't make sense. Like any collection, the Queue is as big as the number of items it contains. Why would you want to change the size of it? The only reason I can think of is to put more items in it. Well, if you want to put more items in it then go ahead and do so. The act of adding the items will make the collection grow.

In the case of an array, you might specify its size as 10, which means that it initially has 10 elements that are all Nothing. You might set one of those elements but the array still has 10 elements, 9 of which are Nothing. You might set another element but the array still has 10 elements. So on and so forth until all 10 elements have been set. If you want to add an eleventh object you can't, other than by replacing one of the existing objects, in which case the array still has 10 elements. You could call Array.Resize or use ReDim Preserve and specify a size greater than 10, e.g. 20, in which case an new array with 20 elements would be created and the 10 elements of the original array copied into the first 10 elements of the new array.

The Queue is not like that at all. When you create it it is empty, i.e. it contains no items. When you Enqueue an item the Queue now contains 1 item. If you Enqueue another item the Queue now contains 2 items. If you Dequeue an item then the Queue now has 1 item. Just like the stretchy bag I mentioned earlier, the collection grows and shrinks inherently as you add and remove items. Just like the egg carton I mentioned earlier, the array always has the same number of elements as you specified when you created it, even if some of them are empty.

Are we clear now? If not, please do as I asked last time and explain WHAT YOU ARE TRYING TO ACHIEVE rather than how you are trying to achieve it. Trying to change the size of a Queue is the method by which you are trying to implement some functionality. I want to know what that functionality is because, if I know that, then I can explain how to achieve it without trying to do something that is impossible. If I kept asking you how to walk across the floor of the Pacific Ocean could you tell me how to do it? Would there be any point when what I was actually trying to achieve was to get to the United States? Why do I need to explain the difference between what and how?
 
Thanks now i got it. I just didn't understand you cant size limit a queue. I will just use a size limited collection or just dequeue the item if it get too big.
Well if you are asking about walking on the floor of the ocean, i would guess you want to explore the floor of the ocean. And i would think being able to explore there is more interesting than going on a plane.
 
Well if you are asking about walking on the floor of the ocean, i would guess you want to explore the floor of the ocean. And i would think being able to explore there is more interesting than going on a plane.
Quite so, in which case you'd give me bad advice because you are trying to solve a different to the one I'm trying to solve. That's why you need to actually describe what you're trying to achieve, not how you're trying to achieve it. If the how isn't working then there's every chance that the how is wrong, so we need to know the what in order to determine the how that will work.

Even after all that though, what you're saying still doesn't really make sense. You'll just dequeue if it gets too big? The whole point of a Queue is the FIFO functionality that it provides. That's the reason to use it: if you need FIFO functionality. You should be dequeuing when you need to dequeue. You still haven't actually explained what you're trying to achieve so there's still no way to know what the best way to achieve it is. Whoever told you that providing as little information as possible is the way to go was dead wrong. If people have to spend post after post trying to drag information out of you that you could have simply provided in your first post the pretty soon they'll just stop trying to help at all.
 
I am just trying to keep a history of some data and when the list get too big, i will just discard the oldest one. I just need the most current data. And i have an option to set how much data i should keep. So i am just going to dequeue and discard the data if the count is greater than the number set in option. I was just using a queue like a size limiting array, i will only hold a max number of data. And the old one get discarded.

I just needed a Size Limiting Array of String Array which is a 2d Array that can be saved to My.settings.

And i used the queue to store the string(). With a string setting in my.settings. I save it by converting the queue into a 2d array of string then converting that into a delimiting string. And load it back by, doing the reverse.

There is probably a better way to do it, but this is what i did. I only know how to use simple type and arraylist for my.settings. And i needed to save a 2d array into one setting instead of multiple ones. And the queue seem like what i need, FIFO.
 
Last edited:
no, only remove the oldest one, no reusing. And i have put more into the explanation on the last post. Please read it again.
 
Back
Top