Peretz
Peretz

Reputation: 1126

simple method to keep last n elements in a queue for vb6?

I am trying to keep the last n elements from a changing list of x elements (where x >> n)

I found out about the deque method, with a fixed length, in other programming languages. I was wondering if there is something similar for VB6

Upvotes: 2

Views: 148

Answers (3)

JasonGH
JasonGH

Reputation: 1

Here's my simplest solution to this:

    For i = n - 1 To 1 Step -1
       arrayX(i) = arrayX(i - 1)
    Next i
       arrayX(0) = latestX

Where:

  • arrayX = array of values
  • n = # of array elements
  • latestX = latest value of interest (assumes entire code block is also within another loop)

Upvotes: 0

Matt Donnan
Matt Donnan

Reputation: 5003

The only thing I can think of is possibly looping through the last 5 values of the dynamic array using something like:

For UBound(Array) - 5 To UBound(Array)
    'Code to store or do the desired with these values
Loop

Sorry I don't have a definite answer, but hopefully that might help.

Upvotes: 0

Bob77
Bob77

Reputation: 13267

Create a Class that extends an encapsulated Collection.

Add at the end (anonymous), retrieve & remove from the beginning (index 1). As part of adding check your MaxDepth property setting (or hard code it if you like) and if Collection.Count exceeds it remove the extra item.

Or just hard code it all inline if a Class is a stumper for you.

This is pretty routine.

Upvotes: 2

Related Questions